Beispiel #1
0
        // 确认购买产品成功;
        private void DoConfirmPendingPurchaseByID(long chargeId)
        {
            Product product = m_StoreController.products.WithID(chargeId.ToString());

            if (product != null && product.availableToPurchase)
            {
                //product.metadata.localizedDescription,
                // product.metadata.isoCurrencyCode
                //product.metadata.localizedPrice.ToString(),
                //product.metadata.localizedPriceString,
                Debug.Log("UNITY IAP confirm ok !!!!!!!!!!!!!!!!");

                if (!m_Usr_Transction_Done.IsNull)
                {
                    m_Usr_Transction_Done.SafeInvoke(chargeId, product.metadata.isoCurrencyCode, product.metadata.localizedPrice.ToString());
                }

                if (m_PurchaseInProgress)
                {
                    m_StoreController.ConfirmPendingPurchase(product);
                    m_PurchaseInProgress = false;
                }
                else
                {
                    m_StoreController.ConfirmPendingPurchase(product);
                }
            }
        }
Beispiel #2
0
        public void ConfirmAll()
        {
            log.Debug(nameof(ConfirmAll));
            var products = storeController.products.all;

            foreach (var product in products)
            {
                storeController.ConfirmPendingPurchase(product);
                log.Debug("success confirm " + product.definition.id);
            }
        }
Beispiel #3
0
        private void SendPostReceipt(PurchaseEventArgs args)
        {
            if (isLog)
            {
                Debug.Log("Percent [IAP] Start receipt validation: " + args.purchasedProduct.definition.id);
            }

            dictPendingProducts.Remove(args.purchasedProduct.transactionID);
            storeController.ConfirmPendingPurchase(args.purchasedProduct);

            ResultPurchaseSuccessed(args);
        }
Beispiel #4
0
 public int ConfirmPurchase(string productId)
 {
     //Debug.Log("█ [ConfirmPurchase]" + productId);
     if (productId != null)
     {
         var product = _storeController.products.WithID(productId);
         if (product != null)
         {
             if (_storeController.products.WithID(productId).hasReceipt)
             {
                 _storeController.ConfirmPendingPurchase(_storeController.products.WithID(productId));
                 SoundsSystem.play(Sound.S_RUBINS_BUY);
                 return(0);
             }
             printLog("ConfirmPurchase: Hasn't Receipt"); // ошибка покупки, нету ордера / заказа. Неправильно выбран продукт
             Errors.showError(Errors.TypeError.EP_ON_FAILED_CONFIRM_PURCHASE);
             return(-1);
         }
         printLog("ConfirmPurchase: Hasn't product: " + productId); // ошибка покупки, нет товара
         Errors.showError(Errors.TypeError.EP_ON_FAILED_CONFIRM_PURCHASE);
         return(-1);
     }
     printLog("ConfirmPurchase: product is empty"); // ошибка покупки продукт пустой.
     Errors.showError(Errors.TypeError.EP_ON_FAILED_CONFIRM_PURCHASE);
     return(-1);
 }
Beispiel #5
0
    private IEnumerator ConfirmPendingPurchaseAfterDelay(Product p)
    {
        m_PendingProducts.Add(p.definition.id);
        Debug.Log("Delaying confirmation of " + p.definition.id + " for 5 seconds.");

        var end = Time.time + 5f;

        while (Time.time < end)
        {
            yield return(null);

            var remaining = Mathf.CeilToInt(end - Time.time);
            UpdateProductPendingUI(p, remaining);
        }

        if (m_IsGooglePlayStoreSelected)
        {
            Debug.Log("Is " + p.definition.id + " currently owned, according to the Google Play store? "
                      + m_GooglePlayStoreExtensions.IsOwned(p));
        }
        Debug.Log("Confirming purchase of " + p.definition.id);
        m_Controller.ConfirmPendingPurchase(p);
        m_PendingProducts.Remove(p.definition.id);
        UpdateProductUI(p);
    }
