コード例 #1
0
ファイル: HuaweiStore.cs プロジェクト: msalihkarakasli/HiGame
        void IStore.Purchase(ProductDefinition product, string developerPayload)
        {
            if (!productsByID.ContainsKey(product.storeSpecificId))
            {
                storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.ProductUnavailable, "UnknownProduct"));
                return;
            }

            var productInfo = productsByID[product.storeSpecificId];
            PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq
            {
                PriceType        = productInfo.PriceType,
                ProductId        = productInfo.ProductId,
                DeveloperPayload = developerPayload
            };

            var task = iapClient.CreatePurchaseIntent(purchaseIntentReq)
                       .AddOnSuccessListener((intentResult) =>
            {
                PurchaseInitentCreated(intentResult, product);
            })
                       .AddOnFailureListener((exception) =>
            {
                storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.Unknown, exception.Message));
            });
        }
コード例 #2
0
    public void BuyProduct(ProductInfo productInfo)
    {
        if (iapAvailable != true)
        {
            OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
            return;
        }

        PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq
        {
            PriceType = productInfo.PriceType,
            ProductId = productInfo.ProductId,
            // ToDo : developer payload???
            DeveloperPayload = "test"
        };

        ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq);

        task.AddOnSuccessListener((result) =>
        {
            if (result != null)
            {
                Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: Bought " + purchaseIntentReq.ProductId);
                Status status = result.Status;
                status.StartResolutionForResult((androidIntent) =>
                {
                    PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);

                    Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode);
                    Debug.Log("HMErrorMssg: " + purchaseResultInfo.ErrMsg);
                    Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData);
                    Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature);

                    switch (purchaseResultInfo.ReturnCode)
                    {
                    case OrderStatusCode.ORDER_STATE_SUCCESS:
                        OnBuyProductSuccess.Invoke(purchaseResultInfo);
                        break;

                    default:
                        OnBuyProductFailure.Invoke(purchaseResultInfo.ReturnCode);
                        break;
                    }
                }, (exception) =>
                {
                    Debug.Log("[HMSPlugin]:startIntent ERROR");
                });
            }
        }).AddOnFailureListener((exception) =>
        {
            Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message);
        });
    }
コード例 #3
0
        private void Buy(int index)
        {
            Log.Info(TAG, "buy");
            PurchaseIntentReq req         = new PurchaseIntentReq();
            ProductInfo       productInfo = nonconsumableProducts.ElementAt(index);

            req.ProductId = productInfo.ProductId;
            req.PriceType = productInfo.PriceType;

            Task task = mClient.CreatePurchaseIntent(req);

            task.AddOnSuccessListener(new BuyListenerImp(this)).AddOnFailureListener(new BuyListenerImp(this));
        }
コード例 #4
0
        public void Buy(string productId)
        {
            Log.Info(TAG, "buy");
            cacheOwnedPurchasesResult = null;
            PurchaseIntentReq req = new PurchaseIntentReq();

            req.ProductId = productId;
            req.PriceType = IapClientPriceType.InAppSubscription;


            Task task = mClient.CreatePurchaseIntent(req);

            task.AddOnSuccessListener(new BuyListenerImpl(this.view, this, productId)).AddOnFailureListener(new BuyListenerImpl(this.view, this, productId));
        }
