Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What if iOS purchase receipt verification failed?

Tags:

ios

The iOS purchase receipt server verification usually works like this:

  1. User purchase on iPhone

  2. Your app sent the purchase recipt to server

  3. Server receive the recipt and send it to Apple to verify

  4. Server gets the verify results from Apple .

  5. Server sents the verify result to app

BUT what if only Step 1 is successful? For example, The app can't send request to the server in Step 2 or app can't get response from server in Step 5. The problem is user already paid. What is the best way to handle this problem?

like image 528
巫妖王 Avatar asked Jul 02 '12 02:07

巫妖王


People also ask

How to fix “verification failed” error on iOS devices?

To reset your iOS network settings and hopefully fixed the verification failed error, simply launch the “Settings” app, then go to “General > Reset > Reset Network Settings” and lastly, enter your password to complete the process. Once your network settings have been reset, you’ll have to connect to the Wi-Fi connection again.

What is an app store receipt and how does it work?

When a user makes an in-app purchase, the AppStore creates a receipt. What is App Store Receipt? In-App Purchases provide you a convenient way to monetize in-app content and features within your app. To provide access to your content, you need to pass a receipt through the receipt validation ( verifyReceipt) endpoint.

What is receipt validation ( verifyreceipt)?

To provide access to your content, you need to pass a receipt through the receipt validation ( verifyReceipt) endpoint. Receipt is an encrypted file signed with an Apple certificate. To validate purchases, you need to verify receipts on your server or the device.

How to restart if Apple verification failed again?

Force Restart If Apple Verification Failed Again 1 Press the “Volume Up” button and release it quickly. 2 Press the “Volume Down” button and release it quickly. 3 Now, press and hold the “Side” button. Don’t release it until the Apple logo appears on the screen of your device.


Video Answer


1 Answers

If you are using SKPaymentQueue, then it's easy. All you have to do is to keep the transaction in SKPaymentQueue until 'step 5' when you get a success/failure verify result from your server.

If anything goes wrong in between step 1 to 5 your app still has access to the transaction in the SKPaymentQueue and can 'reprocess' it.
The reprocessing of incomplete transactions could kick in at start of your app (or some time interval as you prefer).
Just check SKPaymentQueue to get the pending/incomplete transactions and send them to your server (just like 'step 2'). If your server is still not accessible obviously you won't get to step 5, therefore you don't remove the transaction from the queue and this reprocessing happens again and again every time at the next app start (or next queue check time interval) until is fulfilled.

Implementation

The implementation is also easy, you need to have a 'transaction observer class' of SKPaymentTransactionObserver.
At app start create an instance of the 'transaction observer class' and that should register itself by call to:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self]

Then 'transaction observer class' gets the transactions in method:

(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions

This method is where you can handle and reprocess all incomplete transactions.

Note that your server must be idempotent (i.e able to handle repeated transactions if they already been processed)
Once the server processes and completes steps 2 to 4, then it comes to app with success/failure result and that's the only time when you want to remove that transaction from the queue by call to:

[[SKPaymentQueue defaultQueue] finishTransaction: transaction]

And finally give your user the premium feature they purchased at this point.

like image 106
Sia Avatar answered Oct 16 '22 12:10

Sia