What should I do if the iOS purchase confirmation check fails?

Verification of the iOS purchase verification server usually works as follows:

  • IPhone custom purchase

  • Your application has sent a purchase request to the server

  • The server receives a response and sends it to Apple to confirm

  • The server receives verification results from Apple.

  • The server sends the verification result to the application

BUT what if Step 1 was successful? For example, the application cannot send a request to the server in step 2, or the application cannot receive a response from the server in step 5. The problem is that the user has already paid. What is the best way to deal with this problem?

+6
source share
1 answer

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.

+7
source

Source: https://habr.com/ru/post/919467/


All Articles