[Xamarin InAppBillingPlugin]: When should I call AcknowledgePurchaseAsync?

Viewed 75

I'm upgrading to version 4 of InAppBillingPlugin, and I understand I must now call CrossInAppBilling.Current.AcknowledgePurchaseAsync. My question is precisely when. I'm getting conflicting information from different parts of the documentation.

For example, sample code on James Montemagno's blog here (https://montemagno.com/ios-android-subscription-implemenation-strategies/), linked from the GitHub project page, shows this basic flow:

var purchase = await CrossInAppBilling.Current.PurchaseAsync(productIdSub, ItemType.Subscription);

if (purchase == null)
{
    return;
}

if (purchase.State == PurchaseState.Purchased)
{
    if (DeviceInfo.Platform == DevicePlatform.Android)
    {
        await CrossInAppBilling.Current.AcknowledgePurchaseAsync(purchase.PurchaseToken);
    }
}

This seems to indicate that AcknowledgePurchaseAsync should not be called unless the purchase has a state of Purchased and the platform is Android.

However, the sample code here (https://github.com/jamesmontemagno/app-ac-islandtracker/blob/master/TurnipTracker/ViewModel/ProViewModel.cs), also linked from the main GitHub project page, does not show any check against DeviceInfo.Platform.

Finally, the official documentation linked to by the project page (https://jamesmontemagno.github.io/InAppBillingPlugin/PurchaseSubscription.html) doesn't have AcknowledgePurchaseAsync at all, though it appears that FinalizePurchaseAsync might have been an old name.

Therefore, my questions are as follows:

  • Do I actually need to avoid calling AcknowledgePurchaseAsync on non-Android platforms?
  • Do I really have to wait until InAppBillingPurchase.State is Purchased?

If the latter is yes, then I have a follow-up question that I don't see addressed anywhere. One of the values of InAppBillingPurchase.State is FreeTrial. If my subscription offers a free trial, then it sounds like I must wait for the trial to end before I can acknowledge the purchase. And if I must acknowledge it within 72 hours from the trial ending, there is no guarantee that the app will be running during that critical window. So that would suggest that I should plan on handling this on the server side, since only the server can be guaranteed to be around to handle subscriptions that cross over from free trial to purchased. Do I have that right or am I misunderstanding something.

Thank you in advance!

0 Answers
Related