Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check subscription validity using Flutters in-app-purchase plugin?

I'm trying to implement in-app purchases using the official Flutter In-App-Purchase plugin. I've got things working, except I can't figure out how to tell if a users subscription is still active or if it expired. Even after I canceled my test subscription, the values I get after connecting and doing queryPastPurchases() are the same as when the subscription was active:

productId: test_subscription_1   
transactiondate: 1565682346568   
status: null

verificationData
    source: IAPSource.GooglePlay   
    localVerificationData: {
        "orderId":"GPA.1234-1234-1234-12345",
        "packageName":"com.example.myapp",
        "productId":"test_subscription_1",
        "purchaseTime":1565682346568,
        "purchaseState":0,
        "purchaseToken":"<long string>",
        "autoRenewing":false
    }   
    serverVerificationData: "<long string>"

Am I supposed to simply hard code my subscription period and compare the current time to purchaseTime + the subscription period? Will that even work across auto-renewals? What if the user changes the date on his phone to a year ago? It seems like there should be some value that should either give me the expiration time or at least a boolean true/false to indicate if the subscription is still valid?

like image 755
Magnus Avatar asked Aug 13 '19 09:08

Magnus


Video Answer


1 Answers

The official in-app purchase plugin handles making the purchase but doesn't supply all of the backend infrastructure you need to handle auto-renewing subscriptions specifically.

The short answer to your question is send this purchase info up to your server and manage subscription status there. Alternatively you can look into a managed solution like purchases_flutter: https://pub.dev/packages/purchases_flutter/

like image 96
enc_life Avatar answered Sep 22 '22 16:09

enc_life