Skip to main content
Version: SDK-5.11.2

Google Receipt Verification Example

To verify a receipt in BACKND Function, the ID of the purchased product and receipt token are required.
If you complete an in-app purchase properly using the Unity IAP function, the ProcessPurchase method below is called.

  • In an Android environment, you must reprocess the returned receipt token using the above parsing method and transmit it to BACKND Function.
  • In an iOS environment, you must transmit the returned receipt token to BACKND Function without any changes.
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
string id = string.Empty;
string token = string.Empty;
Param param = new Param();

#if UNITY_IOS
// For iOS, you can transmit the receipt token included in PurchaseEventArgs to BACKND Function without any changes.
param.Add("token", args.purchasedProduct.receipt);

// The product ID is not included in an iOS receipt,
// so in order to recharge the TBC, you must store the productID before starting the purchase process and include it in param.
param.Add("productID", productID);
// To recharge TBC, you must include the platform information to be able to check the platform when recharging the TBC in BACKND Function.
param.Add("platform", "apple");

#elif UNITY_ANDROID
// For Android, parse the receipt token included in PurchaseEventArgs
// must be parsed using the BackEnd.Game.Payment.GoogleReceiptData.FromJson method, have its ID and token value extracted,
// and transmitted to BACKND Function.
BackEnd.Game.Payment.GoogleReceiptData.FromJson(args.purchasedProduct.receipt, out id, out token);
param.Add("productID", id);
param.Add("token", token);
// To recharge TBC, you must include the platform information to be able to check the platform when recharging the TBC in BACKND Function.
param.Add("platform", "google");
#endif

// Call BACKND Function
Backend.BFunc.InvokeFunction("receiptVaildate", param, callback => {
// TODO: Perform BACKND Function and check its result
});

return PurchaseProcessingResult.Complete;
}