private void ProcessCompletedTransaction(UM_iTransaction transaction) { Debug.Log("ProcessCompletedTransaction"); //Our product has been successfully purchased or restored //So we need to provide content to our user depends on productIdentifier //Before we will provide content to the user we might want //to make sure that purchase is valid, using server-side validation //let's see check the current platform switch (Application.platform) { case RuntimePlatform.Android: //On android all the info we need is inside the ordinal android transaction //So let's get one. string productId = transaction.ProductId; AN_Inventory inventory = AN_Billing.Inventory; AN_Purchase an_purchase = inventory.GetPurchaseByProductId(productId); //Now you have asses to the all data from the original goal transaction object //That you can send to your server side and validate the purchase. Debug.Log(an_purchase.OriginalJson); break; case RuntimePlatform.IPhonePlayer: Debug.Log("go IOS"); //In case this transaction was restored, we might want to validate an original transaction. var iosTransaction = (transaction as UM_IOSTransaction).IosTransaction; if (transaction.State == UM_TransactionState.Restored) { iosTransaction = iosTransaction.OriginalTransaction; } Debug.Log("iOS Transaction Id:" + iosTransaction.TransactionIdentifier); //For iOS we need to validate the AppStoreReceipt. //So we need to get it using iOS Native var receipt = ISN_SKPaymentQueue.AppStoreReceipt; //You can now send receipt to your server side Debug.Log("Receipt loaded, byte array length: " + receipt.Data.Length); Debug.Log("Receipt As Base64 String" + receipt.AsBase64String); break; } UnlockProduct(transaction); //Once product is successfully unlocked we can finish the transaction UM_InAppService.Client.FinishTransaction(transaction); }
public void OnTransactionUpdated(UM_iTransaction transaction) { //Transactions have been updated. //Let's act accordingly PrintTransactionInfo(transaction); switch (transaction.State) { case UM_TransactionState.Purchased: case UM_TransactionState.Restored: //Our product has been successfully purchased or restored //So we need to provide content to our user depends on productIdentifier //Before we will provide content to the user we might want //to make sure that purchase is valid, using server-side validation //let's see check the current platform switch (Application.platform) { case RuntimePlatform.Android: //On android all the info we need is inside the ordinal android transaction //So let's get one. string productId = transaction.ProductId; AN_Inventory inventory = AN_Billing.Inventory; AN_Purchase an_purchase = inventory.GetPurchaseByProductId(productId); //Now you have asses to the all data from the original goal transaction object //That you can send to your server side and validate the purchase. Debug.Log(an_purchase.OriginalJson); break; case RuntimePlatform.IPhonePlayer: //For iOS we need to validate the AppStoreReceipt. //So we need to get it using iOS Native var receipt = ISN_SKPaymentQueue.AppStoreReceipt; //You can now send receipt to your server side Debug.Log("Receipt loaded, byte array length: " + receipt.Data.Length); Debug.Log("Receipt As Base64 String" + receipt.AsBase64String); break; } UnlockProduct(transaction); //Once product is successfully unlocked we can finish the transaction UM_InAppService.Client.FinishTransaction(transaction); break; case UM_TransactionState.Deferred: //Only fir iOS //iOS 8 introduces Ask to Buy, which lets parents approve any //purchases initiated by children //You should update your UI to reflect this deferred state, //and expect another Transaction Complete to be called again //with a new transaction state //reflecting the parent’s decision or after the transaction times out. //Avoid blocking your UI or gameplay while waiting //for the transaction to be updated. break; case UM_TransactionState.Failed: //Our purchase flow is failed. //We can unlock interface and tell user that the purchase is failed. UM_InAppService.Client.FinishTransaction(transaction); break; } }