Where/how to execute redemption code?

I've hooked my game up to IAP and economy. I am able to initiate a Play store purchase in my game and once the test payment is made, the purchase (from a Play store point of view) is complete.

This all occurs in the ProcessPurchase method that is defined in IStoreListener and the PurchaseEventArgs contain all the details that are required to redeem the purchase in Economy. This method is synchronous.

The Economy.Purchases.RedeemGooglePlayPurchaseAsync method is asynchronous.

It seemed logical to me to include the RedeemGooglePlayPurchaseAsync call inside the ProcessPurchase method, but I can't find a nice way to call the async method from a sync method (and I don't think it's recommended).

Is there an example of how the RedeemGooglePlayPurchaseAsync method should be called correctly? It would be so helpful to have some examples of IAP/Economy integration as the code examples for both products effectively work in isolation.

The pertinent (and incorrect) code is on line 26

        //Inside the Synchronous ProcessPurchase method after the purchase has been validated
        if (validPurchase)
            var receipt = e.purchasedProduct.receipt;
            var wrapper = (Dictionary<string, object>)MiniJson.JsonDecode(receipt);
            if(wrapper == null)
                throw new System.Exception();
            // Corresponds to http://docs.unity3d.com/Manual/UnityIAPPurchaseReceipts.html
            var store = (string)wrapper["Store"];
            var payload = (string)wrapper["Payload"]; // For Apple this will be the base64 encoded ASN.1 receipt

            // For GooglePlay payload contains more JSON
            if (Application.platform == RuntimePlatform.Android)
                var details = (Dictionary<string, object>)MiniJson.JsonDecode(payload);
                var gpJson = (string)details["json"];
                var gpSig = (string)details["signature"];
                var args = new Purchases.RedeemGooglePlayStorePurchaseArgs(e.purchasedProduct.definition.id, gpJson, gpSig, (int)(e.purchasedProduct.metadata.localizedPrice * 100), e.purchasedProduct.metadata.isoCurrencyCode);

                /* *************************************************************
                 The line below obviously won't work in a Synchronous method

                var redemptionResult = await Economy.Purchases.RedeemGooglePlayPurchaseAsync(args);
                if(redemptionResult.Verification.Status == GoogleVerification.StatusOptions.VALID)
                    Debug.Log("Redeemed successfully");



        return PurchaseProcessingResult.Complete;

Hi there,

Looking at your code snippet, instead of doing:

var redemptionResult = await 

you could do:

var redemptionResult = Task.Run(async() => await Economy.Purchases.RedeemGooglePlayPurchaseAsync(args)).Result;

That will cause the game to wait for the purchase to be redeemed before moving on.

Hopefully that should get you going while we build out some examples of common use case like this one.