Skip to content

Commit

Permalink
Update to latest native majors
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Aug 1, 2024
1 parent fba07a0 commit 4175c3f
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 152 deletions.
4 changes: 2 additions & 2 deletions AMAZON-INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void OnInitialized(IStoreController controller, IExtensionProvider extens
if (product.hasReceipt) {
var amazonExtensions = storeExtensionProvider.GetExtension<IAmazonExtensions>();
var userId = amazonExtensions.amazonUserId;
purchases.SyncObserverModeAmazonPurchase(
purchases.SyncAmazonPurchase(
product.definition.id,
product.transactionID,
userId,
Expand All @@ -55,7 +55,7 @@ public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)

var amazonExtensions = storeExtensionProvider.GetExtension<IAmazonExtensions>();
var userId = amazonExtensions.amazonUserId;
purchases.SyncObserverModeAmazonPurchase(
purchases.SyncAmazonPurchase(
e.purchasedProduct.definition.id,
e.purchasedProduct.transactionID,
userId,
Expand Down
8 changes: 4 additions & 4 deletions IntegrationTests/Assets/APITests/PurchasesAPITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private void Start()
receivedError = error;
});

purchases.SetFinishTransactions(true);
#pragma warning disable CS0618 // Type or member is obsolete
purchases.SetAllowSharingStoreAccount(false);
#pragma warning restore CS0618 // Type or member is obsolete
Expand All @@ -170,7 +169,6 @@ private void Start()
});

purchases.SyncPurchases();
purchases.SetAutomaticAppleSearchAdsAttributionCollection(true);
purchases.EnableAdServicesAttributionTokenCollection();
Dictionary<string, Purchases.IntroEligibility> receivedEligibilities;
purchases.CheckTrialOrIntroductoryPriceEligibility(new string[] { "a", "b" },
Expand Down Expand Up @@ -220,16 +218,18 @@ private void Start()
Purchases.PurchasesConfiguration purchasesConfiguration =
builder.SetUserDefaultsSuiteName("user_default")
.SetDangerousSettings(new Purchases.DangerousSettings(false))
.SetObserverMode(true)
.SetPurchasesAreCompletedBy(Purchases.PurchasesAreCompletedBy.MyApp, Purchases.StoreKitVersion.StoreKit2)
.SetUseAmazon(false)
.SetAppUserId(appUserId)
.SetUsesStoreKit2IfAvailable(false)
.SetStoreKitVersion(Purchases.StoreKitVersion.StoreKit2)
.SetShouldShowInAppMessagesAutomatically(false)
.SetEntitlementVerificationMode(Purchases.EntitlementVerificationMode.Informational)
.SetPendingTransactionsForPrepaidPlansEnabled(true)
.Build();
purchases.Configure(purchasesConfiguration);

purchases.SyncObserverModeAmazonPurchase("product_id", "receipt_id", "amazon_user_id", "iso_currency_code", 1.99);
purchases.SyncAmazonPurchase("product_id", "receipt_id", "amazon_user_id", "iso_currency_code", 1.99);

purchases.ShowInAppMessages(new Purchases.InAppMessageType[] { Purchases.InAppMessageType.BillingIssue,
Purchases.InAppMessageType.PriceIncreaseConsent, Purchases.InAppMessageType.Generic });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ private void Start()
bool IsBasePlan = subscriptionOption.IsBasePlan;
bool IsPrepaid = subscriptionOption.IsPrepaid;
string PresentedOfferingIdentifier = subscriptionOption.PresentedOfferingIdentifier;
Purchases.SubscriptionOption.InstallmentsInfo installmentsInfo = subscriptionOption.InstallmentsInfo;
int commitmentPaymentsCount = installmentsInfo.CommitmentPaymentsCount;
int renewalCommitmentPaymentsCount = installmentsInfo.RenewalCommitmentPaymentsCount;
}
}
}
9 changes: 2 additions & 7 deletions RevenueCat/Plugins/Android/PurchasesWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,14 @@ public void onError(ErrorContainer errorContainer) {
});
}

