protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)

        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == Constants.REQ_CODE_BUY)
            {
                if (data == null)
                {
                    Log.Error(TAG, "data is null");
                    return;
                }

                PurchaseResultInfo purchaseIntentResult = Iap.GetIapClient(this).ParsePurchaseResultInfoFromIntent(data);
                switch (purchaseIntentResult.ReturnCode)
                {
                case OrderStatusCode.OrderStateCancel:
                    Toast.MakeText(this, "Order has been canceled!", ToastLength.Long).Show();
                    break;

                case OrderStatusCode.OrderStateFailed:
                    Toast.MakeText(this, GetString(Resource.String.pay_fail), ToastLength.Long).Show();
                    break;

                case OrderStatusCode.OrderStateSuccess:
                    Toast.MakeText(this, GetString(Resource.String.pay_success), ToastLength.Long).Show();
                    presenter.RefreshSubscription();
                    break;

                default:
                    break;
                }
                return;
            }
        }
        void Update()
        {
            if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.WindowsEditor)
            {
                return;
            }
            if (_deferred == null)
            {
                return;
            }
            var    jc        = new AndroidJavaClass("com.redcap.thugs.PurchaseActivity");
            string lastEvent = jc.CallStatic <string>("GetLastEvent");

            if (!string.IsNullOrEmpty(lastEvent))
            {
                PurchaseResultInfo purchaseResultInfo = JsonConvert.DeserializeObject <PurchaseResultInfo>(lastEvent);

                if (purchaseResultInfo.PurchaseResult == BazaarPurchaseResult.Succeded)
                {
                    Deferred <string, MarketPurchaseError> deferred = _deferred;
                    _deferred = null;
                    deferred.Resolve(purchaseResultInfo.Token);
                }
                else
                {
                    Deferred <string, MarketPurchaseError> deferred = _deferred;
                    _deferred = null;
                    deferred.Reject(purchaseResultInfo.PurchaseResult == BazaarPurchaseResult.Canceled
                        ? MarketPurchaseError.Cancel
                        : MarketPurchaseError.Failed);
                }
            }
        }
예제 #3
0
        protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)

        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (requestCode == Constants.REQ_CODE_BUY)
            {
                if (data == null)
                {
                    Log.Error(TAG, "data is null");
                    return;
                }

                PurchaseResultInfo purchaseIntentResult = mClient.ParsePurchaseResultInfoFromIntent(data);
                switch (purchaseIntentResult.ReturnCode)
                {
                case OrderStatusCode.OrderStateCancel:
                    Toast.MakeText(this, "Order has been canceled!", ToastLength.Long).Show();
                    break;

                case OrderStatusCode.OrderProductOwned:
                    QueryPurchases(null);
                    break;

                case OrderStatusCode.OrderStateSuccess:
                    isHiddenLevelPurchased = true;
                    DeliverProduct();
                    break;

                default:
                    break;
                }
                return;
            }
        }
예제 #4
0
 private void OnBuyProductSuccess(PurchaseResultInfo result)
 {
     if (result.InAppPurchaseData.ProductId == HMSIAPConstants.AdsRemove)
     {
         // Write your remove ads logic here.
         Debug.Log(" OnBuyProductSuccess ");
         MazeGameManager.Instance.isOwned = true;
         HMSAdsKitManager.Instance.HideBannerAd();
     }
 }
    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);
        });
    }
예제 #6
0
 private void OnBuyProductSuccess(PurchaseResultInfo obj)
 {
     if (obj.InAppPurchaseData.ProductId == "removeads")
     {
         // Hide banner Ad for example
         //HMSAdsKitManager.Instance.HideBannerAd();
     }
     else if (obj.InAppPurchaseData.ProductId == "coins100")
     {
         // Give your player coins here.
     }
     else if (obj.InAppPurchaseData.ProductId == "premium")
     {
         // Grant your player premium feature.
     }
 }
예제 #7
0
        void PurchaseInitentCreated(PurchaseIntentResult intentResult, ProductDefinition product)
        {
            if (intentResult == null)
            {
                storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.Unknown, "IntentIsNull"));
                return;
            }

            var status = intentResult.Status;

            status.StartResolutionForResult((androidIntent) =>
            {
                PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent);


                switch (purchaseResultInfo.ReturnCode)
                {
                case OrderStatusCode.ORDER_STATE_SUCCESS:
                    var data = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData);
                    this.purchasedData[product.storeSpecificId] = data;

                    this.productsByID.TryGetValue(product.storeSpecificId, out var productInfo);
                    var receipt = EncodeReceipt(purchaseResultInfo.InAppPurchaseData, purchaseResultInfo.InAppDataSignature, ProductToJson(productInfo));
                    storeEvents.OnPurchaseSucceeded(product.storeSpecificId, receipt, data.OrderID);
                    break;

                case OrderStatusCode.ORDER_PRODUCT_OWNED:
                    storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.DuplicateTransaction, purchaseResultInfo.ErrMsg));
                    break;

                case OrderStatusCode.ORDER_STATE_CANCEL:
                    storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.UserCancelled, purchaseResultInfo.ErrMsg));
                    break;

                default:
                    storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.Unknown, purchaseResultInfo.ErrMsg));
                    break;
                }
            }, (exception) =>
            {
                storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.Unknown, exception.Message));
            });
        }
예제 #8
0
 public void ConsumePurchase(PurchaseResultInfo purchaseResultInfo)
 {
     ConsumePurchaseWithPurchaseData(purchaseResultInfo.InAppPurchaseData);
 }
예제 #9
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);
        });
    }
예제 #10
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);
            });
        }
예제 #11
0
파일: IapShop.cs 프로젝트: xAdamQ/Basra
 private void OnPurchaseSuccess(PurchaseResultInfo obj)
 {
     Controller.I.Send("MakePurchase", obj.InAppPurchaseDataRawJSON, obj.InAppDataSignature);
 }