Example #1
0
    private void onProductStateDeferred(string productIdentifier)
    {
        IOSStoreKitResult response = new IOSStoreKitResult(productIdentifier, InAppPurchaseState.Deferred);


        OnTransactionComplete(response);
    }
    //--------------------------------------
    // Event Handlers
    //--------------------------------------


    private void IOS_OnTransactionComplete(IOSStoreKitResult responce)
    {
        UM_InAppProduct p = UltimateMobileSettings.Instance.GetProductByIOSId(responce.ProductIdentifier);

        if (p != null)
        {
            UM_PurchaseResult r = new UM_PurchaseResult();
            r.product          = p;
            r.IOS_PurchaseInfo = responce;


            switch (r.IOS_PurchaseInfo.State)
            {
            case InAppPurchaseState.Purchased:
            case InAppPurchaseState.Restored:
                r.isSuccess = true;
                break;

            case InAppPurchaseState.Deferred:
            case InAppPurchaseState.Failed:
                r.isSuccess = false;
                break;
            }

            SendPurchaseFinishedEvent(r);
        }
        else
        {
            SendNoTemplateEvent();
        }
    }
Example #3
0
        public void OnPurchaseSucceeded(IOSStoreKitResult item)
        {
            switch (item.State)
            {
            case InAppPurchaseState.Deferred:
                return;

            case InAppPurchaseState.Restored:
                ProductDefinition definition = definitions.FirstOrDefault(x => x.storeSpecificId == item.ProductIdentifier);
                if (definition == null || definition.type == ProductType.Subscription || DBManager.isPurchased(definition.id))
                {
                    return;
                }
                break;

            case InAppPurchaseState.Failed:
                OnPurchaseFailed(item.Error.Message, item.Error.Code);
                return;
            }

            string transactionId = item.TransactionIdentifier;

            #if UNITY_EDITOR
            //allow for multiple test purchases with unique transactions
            transactionId = (System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds.ToString();
            #endif

            callback.OnPurchaseSucceeded(item.ProductIdentifier, item.Receipt, transactionId);
        }
Example #4
0
    //--------------------------------------
    // IOS Listners
    //--------------------------------------


    private void IOS_OnTransactionComplete(IOSStoreKitResult responce)
    {
        UM_InAppProduct p = UltimateMobileSettings.Instance.GetProductByIOSId(responce.ProductIdentifier);

        if (p != null)
        {
            UM_PurchaseResult r = new UM_PurchaseResult();
            r.product          = p;
            r.IOS_PurchaseInfo = responce;
            SendPurchaseEvent(r);
        }
        else
        {
            SendNoTemplateEvent();
        }
    }
Example #5
0
    private static void OnTransactionComplete(IOSStoreKitResult result)
    {
//        Debug.Log("OnTransactionComplete: " + result.ProductIdentifier);
//        Debug.Log("OnTransactionComplete: state: " + result.State);
//        Debug.Log("-----------------------------start");
//        Debug.Log("OnTransactionComplete: Receipt: " + result.Receipt);
        switch (result.State)
        {
        case InAppPurchaseState.Purchased:
        case InAppPurchaseState.Restored:
            //Our product been succsesly purchased or restored
            //So we need to provide content to our user depends on productIdentifier
            _mai_ProductId = result.ProductIdentifier;
            _mai_Receipt   = result.Receipt;
            PlayerPrefs.SetString("LatestReceipt", _mai_Receipt);     //标记receipt,用于补单

            VerificationReceipt(_mai_Receipt);

//                Debug.Log("=========================, 新 OnTransactionComplete");
//                Debug.Log("=========================, 新 result.ProductIdentifier = " + result.ProductIdentifier);
//                Debug.Log("=========================, 新 result.State = " + result.State);
//                Debug.Log("=========================, 新 result.TransactionIdentifier = " + result.TransactionIdentifier);
//                Debug.Log("=========================, 新 result.Receipt = " + result.Receipt);
            break;

        case InAppPurchaseState.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.
            IOSNativePopUpManager.showMessage("提示", "充值超时");
            LoadingBlockCtrl.Hide();
            clearIAPCache();
            break;

        case InAppPurchaseState.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: " + result.Error.Code);
//                Debug.Log("Transaction failed with error, description: " + result.Error.Description);
            IOSNativePopUpManager.showMessage("提示", "充值未完成");
            LoadingBlockCtrl.Hide();
            clearIAPCache();
            break;
        }
    }
Example #6
0
    private void FireProductBoughtEvent(string productIdentifier, string applicationUsername, string receipt, string transactionIdentifier, bool IsRestored)
    {
        InAppPurchaseState state;

        if (IsRestored)
        {
            state = InAppPurchaseState.Restored;
        }
        else
        {
            state = InAppPurchaseState.Purchased;
        }

        IOSStoreKitResult response = new IOSStoreKitResult(productIdentifier, state, applicationUsername, receipt, transactionIdentifier);



        lastPurchasedProduct = response.ProductIdentifier;
        OnTransactionComplete(response);
    }
Example #7
0
    private static void OnTransactionComplete(IOSStoreKitResult result)
    {
        Debug.Log("OnTransactionComplete: " + result.ProductIdentifier);
        Debug.Log("OnTransactionComplete: state: " + result.State);
        instance.m_bPurchased = true;
        switch (result.State)
        {
        case InAppPurchaseState.Purchased:
        case InAppPurchaseState.Restored:
            //Our product been succsesly purchased or restored
            //So we need to provide content to our user depends on productIdentifier
            UnlockProducts(result.ProductIdentifier);
            instance.m_eStatus = STATUS.SUCCESS;
            break;

        case InAppPurchaseState.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.
            instance.m_eStatus = STATUS.FAILD;
            break;

        case InAppPurchaseState.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: " + result.Error.Code);
            Debug.Log("Transaction failed with error, description: " + result.Error.Description);
            instance.m_eStatus = STATUS.FAILD;
            break;
        }

        if (result.State == InAppPurchaseState.Failed)
        {
            IOSNativePopUpManager.showMessage("Transaction Failed", "Error code: " + result.Error.Code + "\n" + "Error description:" + result.Error.Description);
        }
        else
        {
            IOSNativePopUpManager.showMessage("Store Kit Response", "product " + result.ProductIdentifier + " state: " + result.State.ToString());
        }
    }
Example #8
0
    private static void HandleOnTransactionComplete(IOSStoreKitResult res)
    {
        switch (res.State)
        {
        case InAppPurchaseState.Purchased:
            IOSProductTemplate tpl = IOSInAppPurchaseManager.Instance.GetProductById(res.ProductIdentifier);
            if (tpl != null)
            {
                ISN_SoomlaGrow.PurchaseFinished(tpl.Id, tpl.PriceInMicros.ToString(), tpl.CurrencyCode);
            }
            break;

        case InAppPurchaseState.Failed:
            if (res.Error.Code == (int)IOSTransactionErrorCode.SKErrorPaymentCancelled)
            {
                ISN_SoomlaGrow.PurchaseCanceled(res.ProductIdentifier);
            }
            else
            {
                ISN_SoomlaGrow.PurchaseError();
            }
            break;
        }
    }
	private static void OnTransactionComplete (IOSStoreKitResult result) {

		Debug.Log("OnTransactionComplete: " + result.ProductIdentifier);
		Debug.Log("OnTransactionComplete: state: " + result.State);

		switch(result.State) {
		case InAppPurchaseState.Purchased:
		case InAppPurchaseState.Restored:
			//Our product been succsesly purchased or restored
			//So we need to provide content to our user depends on productIdentifier
			UnlockProducts(result.ProductIdentifier);
			break;
		case InAppPurchaseState.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 InAppPurchaseState.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: " + result.Error.Code);
			Debug.Log("Transaction failed with error, description: " + result.Error.Description);


			break;
		}

		if(result.State == InAppPurchaseState.Failed) {
			IOSNativePopUpManager.showMessage("Transaction Failed", "Error code: " + result.Error.Code + "\n" + "Error description:" + result.Error.Description);
		} else {
			IOSNativePopUpManager.showMessage("Store Kit Response", "product " + result.ProductIdentifier + " state: " + result.State.ToString());
		}

	}
Example #10
0
    private void SendTransactionFailEvent(string productIdentifier, string errorDescribtion, IOSTransactionErrorCode errorCode)
    {
        IOSStoreKitResult response = new IOSStoreKitResult(productIdentifier, new SA.Common.Models.Error((int)errorCode, errorDescribtion));

        OnTransactionComplete(response);
    }
Example #11
0
    //private static void OnTransactionComplete (IOSStoreKitResult result) {
    private void OnTransactionComplete(IOSStoreKitResult result)
    {
        Debug.Log("OnTransactionComplete: " + result.ProductIdentifier);
        Debug.Log("OnTransactionComplete: state: " + result.State);

        switch (result.State)
        {
        case InAppPurchaseState.Purchased:
            IOSInAppPurchaseManager.Instance.VerifyLastPurchase(IOSInAppPurchaseManager.SANDBOX_VERIFICATION_SERVER);
            Debug.Log("Purchased");
            break;

        case InAppPurchaseState.Restored:
            //Our product been succsesly purchased or restored
            //So we need to provide content to our user depends on productIdentifier
            UnlockProducts(result.ProductIdentifier);
            Debug.Log("Purchases Restored");
            break;

        case InAppPurchaseState.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.
            IOSNativePopUpManager.showMessage("Waiting For Approval", ("Thank you! Your purchase is pending an approval from your family delegate."));
            Debug.Log("Purchases Deferred");
            break;

        case InAppPurchaseState.Failed:
            //Our purchase flow is failed.
            //We can unlock intrefase and repor user that the purchase is failed.
            //IOSNativePopUpManager.showMessage("Purchase Failed", ("Error Code:\n" + result.Error.Code));
            Debug.Log("Transaction failed with error, code: " + result.Error.Code);
            Debug.Log("Transaction failed with error, description: " + result.Error.Description);


            break;
        }

        if (result.State == InAppPurchaseState.Failed)
        {
            //IOSNativePopUpManager.showMessage("Transaction Failed", "Error code: " + result.Error.Code + "\n" + "Error description:" + result.Error.Description);
            switch (result.Error.Code)
            {
            case 0:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Error:\n" + result.Error.Description);
                break;

            case 1:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Invalid client");
                break;

            case 2:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Payment canceled");
                break;

            case 3:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Payment invalid");
                break;

            case 4:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Device is not authorized for purchaces");
                break;

            case 5:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Product unavailable");
                break;

            case 6:
                IOSNativePopUpManager.showMessage("Purchase Failed", "No purchases to restore");
                break;

            case 7:
                IOSNativePopUpManager.showMessage("Purchase Failed", "Store access failed");
                break;

            default:
                IOSNativePopUpManager.showMessage("Purchase Failed", ("Error Code:\n" + result.Error.Code));
                break;
            }
        }
        else
        {
            /*
             * if(RandomRestore == false)
             * {
             *      if(result.State.ToString() == "Restored")
             *      {
             *              IOSNativePopUpManager.showMessage("Restore Succeeded", "Restored Purchases");
             *      }
             *      else
             *      {
             *              string tempMessage = "Purchase Complete";
             *              if(result.ProductIdentifier.ToString() == No_Ads)
             *              {
             *                      tempMessage = "No Ads\n" + result.State.ToString();
             *              }
             *              if(result.ProductIdentifier.ToString() == Pro_Version)
             *              {
             *                      tempMessage = "Pro Version\n" + result.State.ToString();
             *              }
             *              // this is commmented out because it is rendundant since there thank you message is already displayed
             *              //IOSNativePopUpManager.showMessage("Purchase Complete", tempMessage);
             *      }
             * }
             */
        }
    }
Example #12
0
    private static void OnTransactionComplete(IOSStoreKitResult result)
    {
        Debug.Log("OnTransactionComplete: " + result.ProductIdentifier);
        Debug.Log("OnTransactionComplete: state: " + result.State);

        switch (result.State)
        {
        case InAppPurchaseState.Purchased:

            IOSNativePopUpManager.showMessage("Transaction Responce", " InAppPurchaseState is PURCHASED");

            UnlockProducts(result.ProductIdentifier);
            break;

        case InAppPurchaseState.Restored:

            IOSNativePopUpManager.showMessage("Transaction Responce", " InAppPurchaseState is RESTORED");

            //Our product been succsesly purchased or restored
            //So we need to provide content to our user depends on productIdentifier
            UnlockProducts(result.ProductIdentifier);
            break;

        case InAppPurchaseState.Deferred:

            IOSNativePopUpManager.showMessage("Transaction Responce", " InAppPurchaseState is DEFERRED");

            if (FailedPurchase != null)
            {
                FailedPurchase();
            }
            else
            {
                Debug.LogWarning("NOTHING IS SUBSCRIBED TO FailedPurchase DELEGATE");
            }

            //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 InAppPurchaseState.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: " + result.Error.Code);
            Debug.Log("Transaction failed with error, description: " + result.Error.Description);

            IOSNativePopUpManager.showMessage("Transaction Responce", " InAppPurchaseState is FAILED");

            if (FailedPurchase != null)
            {
                FailedPurchase();
            }
            else
            {
                Debug.LogWarning("NOTHING IS SUBSCRIBED TO FailedPurchase DELEGATE");
            }


            break;
        }

        if (result.State == InAppPurchaseState.Failed)
        {
            IOSNativePopUpManager.showMessage("Transaction Failed", "Error code: " + result.Error.Code + "\n" + "Error description:" + result.Error.Description);
        }
        else
        {
            IOSNativePopUpManager.showMessage("Store Kit Response", "product " + result.ProductIdentifier + " state: " + result.State.ToString());
        }
    }