In app purchase receipt validation fails on Server

I'm implementing in app purchase functionality on a Flutter application with NodeJs backend server. I'm facing difficulties on validating the receipt. The purchase from Flutter app is successful on sandbox environment and I'm getting the receipt url returned. Sharing the local and server receipt responses as attachments. (They seems same though).

Please list the steps you took to reproduce the issue:

  1. Implemented and tested in app purchase on Flutter application.
  2. Got the receipt response making an in app purchase.
  3. Sent the receipt to backend for validation.
  4. Try to Validate receipt data on backend. Sending the request body as follows

{ receipt-data: "receipt" password: "13e55418e6114ed6b22453b6fc314be6" exclude-old-transactions: true }

  1. Getting response

{"error":{},"status":21002,"message":"The data in the receipt-data property was malformed."}

when the data is sent base64 encoded and as string

  1. Getting response

{"error":{},"status":498,"message":"Invalid Purchase Token"}

when data is sent base64 encoded.

What did you expect to happen?

I expected to get the receipt validated and receipt details

What actually happened?

  1. Received response

{"error":{},"status":21002,"message":"The data in the receipt-data property was malformed."}

when the data is sent base64 encoded and as string

  1. Received response

{"error":{},"status":498,"message":"Invalid Purchase Token"}

when data is sent base64 encoded.

  • The app Name. - Clarity Forex
  • The app's Apple ID. - com.clarityforex.app
  • The list of In-App purchases affected. - Auto -renewable subscription, clarity_4999_1m

Please wrap your keys in your JSON in quotes. Keys must be quoted in JSON.

Example: { "receipt-data": "receipt", "password: "password_here", "exclude-old-transactions": true }

Check your receipt token twice while you copy it from the terminal or if the token is correct then there should be an issue in your environment. I faced the same issue for a long time and then I realized that while making a purchase from my testing device my device was showing the environment: XCode but XCode token are not valid for verification your purchase environment need to be sandboxed while making a purchase from the device.

If You are not getting a sandbox environment in your mobile phone then first do flutter clean, remove infoplist file from xcode, logout from your apple on your device, add sandbox tester in the apple developer console and then do login that accounts in mobile as a sandbox tester (note: do not log in for apple account do login for sandbox tester there will be an option for that in general setting)

now you will be able to make purchases in the sandbox environment and your receipt will be valid.

In app purchase receipt validation fails on Server
 
 
Q