DEV Community

Victor Corvalan
Victor Corvalan

Posted on • Originally published at Medium on

Setup auto-renewable subscriptions for iOS in Flutter

After I had successfully tested and implemented auto-renewable subscriptions on my Android APP… it was time to do the same thing for iOS… but once again… a problem came up.

When I was trying to list my past purchases, on iOS I was receiving an empty list… I won’t write about a full implementation of in-app purchases in Flutter as I’m only interested in this specific problem… you can get a good tutorial from Fireship.io.

The thing is, on iOS, you need to call completePurchase() in purchaseUpdatedStream.listen … just before you complete a purchase (yeah)… something like this

InAppPurchaseConnection.instance.purchaseUpdatedStream.listen((purchases) {
 purchases.forEach((purchase){
 if (purchase.status == PurchaseStatus.purchased) {
 if (Platform.isIOS) {
 InAppPurchaseConnection._instance_.completePurchase(purchase);
 }
 }
}

If you are following the tutorial from Fireship.io… I’ve added that call inside _verifyPurchase(). They added the completePurchase call in _getPastPurchases() but nothing happens if you call from there because you are going to receive always an empty list of past purchases if you don’t “confirm”.

Top comments (1)

Collapse
 
stanley12qs profile image
stanley12qs • Edited

It looks pretty neat and simple, as a separate part of code blocks. But if we talk about comprehensive and reliable payment system, especially in mobile applications, I would rather choose something completed and ready to be used, like ios payment sdk from Adapty. As I know, they can easily implement those in-app purchase systems in almost any iOS application, giving users options to purchase any item or service in this or that mobile solution.