public UM_IOSTransaction(ISN_SKPaymentTransaction transaction) { m_id = transaction.TransactionIdentifier; m_productId = transaction.ProductIdentifier; m_unitxTimestamp = SA_Unix_Time.ToUnixTime(transaction.Date); switch (transaction.State) { case ISN_SKPaymentTransactionState.Deferred: m_state = UM_TransactionState.Deferred; break; case ISN_SKPaymentTransactionState.Failed: m_state = UM_TransactionState.Failed; break; case ISN_SKPaymentTransactionState.Restored: m_state = UM_TransactionState.Restored; break; case ISN_SKPaymentTransactionState.Purchased: m_state = UM_TransactionState.Purchased; break; } m_error = transaction.Error; m_iosTransaction = transaction; }
//-------------------------------------- // Private Methods //-------------------------------------- private static void UnlockProducts(ISN_SKPaymentTransaction transaction) { //At this point user already paid for content, so we need to provide it //Unless, we want to make sure that payment was legit, and nobody trying to hack us //In ordrer to do it, we have to use server side verification, you can read more about it here: //https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1 // //this step isn't required. Use it only if you want to make sure that payment is 100% legit //So far let's just print a Base64 receipt data // Debug.Log("Receipt: " + ISN_SKPaymentQueue.AppStoreReceipt.AsBase64StringString); switch (transaction.ProductIdentifier) { case SMALL_PACK: //code for adding small game money amount here break; case NC_PACK: //code for unlocking cool item here break; } //After contect was provided to use we can finaly finish the transaction ISN_SKPaymentQueue.FinishTransaction(transaction); }
public void FinishTransaction(UM_iTransaction transaction) { UM_IOSTransaction t = (UM_IOSTransaction)transaction; ISN_SKPaymentTransaction skPaymentTransaction = t.IosTransaction; ISN_SKPaymentQueue.FinishTransaction(skPaymentTransaction); }
public void AddPayment(string productIdentifier) { SA_Coroutine.WaitForSeconds(DelayTime, () => { var produdct = ISN_SKPaymentQueue.GetProductById(productIdentifier); var tranasaction = new ISN_SKPaymentTransaction(produdct, ISN_SKPaymentTransactionState.Purchased); m_transactionUpdated.Invoke(tranasaction); }); }
public void RestoreCompletedTransactions() { SA_Coroutine.WaitForSeconds(DelayTime, () => { foreach (var product in ISN_SKPaymentQueue.Products) { if (product.Type == ISN_SKProductType.NonConsumable) { var tranasaction = new ISN_SKPaymentTransaction(product, ISN_SKPaymentTransactionState.Restored); m_transactionUpdated.Invoke(tranasaction); } } m_restoreTransactionsComplete.Invoke(new SA_Result()); }); }
//-------------------------------------- // ISN_TransactionObserver implementation //-------------------------------------- public void OnTransactionUpdated(ISN_SKPaymentTransaction transaction) { //Transactions have been updated. //Let's acti accordinaly Debug.Log("transaction JSON: " + JsonUtility.ToJson(transaction)); Debug.Log("OnTransactionComplete: " + transaction.ProductIdentifier); Debug.Log("OnTransactionComplete: state: " + transaction.State); switch (transaction.State) { case ISN_SKPaymentTransactionState.Purchasing: //No actions is reuiredhere, we probably don't even have a ProductIdentifier //but we can use this callback to show preloader for example, since we know that user is currently //working on this transaction break; case ISN_SKPaymentTransactionState.Purchased: case ISN_SKPaymentTransactionState.Restored: //Our product been succsesly purchased or restored //So we need to provide content to our user depends on productIdentifier UnlockProducts(transaction); break; case ISN_SKPaymentTransactionState.Deferred: //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 ISN_SKPaymentTransactionState.Failed: //Our purchase flow is failed. //We can unlock intrefase and repor user that the purchase is failed. Debug.Log("Transaction failed with error, code: " + transaction.Error.Code); Debug.Log("Transaction failed with error, description: " + transaction.Error.Message); //at this point we just need to finish the transaction ISN_SKPaymentQueue.FinishTransaction(transaction); break; } if (transaction.State == ISN_SKPaymentTransactionState.Failed) { Debug.Log("Error code: " + transaction.Error.Code + "\n" + "Error description:" + transaction.Error.Message); } else { Debug.Log("product " + transaction.ProductIdentifier + " state: " + transaction.State.ToString()); } }
//-------------------------------------- // ISN_TransactionObserver implementation //-------------------------------------- public void OnTransactionUpdated(ISN_SKPaymentTransaction transaction) { var um_transaction = new UM_IOSTransaction(transaction); switch (transaction.State) { case ISN_SKPaymentTransactionState.Purchasing: break; case ISN_SKPaymentTransactionState.Purchased: case ISN_SKPaymentTransactionState.Restored: UpdateTransaction(um_transaction); break; case ISN_SKPaymentTransactionState.Deferred: UpdateTransaction(um_transaction); break; case ISN_SKPaymentTransactionState.Failed: UpdateTransaction(um_transaction); break; } }
public void OnTransactionRemoved(ISN_SKPaymentTransaction result) { //Your application does not typically need to anything on this event, //but it may be used to update user interface to reflect that a transaction has been completed. }
public void FinishTransaction(ISN_SKPaymentTransaction transaction) { SA_Coroutine.WaitForSeconds(DelayTime, () => { m_transactionRemoved.Invoke(transaction); }); }
public void FinishTransaction(ISN_SKPaymentTransaction transaction) { #if ((UNITY_IPHONE || UNITY_TVOS) && STORE_KIT_API_ENABLED) _ISN_FinishTransaction(transaction.TransactionIdentifier); #endif }