Beispiel #6
0
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_Controller      = controller;
        m_AppleExtensions = extensions.GetExtension <IAppleExtensions> ();

        m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);

        foreach (var item in controller.products.all)
        {
            if (item.hasReceipt)              // リストア可能なレシートあるよ!
            {
                MyLog.I("hasReceipt items:" + item.definition.id);
                m_Controller.ConfirmPendingPurchase(item);
                // item.definition.id - アイテムID
                // item.receipt - レシート関連(JSON)
                // サーバー検証しアイテム復元
            }
            if (item.availableToPurchase)
            {
                MyLog.D(string.Join(" - ",
                                    new[]
                {
                    item.metadata.localizedTitle,
                    item.metadata.localizedDescription,
                    item.metadata.isoCurrencyCode,
                    item.metadata.localizedPrice.ToString(),
                    item.metadata.localizedPriceString,
                    item.transactionID,
                    item.receipt
                }));
            }
        }
    }
Beispiel #7
0
        /// <summary>
        /// 购买成功,确认已发货
        /// </summary>
        /// <param name="productID"></param>
        public void OnConfirmProduct(string productID)
        {
            Product produdt = mStoreController.products.WithID(productID);

            EB.Debug.Log("Own Product , consume it ---------------------------------------");
            mStoreController.ConfirmPendingPurchase(produdt);
        }
Beispiel #8
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        Debug.Log("Processing the purchase");
        ScoreManager.instance.Loading(false);
        m_StoreController.ConfirmPendingPurchase(args.purchasedProduct);
#if UNITY_EDITOR
        GoogleAds.instance.SetAdBool(false);
        ScoreManager.instance.ProvideInfo("Purchase Successful!");
#else
        if (string.Equals(args.purchasedProduct.definition.id, removeAds, System.StringComparison.Ordinal))
        {
            if (GoogleAds.instance.ShouldShowAds())
            {
                GoogleAds.instance.SetAdBool(false);
                ScoreManager.instance.ProvideInfo("Purchase Successful!");
            }
            else
            {
                ScoreManager.instance.ProvideInfo("Purchase Restored!");
            }
        }
        else
        {
            ScoreManager.instance.ProvideInfo("Purchase Unsuccessful, Try Again.");
        }
#endif
        return(PurchaseProcessingResult.Complete);
    }
Beispiel #9
0
    public void OnPurchaseFailed(Product item, PurchaseFailureReason r)
    {
        MyLog.D("Purchase failed: " + item.definition.id);
        Debug.Log(r);

        m_Controller.ConfirmPendingPurchase(item);
        m_PurchaseInProgress = false;
    }
Beispiel #10
0
    public static void ConfirmPendingPurchase(Product product, bool purchaseVerifiedSuccess)
    {
        if (purchaseVerifiedSuccess)
        {
            UnlockInGameContent(product.definition.id);
        }

        m_StoreController.ConfirmPendingPurchase(product);
    }
Beispiel #11
0
        PurchaseProcessingResult IStoreListener.ProcessPurchase(PurchaseEventArgs e)
        {
            var product = e.purchasedProduct;
            var rep     = _specialOffers.GetReplacementBySOSku(e.purchasedProduct.definition.id);

            ReportPurchase(e,
                           res => {
                if (Settings.instance.autoConfirmPurchase)
                {
                    _store.ConfirmPendingPurchase(e.purchasedProduct);
                }
                JsonObject so;
                res.TryGet("specialOffer", out so);

                string soPayload = null;
                if (so != null)
                {
                    so.TryGet("soPayload", out soPayload);
                }

                soPayload = string.IsNullOrEmpty(soPayload) ? null : soPayload;

                string originReceipt;
                res.TryGet("originReceipt", out originReceipt);

                if (PurchaseCompleted != null)
                {
                    PurchaseCompleted(new PurchaseCompletedEventArgs(product, PurchaseCheckingState.Legal, rep,
                                                                     soPayload, originReceipt));
                }
            },
                           err => {
                if (Settings.instance.autoConfirmPurchase && Settings.instance.autoConfirmPurchaseWhenError)
                {
                    _store.ConfirmPendingPurchase(e.purchasedProduct);
                }
                if (PurchaseCompleted != null)
                {
                    PurchaseCompleted(
                        new PurchaseCompletedEventArgs(product, PurchaseCheckingState.Error, rep));
                }
            });
            return(PurchaseProcessingResult.Pending);
        }
