If you’ve enabled purchase verification, you can use the Adjust SDK to request purchase verification. There are two ways to verify purchases with the Adjust SDK:
- Create an
AdjustEvent
object that represents your purchase and add the following properties:productId
(String
): The product identifier of the item that was successfully purchased.purchaseToken
(String
): The purchase token generated for your successfully completed in-app purchase.
- Create an
AdjustPlayStorePurchase
object with your product ID and purchase token.
When you send purchase information with the Adjust SDK, Adjust does the following:
- Sends the information to Google Play and waits for a status response.
- Forwards the status response to the Adjust SDK.
You can access the purchase verification status by using a callback. Results are returned as AdjustPurchaseVerificationResult
objects containing the following properties:
verificationStatus
(String
): The status of the purchase.code
(int
): The status code of the purchase.message
(String
): Any message returned by Google Play.
Record event and verify purchase
public static void verifyAndTrackPlayStorePurchase(final AdjustEvent event, OnPurchaseVerificationFinishedListener callback)
To send a revenue event for verification and listen for the purchase verification status, follow these steps:
- Instantiate an
AdjustEvent
object with the your event token and set the following parameters:productId
(String
): The ID of the product that has been purchased.purchaseToken
(String
): The purchase token associated with the purchase.
- Call the
Adjust.verifyAndTrackPlayStorePurchase
method with the following arguments:event
(AdjustEvent
): Your instantiated event object.callback
(OnPurchaseVerificationFinishedListener
): A delegate callback function that receives anAdjustPurchaseVerificationResult
object as an argument.
In this example, the purchase verification response is output to the logging daemon.
val adjustEvent = AdjustEvent("abc123")adjustEvent.setRevenue(6.0, "EUR")adjustEvent.productId = "product-id"adjustEvent.purchaseToken = "purchase-token"Adjust.trackEvent(adjustEvent)
Adjust.verifyAndTrackPlayStorePurchase(adjustEvent) { result -> Log.d("Verification status: ", result.verificationStatus) Log.d("Code: ", result.code) Log.d("Message: ", result.message)}
AdjustEvent adjustEvent = new AdjustEvent("abc123");adjustEvent.setRevenue(6.0, "EUR");adjustEvent.setProductId("product-id");adjustEvent.setPurchaseToken("purchase-token");Adjust.trackEvent(adjustEvent);
Adjust.verifyAndTrackPlayStorePurchase(adjustEvent, new OnPurchaseVerificationFinishedListener() { @Override public void onFinished(AdjustPurchaseVerificationResult result) { Log.d("Verification status: ", result.verificationStatus); Log.d("Code: ", result.code); Log.d("Message: ", result.message); }});
Only verify purchase
public static void verifyPlayStorePurchase(final AdjustPlayStorePurchase purchase, final OnPurchaseVerificationFinishedListener callback)
To send a standalone purchase and listen for the purchase verification status, follow these steps:
- Instantiate an
AdjustPlayStorePurchase
with the following arguments:productId
(String
): The ID of the product that has been purchased.purchaseToken
(String
): The purchase token associated with the purchase.
- Call the
Adjust.verifyPlayStorePurchase
method with the following arguments:purchase
(AdjustPlayStorePurchase
): Your instantiated purchase object.callback
(OnPurchaseVerificationFinishedListener
): A delegate callback function that receives anAdjustPurchaseVerificationResult
object as an argument.
In this example, the purchase verification response is output to the logging daemon.
val purchase = AdjustPlayStorePurchase("product-id", "purchase-token")Adjust.verifyPlayStorePurchase(purchase) { result -> Log.d("Verification status: ", result.verificationStatus) Log.d("Code: ", result.code) Log.d("Message: ", result.message)}
AdjustPlayStorePurchase purchase = new AdjustPlayStorePurchase("product-id", "purchase-token");Adjust.verifyPlayStorePurchase(purchase, new OnPurchaseVerificationFinishedListener() { @Override public void onFinished(AdjustPurchaseVerificationResult result) { Log.d("Verification status: ", result.verificationStatus); Log.d("Code: ", result.code); Log.d("Message: ", result.message); }});