Search code examples
xamarinxamarin.iosin-app-purchase

Xamarin IOS InAppBiling plugin how to get receipt-data


I use Plugin.InAppBiling for In-App Purchase ios. I want to know Purchase receipt data.

here is my code.

private async Task<bool> MakePurchase(string productId)
        {
            var billing = CrossInAppBilling.Current;
            try
            {
                var connected = await billing.ConnectAsync();

                if (!connected)
                {   
                    return false;
                }

                var verify = DependencyService.Get<IInAppBillingVerifyPurchase>();
                var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, verify);
                
                if (purchase == null)
                {
                    return false;
                }
                else if (purchase.State == PurchaseState.Purchased)
                {
                 
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        Console.WriteLine("CHECK");
                        if(verify == null)
                        {
                            Console.WriteLine("null");
                        }
                        else
                        {
                            Console.WriteLine($"{verify}");
                        }
                        
                    }
                    return true;
                }

                return false;
            }
            finally
            {
                await billing.DisconnectAsync();
            }
        }

The payment process goes well. but verify is just return null.

I understood verify as receipt-data. It's right?

How do I get a base64 encoded string receipt-data?


Solution

  • The documentation you also link to clearly states that you need to implement IInAppBillingVerifyPurchase yourself. There is no implementation of this in the plugin.

    So you need to create your own class and register it in the IoC container:

    [assembly: Dependency(typeof(MyIAPVerification))]
    public class MyIAPVerification : IInAppBillingVerifyPurchase
    {
        // implementation here
    }
    

    Only then will your verify instance not be null.