Skip to content

Commit

Permalink
Version 4.1.1 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kherembourg authored Oct 30, 2023
1 parent 92b6c35 commit 980d0ae
Showing 10 changed files with 92 additions and 71 deletions.
2 changes: 1 addition & 1 deletion purchasely/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 4.1.0
## 4.1.1
🚨 Important: This SDK version uses StoreKit 2 by default. Read the [documentation](https://docs.purchasely.com/quick-start-1/sdk-configuration/storekit-2) for more information.
If you did not configure StoreKit 2 in Purchasely console, the SDK will fallback to StoreKit 1.

Original file line number Diff line number Diff line change
@@ -187,10 +187,10 @@ class PurchaselyFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware,
val planVendorId = call.argument<String>("planVendorId")
if(planVendorId == null) {
result.error("-1", "planVendorId must not be null", null)
return@launch
}
else {
result.success(isEligibleForIntroOffer(planVendorId))
}

result.success(isEligibleForIntroOffer(planVendorId))
}
}
"userLogin" -> {
@@ -354,7 +354,7 @@ class PurchaselyFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware,
.userId(userId)
.build()

Purchasely.sdkBridgeVersion = "4.1.0"
Purchasely.sdkBridgeVersion = "4.1.1"
Purchasely.appTechnology = PLYAppTechnology.FLUTTER

Purchasely.start { isConfigured, error ->
@@ -380,28 +380,28 @@ class PurchaselyFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware,
presentationId = presentationId,
contentId = contentId)

Purchasely.fetchPresentation(
properties = properties
) { presentation: PLYPresentation?, error: PLYError? ->
launch {
if (presentation != null) {
presentationsLoaded.removeAll { it.id == presentation.id && it.placementId == presentation.placementId }
presentationsLoaded.add(presentation)
val map = presentation.toMap().mapValues {
val value = it.value
if (value is PLYPresentationType) value.ordinal
else value
}
val mutableMap = map.toMutableMap().apply {
this["metadata"] = presentation.metadata?.toMap()
this["plans"] = (this["plans"] as List<PLYPresentationPlan>).map { it.toMap() }
}
result.success(mutableMap)
Purchasely.fetchPresentation(
properties = properties
) { presentation: PLYPresentation?, error: PLYError? ->
launch {
if (presentation != null) {
presentationsLoaded.removeAll { it.id == presentation.id && it.placementId == presentation.placementId }
presentationsLoaded.add(presentation)
val map = presentation.toMap().mapValues {
val value = it.value
if (value is PLYPresentationType) value.ordinal
else value
}

if (error != null) result.error("467", error.message, error)
val mutableMap = map.toMutableMap().apply {
this["metadata"] = presentation.metadata?.toMap()
this["plans"] = (this["plans"] as List<PLYPresentationPlan>).map { it.toMap() }
}
result.success(mutableMap)
}

if (error != null) result.error("467", error.message, error)
}
}
}

private fun presentPresentation(presentationMap: Map<String, Any>?,
@@ -860,17 +860,17 @@ class PurchaselyFlutterPlugin: FlutterPlugin, MethodCallHandler, ActivityAware,
}

private suspend fun isEligibleForIntroOffer(planVendorId: String) : Boolean {
try {
return try {
val plan = Purchasely.plan(planVendorId)
return plan?.let {
it.promoOffers.any { plan.isEligibleToIntroOffer(it.storeOfferId) }
} ?: run {
if(plan != null) {
plan.isEligibleToIntroOffer()
} else {
Log.e("Purchasely", "plan $planVendorId not found")
false
}
} catch (e: Exception) {
Log.e("Purchasely", e.message, e)
return false
false
}
}

12 changes: 7 additions & 5 deletions purchasely/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -58,7 +58,8 @@ class _MyAppState extends State<MyApp> {
bool isAnonymous = await Purchasely.isAnonymous();
print('is Anonymous ? : $isAnonymous');

bool isEligible = await Purchasely.isEligibleForIntroOffer('PURCHASELY_PLUS_YEARLY');
bool isEligible =
await Purchasely.isEligibleForIntroOffer('PURCHASELY_PLUS_YEARLY');
print('is eligible ? : $isEligible');

try {
@@ -190,15 +191,15 @@ class _MyAppState extends State<MyApp> {

Future<void> fetchPresentation() async {
try {
var presentation = await Purchasely.fetchPresentation(
null,
presentationId: "meta-cm");
var presentation = await Purchasely.fetchPresentation("onboarding");

if (presentation == null) {
print("No presentation found");
return;
}

print("Presentation: ${presentation}");

if (presentation.type == PLYPresentationType.deactivated) {
// No paywall to display
return;
@@ -262,7 +263,8 @@ class _MyAppState extends State<MyApp> {
Future<void> purchaseWithPromotionalOffer() async {
try {
Map<dynamic, dynamic> plan = await Purchasely.purchaseWithPlanVendorId(
vendorId: 'PURCHASELY_PLUS_YEARLY', offerId: 'com.purchasely.plus.yearly.promo');
vendorId: 'PURCHASELY_PLUS_YEARLY',
offerId: 'com.purchasely.plus.yearly.promo');
print('Plan is $plan');
} catch (e) {
print(e);
4 changes: 2 additions & 2 deletions purchasely/ios/Classes/SwiftPurchaselyFlutterPlugin.swift
Original file line number Diff line number Diff line change
@@ -208,7 +208,7 @@ public class SwiftPurchaselyFlutterPlugin: NSObject, FlutterPlugin {
return
}

Purchasely.setSdkBridgeVersion("4.1.0")
Purchasely.setSdkBridgeVersion("4.1.1")
Purchasely.setAppTechnology(PLYAppTechnology.flutter)

let logLevel = PLYLogger.LogLevel(rawValue: (arguments["logLevel"] as? Int) ?? PLYLogger.LogLevel.debug.rawValue) ?? PLYLogger.LogLevel.debug
@@ -239,7 +239,7 @@ public class SwiftPurchaselyFlutterPlugin: NSObject, FlutterPlugin {
return
}

Purchasely.setSdkBridgeVersion("4.1.0")
Purchasely.setSdkBridgeVersion("4.1.1")
Purchasely.setAppTechnology(PLYAppTechnology.flutter)

let logLevel = PLYLogger.LogLevel(rawValue: (arguments["logLevel"] as? Int) ?? PLYLogger.LogLevel.debug.rawValue) ?? PLYLogger.LogLevel.debug
79 changes: 49 additions & 30 deletions purchasely/lib/purchasely_flutter.dart
Original file line number Diff line number Diff line change
@@ -330,7 +330,8 @@ class Purchasely {
final result = await _channel.invokeMethod('setPaywallActionInterceptor');
final Map<dynamic, dynamic>? plan = result['parameters']['plan'];
final Map<dynamic, dynamic>? offer = result['parameters']['offer'];
final Map<dynamic, dynamic>? subscriptionOffer = result['parameters']['subscriptionOffer'];
final Map<dynamic, dynamic>? subscriptionOffer =
result['parameters']['subscriptionOffer'];
return PaywallActionInterceptorResult(
PLYPaywallInfo(
result['info']['contentId'],
@@ -345,7 +346,9 @@ class Purchasely {
result['parameters']['title'],
plan != null ? transformToPLYPlan(plan) : null,
offer != null ? transformToPLYPromoOffer(offer) : null,
subscriptionOffer != null ? transformToPLYSubscription(subscriptionOffer) : null,
subscriptionOffer != null
? transformToPLYSubscription(subscriptionOffer)
: null,
result['parameters']['presentation']));
}

@@ -373,7 +376,8 @@ class Purchasely {

static Future<bool> isEligibleForIntroOffer(String planVendorId) async {
final bool isEligible = await _channel.invokeMethod(
'isEligibleForIntroOffer', <String, dynamic>{'planVendorId': planVendorId});
'isEligibleForIntroOffer',
<String, dynamic>{'planVendorId': planVendorId});
return isEligible;
}

@@ -505,12 +509,13 @@ class Purchasely {
if (offer.isEmpty) return null;

return PLYPromoOffer(
offer['vendorId'],
offer['storeOfferId'],
offer['vendorId'],
offer['storeOfferId'],
);
}

static PLYSubscriptionOffer? transformToPLYSubscription(Map<dynamic, dynamic> subscriptionOffer) {
static PLYSubscriptionOffer? transformToPLYSubscription(
Map<dynamic, dynamic> subscriptionOffer) {
if (subscriptionOffer.isEmpty) return null;

return PLYSubscriptionOffer(
@@ -532,29 +537,26 @@ class Purchasely {
print(e);
}

List<PLYPresentationPlan> plans = (presentation['plans'] as List).map((e) =>
PLYPresentationPlan(
e['planVendorId'],
e['storeProductId'],
e['basePlanId'],
e['offerId'])
).toList();
List<PLYPresentationPlan>? plans = (presentation['plans'] as List?)
?.map((e) => PLYPresentationPlan(e['planVendorId'], e['storeProductId'],
e['basePlanId'], e['offerId']))
.toList();

Map<String, dynamic> metadata = {};
presentation['metadata'].forEach((key, value) {
presentation['metadata']?.forEach((key, value) {
metadata[key] = value;
});

return PLYPresentation(
presentation['id'],
presentation['placementId'],
presentation['audienceId'],
presentation['abTestId'],
presentation['abTestVariantId'],
presentation['language'],
type,
plans,
metadata);
presentation['id'],
presentation['placementId'],
presentation['audienceId'],
presentation['abTestId'],
presentation['abTestVariantId'],
presentation['language'],
type,
plans,
metadata);
}

static Map<dynamic, dynamic> transformPLYPresentationToMap(
@@ -568,7 +570,14 @@ class Purchasely {
presentationMap['abTestVariantId'] = presentation?.abTestVariantId;
presentationMap['language'] = presentation?.language;
presentationMap['type'] = presentation?.type.index;
presentationMap['plans'] = presentation?.plans;
presentationMap['plans'] = presentation?.plans
?.map((e) => {
"basePlanId": e.basePlanId,
"offerId": e.offerId,
"planVendorId": e.planVendorId,
"storeProductId": e.storeProductId
})
.toList();
presentationMap['metadata'] = presentation?.metadata;

return presentationMap;
@@ -758,7 +767,8 @@ class PLYSubscriptionOffer {
String? offerToken;
String? offerId;

PLYSubscriptionOffer(this.subscriptionId, this.basePlanId, this.offerToken, this.offerId);
PLYSubscriptionOffer(
this.subscriptionId, this.basePlanId, this.offerToken, this.offerId);
}

class PLYProduct {
@@ -775,7 +785,8 @@ class PLYPresentationPlan {
String? basePlanId;
String? offerId;

PLYPresentationPlan(this.planVendorId, this.storeProductId, this.basePlanId, this.offerId);
PLYPresentationPlan(
this.planVendorId, this.storeProductId, this.basePlanId, this.offerId);
}

class PLYPresentation {
@@ -789,8 +800,16 @@ class PLYPresentation {
List<PLYPresentationPlan>? plans;
Map<String, dynamic> metadata;

PLYPresentation(this.id, this.placementId, this.audienceId, this.abTestId,
this.abTestVariantId, this.language, this.type, this.plans, this.metadata);
PLYPresentation(
this.id,
this.placementId,
this.audienceId,
this.abTestId,
this.abTestVariantId,
this.language,
this.type,
this.plans,
this.metadata);
}

class PLYSubscription {
@@ -828,8 +847,8 @@ class PLYPaywallActionParameters {
PLYSubscriptionOffer? subscriptionOffer;
String? presentation;

PLYPaywallActionParameters(
this.url, this.title, this.plan, this.offer, this.subscriptionOffer, this.presentation);
PLYPaywallActionParameters(this.url, this.title, this.plan, this.offer,
this.subscriptionOffer, this.presentation);
}

class PLYPaywallInfo {
2 changes: 1 addition & 1 deletion purchasely/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: purchasely_flutter
description: Purchasely is a solution to ease the integration and boost your In-App Purchase & Subscriptions on the App Store, Google Play Store and Huawei App Gallery.
version: 4.1.0
version: 4.1.1
homepage: https://www.purchasely.com/

environment:
2 changes: 1 addition & 1 deletion purchasely_android_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 4.1.0
## 4.1.1
🚨 Important: This SDK version uses StoreKit 2 by default. Read the [documentation](https://docs.purchasely.com/quick-start-1/sdk-configuration/storekit-2) for more information.
If you did not configure StoreKit 2 in Purchasely console, the SDK will fallback to StoreKit 1.

2 changes: 1 addition & 1 deletion purchasely_android_player/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: purchasely_android_player
description: Purchasely Player dependency for Android
version: 4.1.0
version: 4.1.1
homepage: https://www.purchasely.com/

environment:
2 changes: 1 addition & 1 deletion purchasely_google/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 4.1.0
## 4.1.1
🚨 Important: This SDK version uses StoreKit 2 by default. Read the [documentation](https://docs.purchasely.com/quick-start-1/sdk-configuration/storekit-2) for more information.
If you did not configure StoreKit 2 in Purchasely console, the SDK will fallback to StoreKit 1.

2 changes: 1 addition & 1 deletion purchasely_google/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: purchasely_google
description: Purchasely Google Play Billing dependency for Android
version: 4.1.0
version: 4.1.1
homepage: https://www.purchasely.com/

environment:

0 comments on commit 980d0ae

Please sign in to comment.