InApp billing cancel subscription

Stesvis 1,041 Reputation points
2021-04-10T22:09:56.253+00:00

I have implemented in-app billing with the InAppBilling Plugin, but now i am wondering how do you cancel a subscription?
And how to know if a subscription is still active or it's been canceled?

Thanks.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-04-12T06:40:10.387+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You can check one issue in github here Subscription lifecycle .

    It depends on the platform.

    Google Play
    Not beautiful, but simple. Since Google recommends restoring purchases every time you launch and resume the app, and the plugin only returns your currently active subscriptions, you just need to check that your subscription is in the list.

    App Store
    1st way - Apple recommended
    Every time you want to check if your subscription is active, you'll need to validate receipt with Apple. This way you will get all the necessary information. There is no support in the plugin for this way and to get it right and safe without revealing your secrets you need to use a proxy server.

    2nd way - without validating receipt
    It may be easier to implement and works ok as long as subscription status is not a life changer. You need to remember user subscriptions yourself (you can get the list restoring purchases, it returns all active and not active subscriptions, but there is no info about current auto-renewal status). From the token you can decode subscription expiration date and compare it with the system date to check if it is active. Important thing (Apple's advice), you are not spouse of restoring purchases on every start because it may show the store login popup and disturb the user, so it's a better idea to check the current status (restore purchases) only if the user has expired subscription to see if there is a new renewal.

    To decode data from token you may use this code:

      public static IDictionary<string, object> DecodeTokenAppStore(string token)  
        {  
            if (Device.RuntimePlatform == Device.Android)  
            {  
                return null;  
            }  
    
            if (String.IsNullOrWhiteSpace(token))  
            {  
                return null;  
            }  
    
            var data1 = System.Convert.FromBase64String(token);  
            if (!data1.Any())  
            {  
                return null;  
            }  
    
            var receiptDic = (NSDictionary)PropertyListParser.Parse(data1);  
            if (receiptDic == null)  
            {  
                return null;  
            }  
    
            var purchaseInfoContent = receiptDic.ObjectForKey("purchase-info")?.ToString();  
            if (string.IsNullOrEmpty(purchaseInfoContent))  
            {  
                return null;  
            }  
    
            byte[] data2 = System.Convert.FromBase64String(purchaseInfoContent);  
            var purchaseInfoDic = (NSDictionary)PropertyListParser.Parse(data2);  
    
            if (purchaseInfoDic == null)  
            {  
                return null;  
            }  
    
            var result = new Dictionary<string, object>();  
    
            foreach (var item in purchaseInfoDic)  
            {  
                result.Add(item.Key, item.Value.ToObject());  
            }  
            return result;  
        }  
    

    Hope it can help you.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Dean Burt 0 Reputation points
    2023-03-10T17:43:00.19+00:00

    Cancel all azure in my email name or name. I registered thinking azure would set my computer up windows 10. Please cancel!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.