If you use SKPaymentQueue then this is easy. All you have to do is save the transaction in SKPaymentQueue to " step 5 " when you get the success / failure check result from your server.
If something goes wrong, between steps 1 to 5, your application still has access to the transaction in SKPaymentQueue and can process it . '
processing of incomplete transactions may begin at the beginning of your application (or some time interval, as you prefer).
Just check SKPaymentQueue to receive pending / incomplete transactions and send them to your server (as " step 2 "). If your server is still unavailable, you will not be able to go to step 5, so you will not remove the transaction from the queue, and this reprocessing will happen again and again each time the next application starts (or the next queue check interval) until .
Implementation
The implementation is also simple: SKPaymentTransactionObserver requires a < transaction observer class .
When starting the application, create an instance of the "class of transaction observers" and it should register itself on a call:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self]
Then, the "transaction observer class" receives the transactions in the method:
(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
This method allows you to process and process all outstanding transactions.
Please note that your server must be idempotent (you can handle recurring transactions if they are already processed)
After the server processes and completes steps 2 through 4 , it comes to the application with the result of success / failure and the only time you want to remove strong> this transaction from the call queue:
[[SKPaymentQueue defaultQueue] finishTransaction: transaction]
Finally, give your user the premium feature that they acquired at that moment.
source share