In-app purchase authentication, in_app field is empty

I am trying to check in-app purchases using the post iOS 5 method of sending it to my server and checking it there. The code in my application is pretty simple:

let url = NSBundle.mainBundle().appStoreReceiptURL! let receipt = NSData(contentsOfURL: url) // Get the receipt data from the app bundle if let receipt = receipt { let requestContents: [String: NSString] = [ "receipt_data" : receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions([])) ] // send the receipt using NSURLSessionDataTask } 

The server side simply transfers the data to Apple, and then analyzes it and sends it back to the application. The problem is that the in_app field in_app unpredictably empty for a large number of clients (as you can see from the logging), but I cannot reproduce this problem on any test devices or beta testers.

What can cause this field to be empty? Following Apple's recommendation, I used SKReceiptRefreshRequest when this happens, but it doesn't seem to help.

+5
source share
1 answer

According to Apple's documentation, this is the expected behavior in certain cases, but, unfortunately, it is not documented what causes this behavior. I suspect that this can happen when a user’s credit card verification takes too long or some other temporary payment problem delays the processing of the transaction, so this cannot be reproduced in the real world. Instead, you should use unit tests and dummy data to make sure your logic is working correctly.

A possible workaround is to update the check a couple of times with a delay of a few seconds between requests. Ultimately, if this fails, you must inform the user that the verification failed, and provide an opportunity to try again.

0
source

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


All Articles