Configuring sending purchase information

Attention. AppMetrica doesn't allow you to create segments of the “test” and “not test” purchases. To debug revenue sending, use the additional API key (Android | iOS (Objective-C) | iOS (Swift)).

You can validate in-app purchases on iOS and Android. Validation is necessary to filter out purchases that were made from hacked apps. This is important for game apps.

Currently, AppMetrica does not support purchase validation. However, you can send validated purchases via the SDK.

  1. Sending Revenue with validation
  2. Sending Revenue without validation

Sending Revenue with validation

This section explains the steps for setting up AppMetrica to send revenue:

To send purchase information with the validation, do the following in the handler for the purchase:
  1. Create the Revenue.Receipt instance with information about the purchase and signature. You must use it when creating the Revenue instance in Revenue.Builder.withReceipt (Revenue.Receipt receipt).
  2. Create the Revenue instance using the Revenue.Builder constructor.
  3. Send the Revenue instance using the YandexMetrica.reportRevenue(Revenue revenue) method.
void handlePurchase(Purchase purchase) {
    ...
    // Creating the Revenue.Receipt instance.
    // It is used for checking purchases in Google Play.
    Revenue.Receipt revenueReceipt = Revenue.Receipt.newBuilder()
            .withData(purchase.getOriginalJson())
            .withSignature(purchase.getSignature())
            .build();
    // Creating the Revenue instance.
    Revenue revenue = Revenue.newBuilderWithMicros(99000000, Currency.getInstance("RUB"))
            .withProductID("com.yandex.service.299")
            .withQuantity(2)
            .withReceipt(revenueReceipt)
            .withPayload("{\"source\":\"Google Play\"}")
            .build();
    // Sending the Revenue instance.
    YandexMetrica.reportRevenue(revenue);
}

Sending Revenue without validation

This section explains the steps for setting up AppMetrica to send revenue:

To send information about a purchase without validation:
  1. Create the Revenue instance using the Revenue.Builder constructor.
  2. (Optional) To group purchases, specify the OrderID in the Revenue.Builder.withPayload(String payload) method.
  3. Send the Revenue instance using the YandexMetrica.reportRevenue(Revenue revenue) method.
// Creating the Revenue instance.
Revenue revenue = Revenue.newBuilderWithMicros(99000000, Currency.getInstance("RUB"))
        .withProductID("com.yandex.service.299")
        .withQuantity(2)
        // To group purchases, pass the OrderID parameter in the .withPayload(String payload) method.
        .withPayload("{\"OrderID\":\"Identifier\", \"source\":\"Google Play\"}")
        .build();
// Sending the Revenue instance.
YandexMetrica.reportRevenue(revenue);