1

I am using Storekit-2 for InApp purchase. The product is consumable. After the purchase is successful, I need to call API and backend will grant 200 coins to that user.

Now, users can try to access the data with no subscription by simply executing requests to the server. For this reason, I will have to validate receipt on server side.

I have done some R&D and get to know that I need to pass the following receiptData to server.

// Get the receipt if it's available.
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
    FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {

    do {
        let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
        print(receiptData)
        let receiptString = receiptData.base64EncodedString(options: [])
        // Read receiptData.
    }
    catch { print("Couldn't read receipt data with error: " + error.localizedDescription) 
    }
}

Then the server should send a request to Apple’s verification server at the following URL:

Production: https://buy.itunes.apple.com/verifyReceipt

Sandbox: https://sandbox.itunes.apple.com/verifyReceipt

I also read one article and they suggest to use following:

switch try await product.purchase() {
case .success(let result):
    let jws = result.jwsRepresentation
    // send jws to your backend

Is that the right way to do? Also my question is, the following receiptData is not for specific transaction, i.e it is not generated from a transaction. Then how specific transaction is verified?

19
  • 1
    The verification endpoint is deprecated. You can use the server endpoints with a transaction id or you can use the signed transaction data from your app Commented Jan 31 at 9:01
  • 1
    You can get the transaction identifier from your app and sending that to your server and then your server can use the Apple server endpoints to validate the transaction. Or send the jwsRepresentation to your server. Receipt validation is deprecated. Commented Jan 31 at 10:17
  • 1
    Yes. There are also libraries to simplify the verification process Commented Jan 31 at 12:04
  • 1
    You can't get actual money debited until the app is in the store. A TestFlight build will allow the purchase process to be tested but no money is charged (and subscriptions expire at a faster rate) Commented Feb 5 at 9:39
  • 1
    The price is related to the currency. It reflects how much the purchaser paid in the currency specified. Conversion to your pay out currency will occur when Apple transfers the money to your account and will reflect the exchange rate in effect at the time for your bank. You cannot convert the price from the transaction Commented Feb 7 at 11:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.