If you’ve enabled purchase verification, you can use the Adjust SDK to request purchase verification.
To use Purchase verification, you first need to set up your app for purchase verification in the Adjust suite. See Set up purchase verification for your app for instructions.
There are two ways to verify purchases with the Adjust SDK:
- Create an
ADJEvent
object that represents your purchase and add the following properties:transactionId
(NSString
): The ID of the transaction you want to verify.productId
(NSString
): The product identifier of the item that was successfully purchased.
- Create an
ADJAppStorePurchase
object with your transaction ID and product ID.
If you use revenue events to measure your purchases in Adjust, you should use the ADJEvent
class. If you only want to verify a purchase but don’t want to associate it with an event, use the ADJAppStorePurchase
class.
When you send purchase information with the Adjust SDK, Adjust does the following:
- Sends the information to the App Store 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 ADJPurchaseVerificationResult
objects containing the following properties:
verificationStatus
(NSString
): The status of the purchase.code
(int
): The status code of the purchase.message
(NSString
): Any message returned by the App Store.
Record event and verify purchase
- (void)verifyAndTrackAppStorePurchase:(nonnull ADJEvent *)event withCompletionHandler:(nonnull ADJVerificationResultBlock)completion;
To send a revenue event for verification and listen for the purchase verification status, follow these steps:
- Instantiate an
ADJEvent
object with the your event token and set the following parameters:transactionId
(NSString
): The ID of the transaction you want to verify.productId
(NSString
): The product identifier of the item that was successfully purchased.
- Call the
Adjust.verifyAndTrackPlayStorePurchase
method with the following arguments:event
(ADJEvent
): Your instantiated event object.callback
(ADJVerificationResultBlock
): A delegate callback function that receives anADJPurchaseVerificationResult
object as an argument.
In this example, the purchase verification response is output to the logging daemon.
let event = ADJEvent(eventToken: "g3mfiw")!event.setProductId("product-id")event.setTransactionId("transaction-id")
Adjust.verifyAndTrackAppStorePurchase(event) { verificationResult in print("Verification status: \(verificationResult.verificationStatus)") print("Code: \(verificationResult.code)") print("Message: \(verificationResult.message)")}
ADJEvent *event = [[ADJEvent alloc] initWithEventToken:yourEventToken];[event setProductId:@"product-id"];[event setTransactionId:@"transaction-id"];
[Adjust verifyAndTrackAppStorePurchase:event withCompletionHandler:^(ADJPurchaseVerificationResult * _Nonnull verificationResult) { NSLog(@"Verification status: %@", verificationResult.verificationStatus); NSLog(@"Code: %d", verificationResult.code); NSLog(@"Message: %@", verificationResult.message);}];
Only verify purchase
- (void)verifyAppStorePurchase:(nonnull ADJAppStorePurchase *)purchase withCompletionHandler:(nonnull ADJVerificationResultBlock)completion;
To send a standalone purchase and listen for the purchase verification status, follow these steps:
- Instantiate an
ADJAppStorePurchase
with the following arguments:transactionId
(NSString
): The ID of the transaction you want to verify.productId
(NSString
): The product identifier of the item that was successfully purchased.
- Call the
Adjust.verifyAppStorePurchase
method with the following arguments:purchase
(ADJAppStorePurchase
): Your instantiated purchase object.callback
(ADJVerificationResultBlock
): A delegate callback function that receives anADJPurchaseVerificationResult
object as an argument.
In this example, the purchase verification response is output to the logging daemon.
let appStorePurchase = ADJAppStorePurchase(transactionId: yourTransactionId, productId: yourProductId;
Adjust.verifyAppStorePurchase(appStorePurchase) { verificationResult in print("Verification status: \(verificationResult.verificationStatus)") print("Code: \(verificationResult.code)") print("Message: \(verificationResult.message)")}
ADJAppStorePurchase *appStorePurchase = [[ADJAppStorePurchase alloc] initWithTransactionId:yourTranscationId productId:yourProductId];
[Adjust verifyAppStorePurchase:appStorePurchase withCompletionHandler:^(ADJPurchaseVerificationResult * _Nonnull verificationResult) { NSLog(@"Verification status: %@", verificationResult.verificationStatus); NSLog(@"Code: %d", verificationResult.code); NSLog(@"Message: %@", verificationResult.message);}];
If you’ve enabled purchase verification, you must send additional information with your purchase events to verify them. When Adjust’s servers receive this information in an ADJEvent
object, they forward it to Apple to verify the purchase.
To verify a purchase, instantiate an ADJEvent
object with your event token and set the following properties:
transactionId
(NSString
): ThetransactionIdentifier
value of the successfully completed purchaseproductId
(NSString
): The product identifier of the item that was successfully purchasedreceipt
(NSData
): The signed receipt containing the information about the successfully completed purchase
See Send event information for more information on the ADJEvent
class.
let receiptURL = Bundle.main.appStoreReceiptURL;let receipt = try Data(contentsOf: receiptURL, options: .alwaysMapped)
let event = ADJEvent(eventToken: "abc123")event?.setRevenue(6.0, currency: "EUR");event?.setTransactionId("transaction-id");event?.setProductId("product-id");event?.setReceipt(receipt);Adjust.trackEvent(event)
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];ADJEvent *event = [ADJEvent eventWithEventToken::@"your-event-token"];[event setRevenue:6.0 currency:@"EUR"];[event setTransactionId:@"transaction-id"];[event setProductId:@"product-id"];[event setReceipt:receipt];[Adjust trackEvent:event];