public static void syncObserverModeAmazonPurchase(
public static void syncAmazonPurchase(
String productID,
String receiptID,
String amazonUserID,
String isoCurrencyCode,
double price
) {
Purchases.getSharedInstance().syncObserverModeAmazonPurchase(productID, receiptID,
Purchases.getSharedInstance().syncAmazonPurchase(productID, receiptID,
amazonUserID, isoCurrencyCode, price);
}

Expand Down Expand Up @@ -357,11 +357,6 @@ public static void getCustomerInfo() {
CommonKt.getCustomerInfo(getCustomerInfoListener(GET_CUSTOMER_INFO));
}

public static void setFinishTransactions(boolean enabled) {
CommonKt.setPurchasesAreCompletedBy(enabled ?
PurchasesAreCompletedBy.REVENUECAT : PurchasesAreCompletedBy.MY_APP);
}

public static void syncPurchases() {
CommonKt.syncPurchases();
}
Expand Down
4 changes: 2 additions & 2 deletions RevenueCat/Plugins/Editor/RevenueCatDependencies.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<dependencies>
<androidPackages>
<androidPackage spec="com.revenuecat.purchases:purchases-hybrid-common:[11.1.0]" />
<androidPackage spec="com.revenuecat.purchases:purchases-hybrid-common:[13.0.0]" />
<androidPackage spec="androidx.annotation:annotation:[1.2.0]" />
</androidPackages>
<iosPods>
<iosPod name="PurchasesHybridCommon" version="11.1.0" minTargetSdk="11.0"/>
<iosPod name="PurchasesHybridCommon" version="13.0.0" minTargetSdk="13.0"/>
</iosPods>
</dependencies>
15 changes: 0 additions & 15 deletions RevenueCat/Plugins/iOS/PurchasesUnityHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,6 @@ - (void)getCustomerInfo {
[RCCommonFunctionality getCustomerInfoWithCompletionBlock:[self getCustomerInfoCompletionBlockFor:GET_CUSTOMER_INFO]];
}

- (void)setFinishTransactions:(BOOL)finishTransactions {
if (finishTransactions) {
[RCCommonFunctionality setPurchasesAreCompletedBy:RCPurchasesAreCompletedByRevenueCat];
} else {
[RCCommonFunctionality setPurchasesAreCompletedBy:RCPurchasesAreCompletedByMyApp];
}
}

- (void)setAutomaticAppleSearchAdsAttributionCollection:(BOOL)enabled {
[RCCommonFunctionality setAutomaticAppleSearchAdsAttributionCollection:enabled];
}

- (void)enableAdServicesAttributionTokenCollection {
if (@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)) {
[RCCommonFunctionality enableAdServicesAttributionTokenCollection];
Expand Down Expand Up @@ -571,9 +559,6 @@ void _RCLogOut() {
[_RCUnityHelperShared() logOut];
}

void _RCSetFinishTransactions(const BOOL finishTransactions) {
[_RCUnityHelperShared() setFinishTransactions:finishTransactions];
}
void _RCSetAllowSharingStoreAccount(const BOOL allow) {
[_RCUnityHelperShared() setAllowSharingStoreAccount:allow];
}
Expand Down
82 changes: 38 additions & 44 deletions RevenueCat/Scripts/Purchases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ public partial class Purchases : MonoBehaviour
"Use your custom subclass to define how to handle updated customer information.")]
public UpdatedCustomerInfoListener listener;

[Tooltip("An optional boolean. Set this to true if you have your own IAP implementation " +
"and want to use only RevenueCat's backend.\nDefault is false.\n" +
"NOTE: This value will be ignored if \"Use Runtime Setup\" is true. For Runtime Setup, you can configure " +
"it through PurchasesConfiguration instead")]
public bool observerMode;

[Tooltip("An optional string. iOS only.\n" +
"Set this to use a specific NSUserDefaults suite for RevenueCat. " +
"This might be handy if you are deleting all NSUserDefaults in your app " +
Expand All @@ -74,6 +68,16 @@ public partial class Purchases : MonoBehaviour
"it through PurchasesConfiguration instead")]
public string userDefaultsSuiteName;

[Tooltip("Set this to MyApp and provide a StoreKitVersion if you have your own IAP implementation and\n" +
"want to only use RevenueCat's backend. Defaults to PurchasesAreCompletedBy.RevenueCat\n." +
"If you are on Android and setting this to MyApp, you will have to acknowledge the purchases yourself.\n" +
"If your app is only on Android, you may specify any StoreKit version, as it is ignored by the Android SDK.")]
public PurchasesAreCompletedBy purchasesAreCompletedBy = PurchasesAreCompletedBy.RevenueCat;

[Tooltip("Version of StoreKit to use in iOS. By default, RevenueCat will decide for you.\n" +
"Set this if you're setting PurchasesAreCompletedBy to MyApp.")]
public StoreKitVersion storeKitVersion = StoreKitVersion.Default;

[Tooltip("Whether we should show store in-app messages automatically. Both Google Play and the App Store provide in-app " +
"messages for some situations like billing issues. By default, those messages will be shown automatically.\n" +
"This allows to disable that behavior, so you can display those messages at your convenience. For more information, " +
Expand All @@ -83,30 +87,17 @@ public partial class Purchases : MonoBehaviour
[Tooltip("The entitlement verification mode to use. For more information, check: https://rev.cat/trusted-entitlements")]
public EntitlementVerificationMode entitlementVerificationMode = EntitlementVerificationMode.Disabled;

[Tooltip("Enable this setting if you want to allow pending purchases for prepaid subscriptions (only supported " +
"in Google Play). Note that entitlements are not granted until payment is done. Disabled by default.")]
public bool pendingTransactionsForPrepaidPlansEnabled = false;

[Header("Advanced")]
[Tooltip("Set this property to your proxy URL before configuring Purchases *only* if you've received " +
"a proxy key value from your RevenueCat contact.\n" +
"NOTE: This value will be ignored if \"Use Runtime Setup\" is true. For Runtime Setup, you can configure " +
"it through PurchasesConfiguration instead")]
public string proxyURL;

[Header("⚠️ Deprecated")]
[Tooltip("⚠️ RevenueCat currently uses StoreKit 1 for purchases, as its stability in production " +
"scenarios has proven to be more performant than StoreKit 2.\n" +
"We're collecting more data on the best approach, but StoreKit 1 vs StoreKit 2 is \n" +
"an implementation detail that you shouldn't need to care about.\n" +
"We recommend not using this parameter, letting RevenueCat decide for " +
"you which StoreKit implementation to use.\n" +
"NOTE: This value will be ignored if \"Use Runtime Setup\" is true. For Runtime Setup, you can configure " +
"it through PurchasesConfiguration instead")]
[Obsolete("RevenueCat currently uses StoreKit 1 for purchases, as its stability in production " +
"scenarios has proven to be more performant than StoreKit 2.\n" +
"We're collecting more data on the best approach, but StoreKit 1 vs StoreKit 2 is \n" +
"an implementation detail that you shouldn't need to care about.\n" +
"We recommend not using this parameter, letting RevenueCat decide for " +
"you which StoreKit implementation to use.", false)]
public bool usesStoreKit2IfAvailable;

private IPurchasesWrapper _wrapper;

private void Start()
Expand Down Expand Up @@ -143,11 +134,11 @@ private void Configure(string newUserId)
var dangerousSettings = new DangerousSettings(autoSyncPurchases);
var builder = PurchasesConfiguration.Builder.Init(apiKey)
.SetAppUserId(newUserId)
.SetObserverMode(observerMode)
.SetPurchasesAreCompletedBy(purchasesAreCompletedBy, storeKitVersion)
.SetUserDefaultsSuiteName(userDefaultsSuiteName)
.SetUseAmazon(useAmazon)
.SetDangerousSettings(dangerousSettings)
.SetUsesStoreKit2IfAvailable(usesStoreKit2IfAvailable)
.SetStoreKitVersion(storeKitVersion)
.SetShouldShowInAppMessagesAutomatically(shouldShowInAppMessagesAutomatically)
.SetEntitlementVerificationMode(entitlementVerificationMode);

Expand Down Expand Up @@ -193,9 +184,9 @@ public void Configure(PurchasesConfiguration purchasesConfiguration)
{
var dangerousSettings = purchasesConfiguration.DangerousSettings.Serialize().ToString();
_wrapper.Setup(gameObject.name, purchasesConfiguration.ApiKey, purchasesConfiguration.AppUserId,
purchasesConfiguration.ObserverMode, purchasesConfiguration.UsesStoreKit2IfAvailable, purchasesConfiguration.UserDefaultsSuiteName,
purchasesConfiguration.PurchasesAreCompletedBy, purchasesConfiguration.StoreKitVersion, purchasesConfiguration.UserDefaultsSuiteName,
purchasesConfiguration.UseAmazon, dangerousSettings, purchasesConfiguration.ShouldShowInAppMessagesAutomatically,
purchasesConfiguration.EntitlementVerificationMode);
purchasesConfiguration.EntitlementVerificationMode, purchasesConfiguration.PendingTransactionsForPrepaidPlansEnabled);
}

private bool IsAndroidEmulator()
Expand Down Expand Up @@ -513,22 +504,6 @@ public void LogOut(CustomerInfoFunc callback)
_wrapper.LogOut();
}

// ReSharper disable once UnusedMember.Global
/// <summary>
/// Whether transactions should be finished automatically. `true` by default.
/// </summary>
/// <remarks>
/// Warning: Setting this value to `false` will prevent the SDK from finishing transactions.
/// In this case, you *must* finish transactions in your app, otherwise they will remain in the queue and
/// will turn up every time the app is opened.
/// More information on finishing transactions manually [is available here](https://rev.cat/finish-transactions).
/// </remarks>
/// <param name="finishTransactions"> Whether transactions should be finished automatically. </param>
public void SetFinishTransactions(bool finishTransactions)
{
_wrapper.SetFinishTransactions(finishTransactions);
}

// ReSharper disable once UnusedMember.Global
[Obsolete("Deprecated, configure behavior through the RevenueCat Dashboard instead.")]
public void SetAllowSharingStoreAccount(bool allow)
Expand Down Expand Up @@ -726,10 +701,29 @@ public void SyncPurchases()
/// <param name="amazonUserID">Amazon's userID.</param>
/// <param name="isoCurrencyCode">Product's currency code in ISO 4217 format.</param>
/// <param name="price">Product's price.</param>
[Obsolete("Deprecated, use SyncAmazonPurchase instead.")]
public void SyncObserverModeAmazonPurchase(string productID, string receiptID, string amazonUserID,
string isoCurrencyCode, double price)
{
_wrapper.SyncObserverModeAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price);
_wrapper.SyncAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price);
}