Beispiel #12
0
/*	private void IosPurchaseCreate(String productId)
 *      {
 *              BasicConn.instance.ReqPost(string.Format("{0}/charge/ios/create", myServer),
 *                      productId,
 *                      OnSucceed,
 *                      OnFail);
 *      }
 *
 *      private void IosPurchaseVerify(String PayloadInfo)
 *      {
 *              BasicConn.instance.ReqPost(string.Format("{0}/charge/ios/verify_test", myServer),
 *                      PayloadInfo,
 *                      OnVerifySucceed,
 *                      OnFail);
 *      }
 */
    public void OnVerifySucceed(string[] returnVal)
    {
        if (m_product != null)
        {
            controller.ConfirmPendingPurchase(m_product);

            getNewIterm();
            Debuger.Log("purchase complete.");
        }
    }
Beispiel #13
0
    public void OnPurchaseSucceeded(Product product)
    {
        _controller.ConfirmPendingPurchase(product); // consume
        _isInProgress = false;

        if (handleSucceeded != null)
        {
            handleSucceeded(product.definition.id);
        }
    }
Beispiel #14
0
    /// Called by ChilliConnect when a purchase has been redeemed on the server.
    /// We close of the transaction, award the items and notify the listener that the purchase has finished.
    ///
    /// NOTE: We have to handle duplicate purchases here
    ///
    /// @param product
    ///     Purchased product
    /// @param status
    ///     Status of the product
    /// @param rewards
    ///     Items to award for the given product as specified on the ChilliConnect dashboard
    ///
    public void OnPurchaseRedeemed(Product product, string status, PurchaseExchange rewards)
    {
        Debug.Log(string.Format("Product redeemed: {0}. Status: {1}", product.definition.storeSpecificId, status));

        // NOTE: If the status is "InvalidRedeemed" then the user has already been awarded the IAP and this is
        // a duplicate purchase. In this case you might want to explain that to the user rather than just closing
        // the transaction silently.
        // If it is "InvalidVerificationFailed" then probably a fraudulent purchase
        if (status != "InvalidRedeemed" && status != "InvalidVerificationFailed")
        {
            foreach (var reward in rewards.Items)
            {
                InventorySystem.Get().AddItem(reward.Key, reward.Amount);
            }
        }

        m_unityStoreController.ConfirmPendingPurchase(product);
        OnPurchaseCompleteEvent();
    }
    /// <summary>
    /// Confirm a pending purchase.
    /// </summary>
    /// <param name="productId"></param>
    public void ConfirmPendingPurchase(string productId)
    {
#if DEBUG_MY_IAP || UNITY_EDITOR
        Debug.Log(string.Format("[" + typeof(MyIAPManager).Name + "] ConfirmPendingPurchase(): productId={0}", productId));
#endif

        if (mStoreController != null)
        {
            Product product = mStoreController.products.WithID(productId);
            mStoreController.ConfirmPendingPurchase(product);
        }
    }
Beispiel #16
0
 public void CompletePurchase()
 {
     if (test_product == null)
     {
         MyDebug("Cannot complete purchase, product not initialized.");
     }
     else
     {
         m_StoreController.ConfirmPendingPurchase(test_product);
         MyDebug("Completed purchase with " + test_product.transactionID.ToString());
     }
 }
Beispiel #17
0
    private IEnumerator ConfirmPendingPurchaseAfterDelay(Product p)
    {
        m_PendingProducts.Add(p.definition.id);
        Debug.Log("Delaying confirmation of " + p.definition.id + " for 5 seconds.");
        UpdateHistoryUI();

        yield return(new WaitForSeconds(5f));

        Debug.Log("Confirming purchase of " + p.definition.id);
        m_Controller.ConfirmPendingPurchase(p);
        m_PendingProducts.Remove(p.definition.id);
        UpdateHistoryUI();
    }
