private static void PrintTransactionInfo(UM_iTransaction transaction) { Debug.Log("transaction.Id: " + transaction.Id); Debug.Log("transaction.State: " + transaction.State); Debug.Log("transaction.ProductId: " + transaction.ProductId); Debug.Log("transaction.Timestamp: " + transaction.Timestamp); }
public void FinishTransaction(UM_iTransaction transaction) { if (transaction.State == UM_TransactionState.Failed) { //noting to fninish since it's failed //it will not have product or transaction id return; } var product = AN_Billing.Inventory.GetProductById(transaction.ProductId); if (product != null) { if (product.Type == AN_ProductType.inapp && product.IsConsumable) { var purchase = (transaction as UM_AndroidTransaction).Purchase; if (purchase != null) { AN_Billing.Consume(purchase, (result) => { }); } } } else { Debug.LogError("Transaction is finished, but no product found with such id"); } UM_AndroidInAppTransactions.RegisterCompleteTransaction(transaction.Id); }
public void OnTransactionUpdated(UM_iTransaction transaction) { //Transactions have been updated. //Let's act accordingly PrintTransactionInfo(transaction); switch (transaction.State) { case UM_TransactionState.Restored: case UM_TransactionState.Purchased: ProcessCompletedTransaction(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; } }
public void OnTransactionUpdated(UM_iTransaction transaction) { switch (transaction.State) { case UM_TransactionState.Restored: case UM_TransactionState.Purchased: ProcessCompletedTransaction(transaction); break; case UM_TransactionState.Deferred: //Only for 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 game play while waiting //for the transaction to be updated. UM_Preloader.UnlockScreen(); break; case UM_TransactionState.Failed: //Our purchase flow is failed. //We can unlock interface and tell user that the purchase is failed. UM_Preloader.UnlockScreen(); UM_InAppService.Client.FinishTransaction(transaction); UM_DialogsUtility.ShowMessage("Error", "We wasn't able to process your transaction. \n" + transaction.Error.Message); break; } }
private static void ProcessCompletedTransaction(UM_iTransaction transaction) { //Our product has been successfully purchased or restored //So we need to provide content to our user depends on productIdentifier //In case you want to run your custom purchase validation, you might want to get full transaction info //provided by a platform. Lear how to do it here: //https://unionassets.com/ultimate-mobile-pro/advanced-use-cases-849 switch (transaction.ProductId) { case GameConfig.k_10AmmoPack: Main.GameData.AddAmmo(10); break; default: //All our other products are skins so, let's unlock it Main.GameData.UnlockSkin(transaction.ProductId); //We also need to update skins UI, once skin is unlocked Main.GameUI.RefreshSkinsOptions(); var product = UM_InAppService.Client.GetProductById(transaction.ProductId); UM_DialogsUtility.ShowMessage("Thank you!", $"You can now try new {product.Title} skin!"); break; } UM_Preloader.UnlockScreen(); UM_InAppService.Client.FinishTransaction(transaction); }
public void FinishTransaction(UM_iTransaction transaction) { Assert.IsNotNull(transaction); var transactionsList = GetTransactionsList(); transactionsList.productIds.Remove(transaction.ProductId); SaveTransactionsList(transactionsList); }
public void FinishTransaction(UM_iTransaction transaction) { var t = (UM_IOSTransaction)transaction; var skPaymentTransaction = t.IosTransaction; ISN_SKPaymentQueue.FinishTransaction(skPaymentTransaction); }
//-------------------------------------- // Protected Methods //-------------------------------------- protected void UpdateTransaction(UM_iTransaction transaction) { if (m_Observer == null) { Debug.LogError("UpdateTransaction has been called before m_observer is set"); return; } UM_AnalyticsInternal.OnTransactionUpdated(transaction); m_Observer.OnTransactionUpdated(transaction); }
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); }
private void PrintTransactionInfo(UM_iTransaction transaction) { Debug.Log("transaction.Id: " + transaction.Id); Debug.Log("transaction.State: " + transaction.State); Debug.Log("transaction.ProductId: " + transaction.ProductId); Debug.Log("transaction.Timestamp: " + transaction.Timestamp); var title = "Transaction Updated."; var message = string.Format("ProductId: {0}. TransactionId: {1}. State: {2}", transaction.ProductId, transaction.Id, transaction.State); UM_DialogsUtility.ShowMessage(title, message); }
private void UnlockProduct(UM_iTransaction transaction) { //Reward your used based on transaction.Id switch (transaction.ProductId) { case k_CoinsProductId: UM_RewardManager.AddCoins(); break; case k_GoldStatusProductId: UM_RewardManager.ActivateGold(); break; default: Debug.LogError("Unknown product Id: " + transaction.ProductId); break; } OnProductUnlock.Invoke(); }
public void FinishTransaction(UM_iTransaction transaction) { if (transaction.State == UM_TransactionState.Failed) { //noting to finish since it's failed //it will not have product or transaction id return; } var skuDetails = GetSkuDetails(transaction.ProductId); if (skuDetails != null) { var purchase = (transaction as UM_AndroidTransaction).Purchase; Assert.IsNotNull(purchase); switch (skuDetails.Type) { case AN_BillingClient.SkuType.inapp: if (skuDetails.IsConsumable) { Consume(purchase); } else { Acknowledge(purchase); } break; case AN_BillingClient.SkuType.subs: Acknowledge(purchase); break; } } else { Debug.LogError("Transaction is finished, but no product found for id: " + transaction.ProductId); } UM_AndroidInAppTransactions.RegisterCompleteTransaction(transaction.Id); }
//-------------------------------------- // Vending //-------------------------------------- internal static void OnTransactionUpdated(UM_iTransaction transaction) { if (!UM_AnalyticsService.Client.IsInitialized) { return; } switch (transaction.State) { case UM_TransactionState.Failed: if (!Settings.FailedTransactions) { return; } Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("TransactionId", transaction.Id); data.Add("ProductId", transaction.ProductId); data.Add("Error", transaction.Error.FullMessage); UM_AnalyticsService.Client.Event("TransactionFailed", data); break; case UM_TransactionState.Purchased: if (!Settings.SuccessfulTransactions) { return; } var product = UM_InAppService.Client.GetProductById(transaction.ProductId); if (product != null) { float price = (float)product.PriceInMicros / 1000000f; UM_AnalyticsService.Client.Transaction(product.Id, price, product.PriceCurrencyCode); } break; } }
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; } }
private void OnFailedTransaction(UM_iTransaction transaction) { Assert.IsTrue(transaction.State == UM_TransactionState.Failed); m_transactionLock.Unlock(); }
public void OnTransactionUpdated(UM_iTransaction transaction) { PrintTransactionInfo(transaction); OnTransaction.Invoke(transaction); }
private void OnSuccessfuTransaction(UM_iTransaction transaction) { Assert.IsTrue(transaction.State == UM_TransactionState.Purchased); m_transactionLock.Unlock(); }
public void FinishTransaction(UM_iTransaction transaction) { //Do nothing in editor }
private void UnlockProduct(UM_iTransaction transaction) { //Reward your used based on transaction.Id }