Receipt Validation for Android

You can perform receipt validation for in-app purchases in the Google Play Store. 

The Receipt Validation Flow is as follows:

1. User performs an in-app purchase

2. Google Play Store responds with success or fail (authentication)

3. Developer calls the SDK Receipt Validation function

public static void validateAndTrackInAppPurchase(Context context, 
String publicKey, String signature, String purchaseData, String price,
String currency, HashMap<String, String> additionalParameters);
  • Signature and purchase data = The developer gets it from google api when purchase succeeded. 
  • Signature = transaction signature
  • purchase data = is the actual product purchased in json format.
  • API Key = is the public key, the developer gets this from the Google portal

For example:

AppsFlyerLib.getInstance().validateAndTrackInAppPurchase(this.getApplicationContext(),
base64EncodedPublicKey, dataSignature, purchaseData, "0.99", "USD", null);

4. Developer must register to validate listener to receive the callbacks.

5. The SDK calls AppsFlyer's validation service with the receipt data

6. AppsFlyer's validation service validates the transaction with Google's servers

7. Google's servers respond with success or failure

8. AppsFlyer's validation service transfers the response to the SDK

9. The SDK transfers the receipt validation response to the App

Please see below a sample of a Receipt Validation response:

AppsFlyerLib.getInstance().registerValidatorListener(this, new AppsFlyerInAppPurchaseValidatorListener(){
public void onValidateInApp() {
Log.d(AppsFlyerLib.LOG_TAG, "onValidateInApp success");
}

public void onValidateInAppFailure(String var1) {
Log.d(AppsFlyerLib.LOG_TAG, "onValidateInAppFailure called " + var1);
}
});

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request
Powered by Zendesk