Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUTOMATIC BUMP] Updates purchases-hybrid-common to 10.1.0 #1013

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version '6.23.0'

buildscript {
ext.kotlin_version = '1.7.21'
ext.common_version = '9.9.0'
ext.common_version = '10.1.0'
repositories {
google()
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.revenuecat.purchases.common.PlatformInfo;
import com.revenuecat.purchases.hybridcommon.CommonKt;
import com.revenuecat.purchases.hybridcommon.ErrorContainer;
import com.revenuecat.purchases.hybridcommon.OnNullableResult;
import com.revenuecat.purchases.hybridcommon.OnResult;
import com.revenuecat.purchases.hybridcommon.OnResultAny;
import com.revenuecat.purchases.hybridcommon.OnResultList;
Expand Down Expand Up @@ -54,10 +55,14 @@ public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler,
// Only set registrar for v1 embedder.
@SuppressWarnings("deprecation")
private io.flutter.plugin.common.PluginRegistry.Registrar registrar;
// Only set activity for v2 embedder. Always access activity from getActivity() method.
@Nullable private Context applicationContext;
@Nullable private MethodChannel channel;
@Nullable private Activity activity;
// Only set activity for v2 embedder. Always access activity from getActivity()
// method.
@Nullable
private Context applicationContext;
@Nullable
private MethodChannel channel;
@Nullable
private Activity activity;

private final Handler handler = new Handler(Looper.getMainLooper());

Expand Down Expand Up @@ -137,9 +142,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String appUserId = call.argument("appUserId");
Boolean observerMode = call.argument("observerMode");
Boolean useAmazon = call.argument("useAmazon");
//noinspection unused
// noinspection unused
String userDefaultsSuiteName = call.argument("userDefaultsSuiteName"); // iOS-only, unused.
//noinspection unused
// noinspection unused
Boolean usesStoreKit2IfAvailable = call.argument("usesStoreKit2IfAvailable"); // iOS-only, unused.
Boolean shouldShowInAppMessagesAutomatically = call.argument("shouldShowInAppMessagesAutomatically");
String verificationMode = call.argument("entitlementVerificationMode");
Expand All @@ -157,6 +162,13 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "getOfferings":
getOfferings(result);
break;
case "getCurrentOfferingForPlacement":
String placementIdentifier = call.argument("placementIdentifier");
getCurrentOfferingForPlacement(placementIdentifier, result);
break;
case "syncAttributesAndOfferingsIfNeeded":
syncAttributesAndOfferingsIfNeeded(result);
break;
case "getProductInfo":
ArrayList<String> productIdentifiers = call.argument("productIdentifiers");
String type = call.argument("type");
Expand All @@ -168,25 +180,28 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
Integer googleProrationMode = call.argument("googleProrationMode");
Boolean googleIsPersonalizedPrice = call.argument("googleIsPersonalizedPrice");
type = call.argument("type");
String presentedOfferingIdentifier = call.argument("presentedOfferingIdentifier");
purchaseProduct(productIdentifier, type, googleOldProductIdentifer, googleProrationMode, googleIsPersonalizedPrice, presentedOfferingIdentifier, result);
Map<String, Object> presentedOfferingContext = call.argument("presentedOfferingContext");
purchaseProduct(productIdentifier, type, googleOldProductIdentifer, googleProrationMode,
googleIsPersonalizedPrice, presentedOfferingContext, result);
break;
case "purchasePackage":
String packageIdentifier = call.argument("packageIdentifier");
String offeringIdentifier = call.argument("offeringIdentifier");
presentedOfferingContext = call.argument("presentedOfferingContext");
googleOldProductIdentifer = call.argument("googleOldProductIdentifier");
googleProrationMode = call.argument("googleProrationMode");
googleIsPersonalizedPrice = call.argument("googleIsPersonalizedPrice");
purchasePackage(packageIdentifier, offeringIdentifier, googleOldProductIdentifer, googleProrationMode, googleIsPersonalizedPrice, result);
purchasePackage(packageIdentifier, presentedOfferingContext, googleOldProductIdentifer,
googleProrationMode, googleIsPersonalizedPrice, result);
break;
case "purchaseSubscriptionOption":
productIdentifier = call.argument("productIdentifier");
String optionIdentifier = call.argument("optionIdentifier");
googleOldProductIdentifer = call.argument("googleOldProductIdentifier");
googleProrationMode = call.argument("googleProrationMode");
googleIsPersonalizedPrice = call.argument("googleIsPersonalizedPrice");
presentedOfferingIdentifier = call.argument("presentedOfferingIdentifier");
purchaseSubscriptionOption(productIdentifier, optionIdentifier, googleOldProductIdentifer, googleProrationMode, googleIsPersonalizedPrice, presentedOfferingIdentifier, result);
presentedOfferingContext = call.argument("presentedOfferingContext");
purchaseSubscriptionOption(productIdentifier, optionIdentifier, googleOldProductIdentifer,
googleProrationMode, googleIsPersonalizedPrice, presentedOfferingContext, result);
break;
case "getAppUserID":
getAppUserID(result);
Expand Down Expand Up @@ -362,8 +377,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
}

private void setupPurchases(String apiKey, String appUserID, @Nullable Boolean observerMode,
@Nullable Boolean useAmazon, @Nullable Boolean shouldShowInAppMessagesAutomatically,
@Nullable String verificationMode, final Result result) {
@Nullable Boolean useAmazon, @Nullable Boolean shouldShowInAppMessagesAutomatically,
@Nullable String verificationMode, final Result result) {
if (this.applicationContext != null) {
PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
Store store = Store.PLAY_STORE;
Expand Down Expand Up @@ -419,6 +434,14 @@ private void getOfferings(final Result result) {
CommonKt.getOfferings(getOnResult(result));
}

private void getCurrentOfferingForPlacement(String placementIdentifier, final Result result) {
CommonKt.getCurrentOfferingForPlacement(placementIdentifier, getOnNullableResult(result));
}

private void syncAttributesAndOfferingsIfNeeded(final Result result) {
CommonKt.syncAttributesAndOfferingsIfNeeded(getOnResult(result));
}

private void getProductInfo(ArrayList<String> productIDs, String type, final Result result) {
CommonKt.getProductInfo(productIDs, type, new OnResultList() {
@Override
Expand All @@ -438,7 +461,7 @@ private void purchaseProduct(final String productIdentifier,
final String googleOldProductId,
@Nullable final Integer googleProrationMode,
@Nullable final Boolean googleIsPersonalizedPrice,
@Nullable final String presentedOfferingIdentifier,
@Nullable final Map<String, Object> presentedOfferingContext,
final Result result) {
CommonKt.purchaseProduct(
getActivity(),
Expand All @@ -448,45 +471,42 @@ private void purchaseProduct(final String productIdentifier,
googleOldProductId,
googleProrationMode,
googleIsPersonalizedPrice,
presentedOfferingIdentifier,
getOnResult(result)
);
presentedOfferingContext,
getOnResult(result));
}

private void purchasePackage(final String packageIdentifier,
final String offeringIdentifier,
final String googleOldProductId,
@Nullable final Integer googleProrationMode,
@Nullable final Boolean googleIsPersonalizedPrice,
final Result result) {
final Map<String, Object> presentedOfferingContext,
final String googleOldProductId,
@Nullable final Integer googleProrationMode,
@Nullable final Boolean googleIsPersonalizedPrice,
final Result result) {
CommonKt.purchasePackage(
getActivity(),
packageIdentifier,
offeringIdentifier,
presentedOfferingContext,
googleOldProductId,
googleProrationMode,
googleIsPersonalizedPrice,
getOnResult(result)
);
getOnResult(result));
}

private void purchaseSubscriptionOption(final String productIdentifier,
final String optionIdentifier,
final String googleOldProductId,
@Nullable final Integer googleProrationMode,
@Nullable final Boolean googleIsPersonalizedPrice,
@Nullable final String presentedOfferingIdentifier,
final Result result) {
final String optionIdentifier,
final String googleOldProductId,
@Nullable final Integer googleProrationMode,
@Nullable final Boolean googleIsPersonalizedPrice,
@Nullable final Map<String, Object> presentedOfferingContext,
final Result result) {
CommonKt.purchaseSubscriptionOption(
getActivity(),
productIdentifier,
optionIdentifier,
googleOldProductId,
googleProrationMode,
googleIsPersonalizedPrice,
presentedOfferingIdentifier,
getOnResult(result)
);
presentedOfferingContext,
getOnResult(result));
}

private void getAppUserID(final Result result) {
Expand All @@ -512,11 +532,11 @@ private void setDebugLogsEnabled(boolean enabled, final Result result) {
}

private void syncObserverModeAmazonPurchase(String productID,
String receiptID,
String amazonUserID,
String isoCurrencyCode,
Double price,
final Result result) {
String receiptID,
String amazonUserID,
String isoCurrencyCode,
Double price,
final Result result) {
Purchases.getSharedInstance().syncObserverModeAmazonPurchase(productID, receiptID,
amazonUserID, isoCurrencyCode, price);
result.success(null);
Expand Down Expand Up @@ -558,9 +578,9 @@ private void invalidateCustomerInfoCache(Result result) {
result.success(null);
}

//================================================================================
// ================================================================================
// Subscriber Attributes
//================================================================================
// ================================================================================

private void setAttributes(Map<String, String> map, final Result result) {
SubscriberAttributesKt.setAttributes(map);
Expand Down Expand Up @@ -742,6 +762,21 @@ public void onError(ErrorContainer errorContainer) {
};
}

@NotNull
private OnNullableResult getOnNullableResult(final Result result) {
return new OnNullableResult() {
@Override
public void onReceived(@Nullable Map<String, ?> map) {
result.success(map);
}

@Override
public void onError(ErrorContainer errorContainer) {
reject(errorContainer, result);
}
};
}

private void reject(ErrorContainer errorContainer, Result result) {
result.error(String.valueOf(errorContainer.getCode()), errorContainer.getMessage(), errorContainer.getInfo());
}
Expand Down
14 changes: 10 additions & 4 deletions api_tester/lib/api_tests/models/package_wrapper_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:purchases_flutter/object_wrappers.dart';

// ignore_for_file: unused_element
// ignore_for_file: unused_local_variable
// ignore_for_file: deprecated_member_use
class _PackageApiTest {
void _checkPackageType(PackageType type) {
switch (type) {
Expand All @@ -26,16 +27,21 @@ class _PackageApiTest {
Map<String, dynamic> json = package.toJson();
}

void _checkConstructor(String identifier, PackageType packageType,
StoreProduct storeProduct, String offeringIdentifier) {
Package package =
Package(identifier, packageType, storeProduct, offeringIdentifier);
void _checkConstructor(
String identifier,
PackageType packageType,
StoreProduct storeProduct,
PresentedOfferingContext presentedOfferingContext) {
Package package = Package(
identifier, packageType, storeProduct, presentedOfferingContext);
}

void _checkProperties(Package package) {
String identifier = package.identifier;
PackageType packageType = package.packageType;
StoreProduct storeProduct = package.storeProduct;
String offeringIdentifier = package.offeringIdentifier;
PresentedOfferingContext presentedOfferingContext =
package.presentedOfferingContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:purchases_flutter/object_wrappers.dart';

// ignore_for_file: unused_element
// ignore_for_file: unused_local_variable
// ignore_for_file: deprecated_member_use
class _StoreProductApiTest {
void _checkFromJsonFactory(Map<String, dynamic> json) {
StoreProduct product = StoreProduct.fromJson(json);
Expand All @@ -22,7 +23,7 @@ class _StoreProductApiTest {
List<StoreProductDiscount>? discounts,
ProductCategory? productCategory,
String? subscriptionPeriod,
String? presentedOfferingIdentifier) {
PresentedOfferingContext? presentedOfferingContext) {
StoreProduct product = StoreProduct(
identifier, description, title, price, priceString, currencyCode);
product = StoreProduct(
Expand All @@ -31,7 +32,7 @@ class _StoreProductApiTest {
discounts: discounts,
productCategory: productCategory,
subscriptionPeriod: subscriptionPeriod,
presentedOfferingIdentifier: presentedOfferingIdentifier);
presentedOfferingContext: presentedOfferingContext);
}

void _checkProperties(StoreProduct product) {
Expand All @@ -48,5 +49,7 @@ class _StoreProductApiTest {
List<SubscriptionOption>? subscriptionOptions = product.subscriptionOptions;
String? subscriptionPeriod = product.subscriptionPeriod;
String? presentedOfferingIdentifier = product.presentedOfferingIdentifier;
PresentedOfferingContext? presentedOfferingContext =
product.presentedOfferingContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:purchases_flutter/object_wrappers.dart';

// ignore_for_file: unused_element
// ignore_for_file: unused_local_variable
// ignore_for_file: deprecated_member_use
class _SubscriptionOptionApiTest {
void _checkFromJsonFactory(Map<String, dynamic> json) {
SubscriptionOption product = SubscriptionOption.fromJson(json);
Expand All @@ -23,7 +24,7 @@ class _SubscriptionOptionApiTest {
PricingPhase? fullPricePhase,
PricingPhase? freePhase,
PricingPhase? introPhase,
String? presentedOfferingIdentifier) {
PresentedOfferingContext? presentedOfferingContext) {
SubscriptionOption subscriptionOption = SubscriptionOption(
id,
storeProductId,
Expand All @@ -36,7 +37,7 @@ class _SubscriptionOptionApiTest {
fullPricePhase,
freePhase,
introPhase,
presentedOfferingIdentifier);
presentedOfferingContext);
}

void _checkProperties(SubscriptionOption subscriptionOption) {
Expand All @@ -53,5 +54,7 @@ class _SubscriptionOptionApiTest {
PricingPhase? introPhase = subscriptionOption.introPhase;
String? presentedOfferingIdentifier =
subscriptionOption.presentedOfferingIdentifier;
PresentedOfferingContext? presentedOfferingContext =
subscriptionOption.presentedOfferingContext;
}
}
15 changes: 13 additions & 2 deletions api_tester/lib/api_tests/purchases_flutter_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class _PurchasesFlutterApiTest {
Offerings offerings = await Purchases.getOfferings();
}

void _checkGetCurrentOfferingForPlacement() async {
Offering? offering = await Purchases.getCurrentOfferingForPlacement('');
}

void _checkSyncAttributesAndOfferingsIfNeeded() async {
Offerings offerings = await Purchases.syncAttributesAndOfferingsIfNeeded();
}

void _checkGetProducts() async {
List<String> productIdentifiers = List.empty();
PurchaseType purchaseType = PurchaseType.subs;
Expand Down Expand Up @@ -509,7 +517,10 @@ class _PurchasesFlutterApiTest {
}

void _showInAppMessages() async {
Future<void> future = Purchases.showInAppMessages(types: {InAppMessageType.billingIssue,
InAppMessageType.priceIncreaseConsent, InAppMessageType.generic});
Future<void> future = Purchases.showInAppMessages(types: {
InAppMessageType.billingIssue,
InAppMessageType.priceIncreaseConsent,
InAppMessageType.generic
});
}
}
Loading