In-App Billing Plugin for Xamarin AcknowledgePurchase is not working

Viewed 676

I am using the In-App Billing Plugin for Xamarin and Windows to implement non-consumable in-app purchases.
I have an issue that the payments are refunded for Android devices because I didn't implement the Acknowledge purchase.
The documentation advises adding the code below, but I still get a refund within three days of an item has been purchased.

if(purchase.State == PurchaseState.Purchased)   
{
    if (DeviceInfo.Platform == DevicePlatform.Android)
    {             
       await billing.AcknowledgePurchaseAsync(purchase.PurchaseToken);
    }
       //consume an item          
 }

enter image description here

1 Answers

You are not storing the result - change it to

BillingResult billingResult = await inAppBilling.BillingClient.AcknowledgePurchaseAsync(acknowledgePurchaseParams);

if (billingResult.ResponseCode == BillingResponseCode.Ok)
{
// whatever you need to do with the result
}

Note my code is not using the plugin. But you need to do the check to see what the billingResult.ResponseCode is to be able to debug it.

If you are doing this within a fragment then you will also need to do the same in your MainActvity's OnResume, as there maybe a delay before you get a BillingResponseCode.Ok. Read the Android docs about the reasons for the delay. https://android-developers.googleblog.com/2020/06/meet-google-play-billing-library.html

Also note that you should verify the PurchaseToken against your backend server before acknowledging the purchase.

Related