2

I am having an app in which I am implementing Auto Renewable Subscription In App Purchase.

I am following this link link

With that, I am getting the alert successfully to purchase but when I press it again, it asks me every time to purchase.

There are two methods mentioned in it about checking an expiration date and if the product is expired.

But I am unable to found the proper solution from that.

Can anyone please help me???

Any help will be appreciated.

Thanks in advance.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • 2
    what is the issue? If you are testing using sandbox account then Actual duration Test duration 1 week =3 minutes 1 month=5 minutes 2 months=10 minutes 3 months=15 minutes 6 months=30 minutes 1 year=1 hour – Jen Jose May 14 '15 at 12:52
  • Ohhhh!!! I didn't know that... Thanks.... Ok but can you please let me know from which code can we check if user has cancelled the subscription? Is this restorable??? – Manthan May 14 '15 at 13:09
  • I have set it for 1 year but it is showing me every time I run the app. User can cancel the subscription outside the app. So how to check from code that user has cancelled the subscription? – Manthan May 14 '15 at 13:13
  • if you are doing auto renewable subscription then the only way to know if the subscription has been cancelled is by checking the transaction receipt! – Jen Jose May 14 '15 at 13:14
  • Can you please show me with the line of code and where to put it??? – Manthan May 14 '15 at 13:15
  • If I have set it for one year, then will it charge only once throughout the year? – Manthan May 14 '15 at 13:16
  • yes! and after one year itunes will automatically deduct amount for another year. Maybe it notifies the user before deducting again after a year. – Jen Jose May 14 '15 at 13:20
  • Do you know how to cancel a subscription in a sandbox environment? and this subscription is not restorable, right? If user deletes the app and reinstalls it, he just have to upgrade but no money will be deducted again. Right? – Manthan May 14 '15 at 13:22
  • 2
    unfortunately its not possible to cancel a subscription from sandbox account! that is why they decrease the subscription period to minutes . – Jen Jose May 14 '15 at 13:37
  • @JennyJose: Have you done this in app? Can you please provide me a code for this? – Manthan May 15 '15 at 04:23
  • Actually, in my app we are doing server side verification! The same code in php.. I send the receipt ID through web service and they check whether the subscription has expired or not – Jen Jose May 15 '15 at 04:42
  • @JennyJose:Ok. No Probs... But one thing is that do we need to implement restore purchase? What if user deletes the app and reinstalls? – Manthan May 15 '15 at 04:45
  • 1
    yes! restore purchase is needed! sometimes Apple rejects the app just because you have not provided "Restore Purchases". So make sure you do that.. – Jen Jose May 15 '15 at 04:56
  • But there is no code for that in the link above... – Manthan May 15 '15 at 04:59
  • Even if I successfully purchases it, it goes to both methods, "Successful transaction" and "Restore" in switch case. – Manthan May 15 '15 at 05:01

1 Answers1

3

Check this link

https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

Apple suggests that the receipt validation should be done at the server side.

The status code received if the subscription has expired is 21006.


For RESTORING PURCHASES

- (IBAction)retoreinApp:(id)sender
{
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

    self.restoringInAppStatusLabel.hidden = NO;

}

It will call the method after getting restore details :

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    UIAlertView *alert ;
    if(queue.transactions.count >0)
    {
        for (SKPaymentTransaction *transaction in queue.transactions)
        {
            NSString *temp = transaction.payment.productIdentifier;

          NSLog(@"Product Identifier string is %@",temp);

        }

        alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"All your previous transactions are restored successfully." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    }
    else
    {
        alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"No transactions in your account to be restored." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    }
    [alert show];

}
Jen Jose
  • 3,995
  • 2
  • 19
  • 36
  • Please note that validation of the receipt on the device is *not* the recommended procedure. Validation is recommended via the encryption style on >= iOS7 or via a server. – Chris Prince May 15 '15 at 16:06
  • Yes! I had mentioned it in the comments that in my project we are doing server side authentication! – Jen Jose May 18 '15 at 05:13
  • In your code, you are contacting *Apple's* validation server. This is not the recommended procedure. – Chris Prince May 18 '15 at 05:49
  • Yes Chris! This is not the recommended procedure and I have already told Manthan that I am doing server side validation. – Jen Jose May 18 '15 at 05:57