/// <summary>
/// Android only. Noop in iOS.
///
/// This method will send a purchase to the RevenueCat backend. This function should only be called if you are
/// in Amazon observer mode or performing a client side migration of your current users to RevenueCat.
/// The receipt IDs are cached if successfully posted so they are not posted more than once.
/// </summary>
/// <param name="productID">Product ID associated to the purchase.</param>
/// <param name="receiptID"> ReceiptId that represents the Amazon purchase.</param>
/// <param name="amazonUserID">Amazon's userID.</param>
/// <param name="isoCurrencyCode">Product's currency code in ISO 4217 format.</param>
/// <param name="price">Product's price.</param>
public void SyncAmazonPurchase(string productID, string receiptID, string amazonUserID,
string isoCurrencyCode, double price)
{
_wrapper.SyncAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price);
}

// ReSharper disable once UnusedMember.Global
Expand Down
31 changes: 31 additions & 0 deletions RevenueCat/Scripts/PurchasesAreCompletedBy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.ComponentModel;

public partial class Purchases
{
public enum PurchasesAreCompletedBy
{
/// RevenueCat will automatically acknowledge verified purchases. No action is required by you.
[Description("REVENUECAT")]
RevenueCat,

/// RevenueCat will **not** automatically acknowledge any purchases. You will have to do so manually.
/// **Note:** failing to acknowledge a purchase within 3 days will lead to Google Play automatically issuing a
/// refund to the user.
/// For more info, see [revenuecat.com](https://docs.revenuecat.com/docs/observer-mode#option-2-client-side).
[Description("MY_APP")]
MyApp,
}
}

internal static class StoreKitVersionExtensions
{
internal static string Name(this Purchases.PurchasesAreCompletedBy purchasesAreCompletedBy)
{
var type = purchasesAreCompletedBy.GetType();
var memInfo = type.GetMember(purchasesAreCompletedBy.ToString());
var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
var stringValue = ((DescriptionAttribute) attributes[0]).Description;
return stringValue;
}
}
Loading

0 comments on commit 4175c3f

Please sign in to comment.