Usage examples
These operations allow you to configure the plugin.
Getting a Receipt for Revenue
The example below is based on the use of Unity IAP.
using Io.AppMetrica;
...
// 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 an instance of the YandexAppMetricaRevenue class.
Revenue revenue = new Revenue(price, currency);
if (product.receipt != null) {
// Creating an instance of the YandexAppMetricaReceipt class.
Revenue.Receipt yaReceipt = new Revenue.Receipt();
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.ReceiptValue = yaReceipt;
}
// Sending data to the AppMetrica server.
AppMetrica.ReportRevenue(revenue);
}
return PurchaseProcessingResult.Complete;
}
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.
Was the article helpful?
Previous