Xamarin Forms using CrossInAppBilling, How to check if subscription is valid?

Viewed 960

Documentation: https://jamesmontemagno.github.io/InAppBillingPlugin/

I'm trying to verify a valid subscription exists for a user, if it does, log them in.

The following will grab all subscription purchases:

 var _subscriptionList = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.Subscription);

and I check to see if a user should be allowed to login depending on if a subscription is found.

            if (_subscriptionList.Any())
            {
                Login();
            }

However I feel this allows users with pending payments, to login(Or anyone that has any kind of subscription record with a state of paid, pending or rejected). So what I have done is put a check in place to observe the "PurchaseState":

if (_subscriptionList.Any())
            {
                foreach (var _subscription in _subscriptionList)
                {
                    if (_subscription.State == PurchaseState.Purchased)
                    {
                        Login();
                        break;
                    }

                }
            }

Is this the correct way to implement? I have tested on Android but the test purchase stays in a state of PurchaseState.Pending, so I had to include "_subscription.State == PurchaseState.PaymentPending" in order to login. I need someone who has experience with this plugin and it's behavior in real time.

0 Answers
Related