コード例 #5
0
    public void BuyProduct(string productID)
    {
        PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq();

        ProductInfo productInfo = productInfoList.Find(product => product.ProductId == productID);

        purchaseIntentReq.PriceType = productInfo.PriceType;
        purchaseIntentReq.ProductId = productID;
        // ToDo : developer payload???
        purchaseIntentReq.DeveloperPayload = "test";

        ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq);

        InAppPurchaseData inAppPurchaseDataBean;

        task.AddOnSuccessListener((result) =>
        {
            if (result != null)
            {
                Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString());
                Debug.Log("[HMSPlugin]: Bought " + productID);
                Status status = result.Status;
                status.StartResolutionForResult((androidIntent) =>
                {
                    PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);

                    Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode);
                    Debug.Log("HMErrorMssg: " + purchaseResultInfo.ErrMsg);
                    Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData);
                    Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature);

                    switch (purchaseResultInfo.ReturnCode)
                    {
                    case OrderStatusCode.ORDER_STATE_CANCEL:
                        // User cancel payment.
                        Debug.Log("[HMS]: User cancel payment");
                        break;

                    case OrderStatusCode.ORDER_STATE_FAILED:
                        Debug.Log("[HMS]: order paymentf failed");
                        break;

                    case OrderStatusCode.ORDER_PRODUCT_OWNED:
                        Debug.Log("[HMS]: Product owned");
                        inAppPurchaseDataBean = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData);
                        ConsumePurchase(inAppPurchaseDataBean.PurchaseToken);

                        // to check if there exists undelivered products.
                        break;

                    case OrderStatusCode.ORDER_STATE_SUCCESS:
                        // pay success.
                        Debug.Log("[HMSPlugin]: PURCHASE SUCCESS");

                        String inAppPurchaseData          = purchaseResultInfo.InAppPurchaseData;
                        String inAppPurchaseDataSignature = purchaseResultInfo.InAppDataSignature;
                        Debug.Log("HMS" + inAppPurchaseData);
                        Debug.Log("HMS:" + inAppPurchaseDataSignature);

                        //ToDO: use the public key of your app to verify the signature.
                        // If ok, you can deliver your products.
                        // If the user purchased a consumable product, call the consumeOwnedPurchase API to consume it after successfully delivering the product.

                        // Consume purchase
                        inAppPurchaseDataBean = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData);
                        ConsumePurchase(inAppPurchaseDataBean.PurchaseToken);
                        break;

                    default:
                        break;
                    }
                }, (exception) =>
                {
                    Debug.Log("[HMSPlugin]:startIntent ERROR");
                }
                                                );
            }
        }).AddOnFailureListener((exception) =>
        {
            Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message);
        });
    }
コード例 #6
0
        public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true, string payload = "")
        {
            if (iapAvailable != true)
            {
                OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE);
                return;
            }

            PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq
            {
                PriceType        = productInfo.PriceType,
                ProductId        = productInfo.ProductId,
                DeveloperPayload = payload
            };

            ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq);

            task.AddOnSuccessListener((result) =>
            {
                if (result != null)
                {
                    Debug.Log("[HMSIAPManager]:" + result.ErrMsg + result.ReturnCode.ToString());
                    Debug.Log("[HMSIAPManager]: Buying " + purchaseIntentReq.ProductId);
                    Status status = result.Status;
                    status.StartResolutionForResult((androidIntent) =>
                    {
                        PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);

                        if (purchaseResultInfo.ReturnCode == OrderStatusCode.ORDER_STATE_SUCCESS)
                        {
                            Debug.Log("[HMSIAPManager] HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData);
                            Debug.Log("[HMSIAPManager] HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature);
                            OnBuyProductSuccess.Invoke(purchaseResultInfo);
                            if (consumeAfter)
                            {
                                ConsumePurchase(purchaseResultInfo);
                            }
                        }
                        else
                        {
                            switch (purchaseResultInfo.ReturnCode)
                            {
                            case OrderStatusCode.ORDER_STATE_CANCEL:
                                Debug.LogError("[HMSIAPManager] User cancel payment");
                                break;

                            case OrderStatusCode.ORDER_STATE_FAILED:
                                Debug.LogError("[HMSIAPManager] order payment failed");
                                break;

                            case OrderStatusCode.ORDER_PRODUCT_OWNED:
                                Debug.LogError("[HMSIAPManager] Product owned");
                                break;

                            default:
                                Debug.LogError("[HMSIAPManager] BuyProduct failed. ReturnCode: " + purchaseResultInfo.ReturnCode + ", ErrorMsg: " + purchaseResultInfo.ErrMsg);
                                break;
                            }
                            OnBuyProductFailure?.Invoke(purchaseResultInfo.ReturnCode);
                        }
                    }, (exception) =>
                    {
                        Debug.LogError("[HMSIAPManager] startIntent ERROR");
                    });
                }
            }).AddOnFailureListener((exception) =>
            {
                Debug.LogError("[HMSIAPManager]: BuyProduct failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage);
            });
        }