Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto renewable IAP subscription user flow & refreshing receipts

I am using the library RMStore - here's what I have currently.

1) Purchase auto renewable subscription & verify the returned receipt.

[[RMStore defaultStore]addPayment:[Environment environment].premiumProductIAPId success:^(SKPaymentTransaction *transaction) {
  [[RMStore defaultStore].receiptVerificator verifyTransaction:transaction success:^{

    //enable premium service

  } failure:^(NSError *error) {

  }];
} failure:^(SKPaymentTransaction *transaction, NSError *error) {

}];

2) On each app launch check the subscription is active for the date and enable the premium service if it is

RMAppReceipt *appReceipt = [RMAppReceipt bundleReceipt];
if (appReceipt){
  NSInteger isActive = [appReceipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]];
  //enable premium service if active
}

3) If user launches app on another device allow them to restore purchases by refreshing the receipt if it exists and checking if there is an active subscription in the purchases.

"In most cases, all your app needs to do is refresh its receipt and deliver the products in its receipt."

- That's from the guide. Here's the code:

[[RMStore defaultStore]refreshReceiptOnSuccess:^{

  if ([receipt containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]]){
   //enable
  }else{ 
   //no longer active
  }
} failure:^(NSError *error) {

}];

My questions:

  • When RMStore checks if the subscription is active it can return no, I look in the receipt and it is correct and I am assuming it hasn't been auto renewed. When I go to purchase another subscription I get a message from itunes saying I'm already subscribed. On subsequent launch I see the new receipt. This indicates the receipt needed to be refreshed on launch, but I don't want to refresh it as it brings up the username & password pop up which is unnecessary. What is the best practice here?
  • Am I restoring the subscriptions for another device the right way? It seems to sometimes take more than one attempt to restore the subscriptions.
  • Is there any need apart from record keeping to store the subscriptions on my server?
like image 941
jeh Avatar asked Sep 26 '22 23:09

jeh


1 Answers

I'm going to try and answer my question.

There may be a renewal which is not detected first thing on launch hence the subscription appears inactive.

I added an observer to listen for finished transactions (RMStore extends this StoreKit functionality).

Each time I receive this notification I check the (now updated) receipt for an active subscription and enable the premium service if there is one.

- (void)storePaymentTransactionFinished:(NSNotification*)notification
{
  BOOL isActive = [[RMAppReceipt bundleReceipt] containsActiveAutoRenewableSubscriptionOfProductIdentifier:[Environment environment].premiumProductIAPId forDate:[NSDate date]];
  if (isActive){
    //enable premium
  }
}  

This seems to be working. If anyone has any other suggestions let me know.

like image 164
jeh Avatar answered Sep 30 '22 08:09

jeh