Beispiel #18
0
    private void validateReceipt(Product product)
    {
        var isSuccess = true;

        if (!isSuccess)
        {
            Debug.Log("[ERR] validateReceipt");
            return;
        }

        Debug.Log("[SUCCESS]: validateReceipt " + product.definition.id);
        controller.ConfirmPendingPurchase(product);
    }
Beispiel #19
0
        /// <summary>
        /// 确认未消费的商品
        /// </summary>
        public void ConfirmPending()
        {
            if (_confirmPending != null)
            {
                // 确认消费
                m_StoreController.ConfirmPendingPurchase(_confirmPending);

                Debugback(string.Format("确认购买商品完成"));
            }
            else
            {
                Debugback(string.Format("商品为空"));
            }
        }
Beispiel #20
0
    public void ReleaseIAP()
    {
        foreach (string productId in android_ProductIds)
        {
            Product p = controller.products.WithID(productId);

            //isPurchaseUnderProcess = true;

            if (p != null)
            {
                controller.ConfirmPendingPurchase(p);
            }
        }
    }
Beispiel #21
0
        /// <summary>
        /// Pending状態のアイテムを更新.
        /// </summary>
        private void UpdatePendingProduct(Product product, PurchaseProcessingResult result)
        {
            // レシートを持っていない.
            if (!product.hasReceipt)
            {
                return;
            }

            if (string.IsNullOrEmpty(product.transactionID))
            {
                return;
            }

            var pendingProducts = new List <Product>(PendingProducts);

            // Pendingの場合は最新のものに更新.
            if (result == PurchaseProcessingResult.Pending)
            {
                var pendingProduct = pendingProducts.FirstOrDefault(x => x.transactionID == product.transactionID);

                if (pendingProduct != null)
                {
                    pendingProducts.Remove(pendingProduct);
                }

                pendingProducts.Add(product);
            }
            else if (result == PurchaseProcessingResult.Complete)
            {
                // 完了した場合は削除.
                var pendingProduct = pendingProducts.FirstOrDefault(x => x.transactionID == product.transactionID);

                if (pendingProduct != null)
                {
                    pendingProducts.Remove(pendingProduct);
                }

                storeController.ConfirmPendingPurchase(product);

                var builder = new StringBuilder();

                builder.AppendLine("------- ConfirmPendingProducts -------");
                builder.AppendLine(GetProductString(product)).AppendLine();

                UnityConsole.Event(ConsoleEventName, ConsoleEventColor, builder.ToString());
            }

            PendingProducts = pendingProducts.ToArray();
        }
Beispiel #22
0
    /*
     * /// <summary>
     * /// Extract Payload part from your receipt for Server Side Receipt Validation.
     * /// </summary>
     * public static string ExtractPayload(string receipt)
     * {
     *  string[] separators = { "\"Payload\":\"" };
     *  string[] splittedStrings = receipt.Split(separators, StringSplitOptions.None);
     *
     *  receipt = splittedStrings[1].Replace("\"}", "");
     *  return receipt;
     * }
     */

    /// <summary>
    /// Releases all unfinished unity IAP transactions. Works on unfinished transactions (Pending) only
    /// </summary>
    public void ReleaseAllUnfinishedUnityIAPTransactions()
    {
        foreach (string productId in managedProducts)
        {
            Product p = storeController.products.WithID(productId);
            if (p != null)
            {
                storeController.ConfirmPendingPurchase(p);
            }
        }

        isPurchaseUnderProcess         = false;
        shouldShowPurchaseRestorePopup = false;
        restoredProductName            = string.Empty;
    }
