Skip to content

Latest commit

 

History

History
91 lines (71 loc) · 4.35 KB

AMAZON-INSTRUCTIONS.md

File metadata and controls

91 lines (71 loc) · 4.35 KB

This release adds pre-release support for Amazon store.

Instructions

  • Download the Purchases-UnityIAP.unitypackage in the release
  • Open your Unity Project
  • Select Import package -> Custom package

Screen Shot 2021-11-24 at 3 55 50 PM

  • Select Purchases_Amazon.unityPackage and make sure all of the files are selected and press import

Screen Shot 2021-11-24 at 3 56 10 PM

  • If Package Manager Resolver asks to solve conflicts, choose library versions and select OK

  • Select Use Amazon in the Editor

Screen Shot 2021-11-24 at 3 57 01 PM

If calling setup on runtime, you can select “Use Runtime Setup” and call setup this way.

       var builder = PurchasesConfiguration.Builder.Init("amazon_specific_api_key")
            .SetUseAmazon(true);
        purchases.Setup(builder.Build());

Due to some limitations, RevenueCat will only validate purchases made in production or in Live App Testing and won't validate purchases made with the Amazon App Tester. You can read more about the different testing environments in our Amazon (Beta) docs.

Observer mode specific

  • If your app also targets the Google Play Store, you will want to conditionally exclude the BillingClient to prevent duplicated classes. If you don't have a mainTemplate.gradle, make sure you have Custom Main Gradle Template selected in the Android Player Settings, which should create a mainTemplate.gradle inside the Assets/Plugins/Android. Add the following to your mainTemplate.gradle to prevent duplicated classes when Unity IAP is targeting the Play Store:
dependencies {
    ...
    
    // ** ADD THIS **
    if (!project(":unityLibrary").fileTree(dir: 'libs', include: ['billing-3*.aar']).isEmpty()) {
        configurations.all {
            exclude group: 'com.android.billingclient', module: 'billing'
        }
    }
}
  • Due to some limitations with the Amazon SDK, SyncPurchases doesn't work when on Amazon observer mode. In order to sync purchases with RevenueCat you have to send the current active subscriptions when Unity IAP initializes and after every successful purchase. For example:
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_StoreController = controller;
        storeExtensionProvider = extensions;
        var purchases = GetComponent<Purchases>();
        purchases.SetDebugLogsEnabled(true);
        foreach (Product product in controller.products.all)
        {
            if (product.hasReceipt) {
                var amazonExtensions = storeExtensionProvider.GetExtension<IAmazonExtensions>();
                var userId = amazonExtensions.amazonUserId;
                purchases.SyncObserverModeAmazonPurchase(
                    product.definition.id,
                    product.transactionID,
                    userId,
                    product.metadata.isoCurrencyCode,
                    Decimal.ToDouble(product.metadata.localizedPrice)
                );
            }
        }
    }

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        var purchases = GetComponent<Purchases>();
        
        var amazonExtensions = storeExtensionProvider.GetExtension<IAmazonExtensions>();
        var userId = amazonExtensions.amazonUserId;
        purchases.SyncObserverModeAmazonPurchase(
            e.purchasedProduct.definition.id,
            e.purchasedProduct.transactionID,
            userId,
            e.purchasedProduct.metadata.isoCurrencyCode,
            Decimal.ToDouble(e.purchasedProduct.metadata.localizedPrice)
        );
        return PurchaseProcessingResult.Complete;
    }
  • Perform a Resolve using the editor option Assets/External Dependency Manager/Android Resolver/Resolve menu. This will add the right dependencies to the mainTemplate.gradle.

  • In observer mode, adding the Amazon in-app-purchasing library jar is not necessary since it will be added by Unity IAP when targeting the Amazon Store