Usage examples

These operations allow you to configure the plugin.

  1. Getting a Receipt for Revenue

Getting a Receipt for Revenue

The example below is based on the use of Unity IAP.

// Declaration of the Receipt structure for getting information about the IAP.
[System.Serializable]
public struct Receipt
{
    public string Store;
    public string TransactionID;
    public string Payload;
}

// Additional information about the IAP for Android.
[System.Serializable]
public struct PayloadAndroid
{
    public string Json;
    public string Signature;
}

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    var product = args.purchasedProduct;
    if(String.Equals(product.definition.id, kProductIDConsumable, StringComparison.Ordinal)) {
        string currency = product.metadata.isoCurrencyCode;
        decimal price = product.metadata.localizedPrice;

        // Creating the instance of the YandexAppMetricaRevenue class.
        YandexAppMetricaRevenue revenue = new YandexAppMetricaRevenue(price, currency);
        if(product.receipt != null) {
            // Creating the instance of the YandexAppMetricaReceipt class.
            YandexAppMetricaReceipt yaReceipt = new YandexAppMetricaReceipt();
            Receipt receipt = JsonUtility.FromJson<Receipt>(product.receipt);
#if UNITY_ANDROID
            PayloadAndroid payloadAndroid = JsonUtility.FromJson<PayloadAndroid>(receipt.Payload);
            yaReceipt.Signature = payloadAndroid.Signature;
            yaReceipt.Data = payloadAndroid.Json;
#elif UNITY_IPHONE
            yaReceipt.TransactionID = receipt.TransactionID;
            yaReceipt.Data = receipt.Payload;
#endif
            revenue.Receipt = yaReceipt;
        }
        // Sending data to the AppMetrica server.
        AppMetrica.Instance.ReportRevenue(revenue);
    }
    return PurchaseProcessingResult.Complete;
}
Copied to clipboard

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.