Beispiel #23
0
    private IEnumerator ConfirmPendingPurchaseAfterDelay(Product p)
    {
        m_PendingProducts.Add(p.definition.id);
        Debug.Log("Delaying confirmation of " + p.definition.id + " for 5 seconds.");

        var end = Time.time + 5f;

        while (Time.time < end)
        {
            yield return(null);

            var remaining = Mathf.CeilToInt(end - Time.time);
            UpdateProductPendingUI(p, remaining);
        }

        Debug.Log("Confirming purchase of " + p.definition.id);
        m_Controller.ConfirmPendingPurchase(p);
        m_PendingProducts.Remove(p.definition.id);
        UpdateProductUI(p);
    }
Beispiel #24
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        Debug.Log("IAP支付成功:" + e.purchasedProduct.metadata.localizedTitle);
        Debug.Log(string.Format("交易id:{0} | 收据:{1}", e.purchasedProduct.transactionID, e.purchasedProduct.receipt));
#if UNITY_EDITOR
        string appStore = "AppleAppStore";
        string payload  = "MIIT0AYJKoZIhvcNAQcCoIITwTCCE70CAQExCzAJBgUrDgMCGgUAMIIDcQYJKoZIhvcNAQcBoIIDYgSCA14xggNaMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATAwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBcTALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDAa4WMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI0OTAYAgEEAgECBBDsY8xsQTlEb5FNr4dn0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Lmj";
#else
        JsonData jd       = JsonMapper.ToObject(e.purchasedProduct.receipt);
        string   appStore = jd["Store"].ToString();
        string   payload  = jd["Payload"].ToString();
#endif
        string goodsID = GoodsData.GetGoodsID(e.purchasedProduct.definition.id);
        Debug.Log("goodsID:" + goodsID);
        string transactionID = e.purchasedProduct.transactionID;

        GameMainManager.instance.netManager.GetOrder(goodsID, 1, (ret, res) =>
        {
            string orderID = res.request_id;
            GameMainManager.instance.netManager.Purchase(appStore, transactionID, payload, orderID, (r, data) => {
                if (data.isOK)
                {
                    Debug.Log("IAP发放物品成功");
                    controller.ConfirmPendingPurchase(e.purchasedProduct);

                    //Alert.Show(string.Format("成功购买【{0}】", e.purchasedProduct.metadata.localizedTitle));
                }
                else
                {
                    Alert.Show("发放物品失败:" + data.errmsg);
                }
                Waiting.Disable();
            });
        });



        return(PurchaseProcessingResult.Pending);
    }
Beispiel #25
0
    public void ConfirmPendingPurchase(string productId)
    {
        Product product = m_StoreController.products.WithID(productId);

        if (product != null && IsInitialized())
        {
            m_StoreController.ConfirmPendingPurchase(product);
        }
        else
        {
            if (!IsInitialized())
            {
                // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
                Debug.LogError("RestorePurchases FAIL. Not initialized.");
            }
            if (onPurchaseFailed != null)
            {
                onPurchaseFailed(product, PurchaseFailureReason.Unknown);
            }
            Debug.LogError("ConfirmPendingPurchase : no productId :" + productId);
        }
    }
        IEnumerator BackEndValidation(Product product)
        {
            m_ProcessingPurchasesCount++;
            UpdateUI();

            //Mock backend validation. Here you would call your own backend and wait for its response.
            //If the app is closed during this time, ProcessPurchase will be called again for the same purchase once the app is opened again.
            yield return(MockServerSideValidation(product));

            m_ProcessingPurchasesCount--;
            UpdateUI();

            Debug.Log($"Confirming purchase of {product.definition.id}");

            //Once we have done the validation in our backend, we confirm the purchase.
            m_StoreController.ConfirmPendingPurchase(product);

            //We can now add the purchased product to the players inventory
            if (product.definition.id == goldProductId)
            {
                AddGold();
            }
        }
        internal void OnValidPurchaseResponseEvent(string price, string currency, string itemId, bool isValid)
        {
            Debug.Log("Billing::OnValidPurchaseResponseEvent: Receipt validation result : " + isValid);

            PurchaseIAPResult result;

            if (isValid)
            {
                result = new PurchaseIAPResult(_iapInValidation, PurchaseIAPResultCode.Success, BillerErrors.NO_ERROR);
                SavePurchaseLocally(_iapInValidation.id);
                if (IsNoAdsItem(_iapInValidation.id))
                {
                    Debug.Log("Billing::OnValidPurchaseResponseEvent IsNoAdsItem=true calling PurchaseAd");
                    PSDKMgr.Instance.PurchaseAd();
                }
                else
                {
                    Debug.Log("Billing::OnValidPurchaseResponseEvent IsNoAdsItem=false");
                }
            }
            else
            {
                Debug.Log("Billing::OnValidPurchaseResponseEvent item is not valid");
                result = new PurchaseIAPResult(_iapInValidation, PurchaseIAPResultCode.Failed, BillerErrors.REMOTE_VALIDATION_FAILED);
            }


            PsdkEventSystem.Instance.NotifyOnBillingPurchased(result);

            _isPurchaseInProgress = false;

            _storeController.ConfirmPendingPurchase(_iapInValidationArgs.purchasedProduct);

            ResetPurchasableItem(_iapInValidation);
            _iapInValidationArgs = null;
        }
