I have a Xamarin.Forms application with a few renewable subscriptions. I am using the InAppBilling plugin to purchase these subscriptions. Now my questions is: (which I already asked in this post) How can I check if the renewable subscription is active? Thanks in advance.
Asked
Active
Viewed 599 times
1 Answers
0
Through the document, you can check the status by
var connected = await billing.ConnectAsync(ItemType.Subscription);
:
Here is the example:
public async Task<bool> PurchaseItem(string productId, string payload)
{
var billing = CrossInAppBilling.Current;
try
{
var connected = await billing.ConnectAsync(ItemType.InAppPurchase);
if (!connected)
{
//we are offline or can't connect, don't try to purchase
return false;
}
//check purchases
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchase, payload);
//possibility that a null came through.
if(purchase == null)
{
//did not purchase
}
else if(purchase.State == PurchaseState.Purchased)
{
//purchased!
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
//Billing Exception handle this based on the type
Debug.WriteLine("Error: " + purchaseEx);
}
catch (Exception ex)
{
//Something else has gone wrong, log it
Debug.WriteLine("Issue connecting: " + ex);
}
finally
{
await billing.DisconnectAsync();
}

nevermore
- 15,432
- 1
- 12
- 30
-
Thank you for your answer, I really appreciate this. So my problem is, I don’t know how to check if a user already subscribed a renewable subscription or not. I tried it with this: var purchases = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.Subscription); but this returns any purchase, also if it’s expired. – WorldOfBasti Sep 08 '20 at 09:59
-
I don't use this plugin before and I assume if a user does not subscribe a renewable subscription, you will get null when you call PurchaseAsync. And does illing.ConnectAsync work to check the subscription? – nevermore Sep 09 '20 at 01:25
-
If I purchase the subscription again, it will return null, but every time the app checks for the subscription, this message will be shown: `you have already subscribed to this article`. And `billing.ConnectAsync` connects the device to the billing service. – WorldOfBasti Sep 09 '20 at 12:22
-
Well, you can open an issue in Github of this plugin to get more help. – nevermore Sep 16 '20 at 08:23
-
Yes, If you find any solution, you can share it here. – nevermore Sep 17 '20 at 05:54
-
Hi, any solutions? Did you manage to solve this? Thanks – user1034912 Jan 03 '22 at 22:25