Beispiel #28
0
        public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
        {
            int cardId;

            if (!_storeSkUsToShopcardId.TryGetValue(args.purchasedProduct.definition.storeSpecificId, out cardId))
            {
                Debug.LogError("Card with id: " + cardId + " is not found in shop cards. " +
                               "Check shop card data arrived from server.");

                return(PurchaseProcessingResult.Pending);
            }

            var toObject = new SFSObject();

            toObject.PutUtfString("storeType",
                                  Application.platform == RuntimePlatform.Android ? "GOOGLE_PLAY"
                : Application.platform == RuntimePlatform.IPhonePlayer ? "APP_STORE": String.Empty);
            toObject.PutInt("shopCardId", cardId);
            toObject.PutUtfString("receiptId", args.purchasedProduct.receipt);

            var request = new ExtensionRequest("shopTestBuy", toObject);

            _sfsx2Manager.GetSfs().Send(request);
            _sfsx2Manager.GetSfs().AddEventListener("purchaseTestBuy", eventArgs =>
            {
                if (eventArgs.Params.Contains("result"))
                {
                    if ((int)eventArgs.Params["result"] == 0)
                    {
                        _storeController.ConfirmPendingPurchase(args.purchasedProduct);
                    }
                }
            });

            return(PurchaseProcessingResult.Pending);
        }
Beispiel #29
0
    /// <summary>
    /// This will be called when a purchase completes.
    /// </summary>
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        Debug.Log("Purchase OK: " + e.purchasedProduct.definition.id);
        Debug.Log("Receipt: " + e.purchasedProduct.receipt);

        m_LastTransationID   = e.purchasedProduct.transactionID;
        m_LastReceipt        = e.purchasedProduct.receipt;
        m_PurchaseInProgress = false;

        // Now that my purchase history has changed, update its UI
        UpdateHistoryUI();

                #if RECEIPT_VALIDATION
        // Local validation is available for GooglePlay and Apple stores
        if (m_IsGooglePlayStoreSelected ||
            Application.platform == RuntimePlatform.IPhonePlayer ||
            Application.platform == RuntimePlatform.OSXPlayer ||
            Application.platform == RuntimePlatform.tvOS)
        {
            try {
                var result = validator.Validate(e.purchasedProduct.receipt);
                Debug.Log("Receipt is valid. Contents:");
                foreach (IPurchaseReceipt productReceipt in result)
                {
                    Debug.Log(productReceipt.productID);
                    Debug.Log(productReceipt.purchaseDate);
                    Debug.Log(productReceipt.transactionID);

                    GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
                    if (null != google)
                    {
                        Debug.Log(google.purchaseState);
                        Debug.Log(google.purchaseToken);
                    }

                    AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
                    if (null != apple)
                    {
                        Debug.Log(apple.originalTransactionIdentifier);
                        Debug.Log(apple.subscriptionExpirationDate);
                        Debug.Log(apple.cancellationDate);
                        Debug.Log(apple.quantity);
                    }
                }
            } catch (IAPSecurityException) {
                Debug.Log("Invalid receipt, not unlocking content");
                return(PurchaseProcessingResult.Complete);
            }
        }
                #endif

        // CloudMoolah purchase completion / finishing currently requires using the API
        // extension IMoolahExtension.RequestPayout to finish a transaction.
        if (m_IsCloudMoolahStoreSelected)
        {
            // Finish transaction with CloudMoolah server
            m_MoolahExtensions.RequestPayOut(e.purchasedProduct.transactionID,
                                             (string transactionID, RequestPayOutState state, string message) => {
                if (state == RequestPayOutState.RequestPayOutSucceed)
                {
                    // Finally, finish transaction with Unity IAP's local
                    // transaction log, recording the transaction id there
                    m_Controller.ConfirmPendingPurchase(e.purchasedProduct);

                    // Unlock content here.
                }
                else
                {
                    Debug.Log("RequestPayOut: failed. transactionID: " + transactionID +
                              ", state: " + state + ", message: " + message);
                    // Finishing failed. Retry later.
                }
            });
        }

        // You should unlock the content here.

        // Indicate if we have handled this purchase.
        //   PurchaseProcessingResult.Complete: ProcessPurchase will not be called
        //     with this product again, until next purchase.
        //   PurchaseProcessingResult.Pending: ProcessPurchase will be called
        //     again with this product at next app launch. Later, call
        //     m_Controller.ConfirmPendingPurchase(Product) to complete handling
        //     this purchase. Use to transactionally save purchases to a cloud
        //     game service.
        return(PurchaseProcessingResult.Complete);
    }
Beispiel #30
0
        public IEnumerator VerifyPurchase(PurchaseEventArgs e = null) {

            Debug.Log("Verify purchase");

            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("Content-Type", "application/json;charset=UTF-8");
            headers.Add("x-api-key", QuartersInit.Instance.SERVER_API_TOKEN);


            string url = Quarters.API_URL + "/apps/" + QuartersInit.Instance.APP_ID + "/verifyReceipt/unity";


            Dictionary<string, string> receiptData = JsonConvert.DeserializeObject<Dictionary<string, string>>(e.purchasedProduct.receipt);


            Hashtable receipt = new Hashtable();
            receipt.Add("Store", receiptData["Store"]);
            receipt.Add("TransactionID", receiptData["TransactionID"]);
            receipt.Add("Payload", receiptData["Payload"]);


  
            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("receipt", receipt);
            data.Add("user", Quarters.Instance.CurrentUser.id);



            string fileName = Application.persistentDataPath + "/" + Random.Range(0, 100000).ToString() + ".json";
            Debug.Log(fileName);

            if (File.Exists(fileName)) {
                Debug.Log(fileName + " already exists.");

            }
            var sr = File.CreateText(fileName);


            sr.WriteLine (JsonConvert.SerializeObject(data));
            sr.Close();



            string dataJson = JsonConvert.SerializeObject(data);
            Debug.Log(dataJson);
            byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(dataJson);


            WWW www = new WWW(url, dataBytes, headers);
            Debug.Log(www.url);

            while (!www.isDone) yield return new WaitForEndOfFrame();

            if (!string.IsNullOrEmpty(www.error)) {
                Debug.LogError(www.error);

                if (PurchaseFailedDelegate != null) PurchaseFailedDelegate(www.error);
            }
            else {
                Debug.Log(www.text);
                Hashtable resultData = JsonConvert.DeserializeObject<Hashtable>(www.text);

                //consume product

                if (resultData.ContainsKey("txId")) {
                    string txId = (string)resultData["txId"];
                    Debug.Log("Consume product");
                    controller.ConfirmPendingPurchase(e.purchasedProduct);

                    if (PurchaseSucessfullDelegate != null) PurchaseSucessfullDelegate(e.purchasedProduct, txId);
                }
                else {
                    if (PurchaseFailedDelegate != null) PurchaseFailedDelegate(www.text);
                }

            }

        }