コード例 #1
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);
        }
コード例 #2
0
        /// <summary>
        /// Callback from the billing system when a (real money) purchase completes successfully.
        /// </summary>
        public void OnPurchaseSucceeded(ConfirmPurchaseResult result)
        {
            orderId = string.Empty;
            ItemInstance item = result.Items[0];

            callback.OnPurchaseSucceeded(item.ItemId, item.PurchaseDate.ToString(), item.ItemInstanceId);
        }
コード例 #3
0
 public void OnPurchaseSucceeded(string productId, string receipt, string tranId)
 {
     util.RunOnMainThread(() => {
         m_CanReceivePurchases = true;
         callback.OnPurchaseSucceeded(productId, receipt, tranId);
     });
 }
コード例 #4
0
 void CallPurchaseSucceededUpdateReceipt(ProductDefinition product, GooglePurchase googlePurchase, string purchaseToken)
 {
     m_StoreCallback?.OnPurchaseSucceeded(
         product.storeSpecificId,
         googlePurchase.receipt,
         purchaseToken
         );
 }
コード例 #5
0
 public void OnPurchaseSucceeded(string productId, string receipt, string tranId)
 {
     util.RunOnMainThread(() => {
         logger.Log("PURCHASE SUCCEEDED!:{0}", count++);
         m_CanReceivePurchases = true;
         callback.OnPurchaseSucceeded(productId, receipt, tranId);
     });
 }
コード例 #6
0
 public void RestoreTransactions(Action <bool> callback)
 {
     restoreCalled = true;
     foreach (var product in m_PurchasedProducts)
     {
         m_Biller.OnPurchaseSucceeded(product, "{ \"this\" : \"is a fake receipt\" }", "1");
     }
     callback(true);
 }
コード例 #7
0
 public virtual void OnPurchaseSucceeded(string id, string receipt, string transactionID)
 {
     if (!eventsDisabled)
     {
         SendPurchaseSucceededEvent(id, receipt, transactionID);
     }
     unity.OnPurchaseSucceeded(id, receipt, transactionID);
     Promo.ProvideProductsToAds(this, unity);
 }
コード例 #8
0
        public void OnPurchaseSucceeded(BillingResult item)
        {
            if (!item.IsSuccess)
            {
                OnPurchaseFailed(item.Message, item.Response);
                return;
            }

            string transactionId = item.Purchase.OrderId;

            #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.Purchase.SKU, item.Purchase.OriginalJson, transactionId);
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        public void OnPurchaseSucceeded(BillingTransaction item)
        {
            if (item == null || !string.IsNullOrEmpty(item.Error))
            {
                OnPurchaseFailed(item == null ? "Unkown Billing Error." : item.Error, 1);
                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.TransactionReceipt, transactionId);
        }
コード例 #10
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));
            });
        }
コード例 #11
0
        private void ParsePurchaseResult(AndroidJavaObject billingResult, AndroidJavaObject javaPurchasesList)
        {
            var responseCode = _jniUtils.GetResponseCodeFromBillingResult(billingResult);
            var debugMessage = JniUtils.GetDebugMessageFromBillingResult(billingResult);

            if (responseCode == BillingResponseCode.Ok)
            {
                var purchasesList = _jniUtils.ParseJavaPurchaseList(javaPurchasesList);
                _inventory.UpdatePurchaseInventory(purchasesList);
                // Unity IAP only supports one purchase at a time.
                Purchase purchase = purchasesList.First();
                if (Google.Play.Billing.Internal.Purchase.State.Pending.Equals(purchase.PurchaseState))
                {
                    string unityProductId;
                    _inventory.GetUnityProductId(purchase.ProductId, out unityProductId);
                    _billingUtil.RunOnMainThread(() =>
                                                 _deferredPurchaseListener.Invoke(_callback.products.WithID(unityProductId)));
                }
                else
                {
                    _billingUtil.RunOnMainThread(() =>
                                                 _callback.OnPurchaseSucceeded(purchase.ProductId, purchase.JsonReceipt,
                                                                               purchase.TransactionId));
                }
            }
            else
            {
                _billingUtil.LogWarningFormat("Purchase failed with error code '{0}' and debug message: '{1}'",
                                              responseCode, debugMessage);
                PurchaseFailureReason purchaseFailureReason;
                switch (responseCode)
                {
                case BillingResponseCode.UserCancelled:
                    purchaseFailureReason = PurchaseFailureReason.UserCancelled;
                    break;

                case BillingResponseCode.ServiceTimeout:
                case BillingResponseCode.ServiceDisconnected:
                case BillingResponseCode.ServiceUnavailable:
                case BillingResponseCode.BillingUnavailable:
                    purchaseFailureReason = PurchaseFailureReason.PurchasingUnavailable;
                    break;

                case BillingResponseCode.ItemUnavailable:
                    purchaseFailureReason = PurchaseFailureReason.ProductUnavailable;
                    break;

                case BillingResponseCode.ItemAlreadyOwned:
                    purchaseFailureReason = PurchaseFailureReason.DuplicateTransaction;
                    break;

                default:
                    purchaseFailureReason = PurchaseFailureReason.Unknown;
                    break;
                }

                // Copy _productInPurchaseFlow.id into the delegate as the delegate is called by the main thread and
                // _productInPurchaseFlow will get cleaned up immediately in this thread.
                var productId = _productInPurchaseFlow.id;
                _billingUtil.RunOnMainThread(() =>
                                             _callback.OnPurchaseFailed(
                                                 new PurchaseFailureDescription(productId, purchaseFailureReason, debugMessage)));
            }

            _productInPurchaseFlow = null;
        }
 public void OnPurchaseSuccessful(string sku, string receipt, string purchaseToken)
 {
     m_StoreCallback?.OnPurchaseSucceeded(sku, receipt, purchaseToken);
 }
コード例 #13
0
 public void OnPurchaseSucceeded(string id, string receipt, string transactionID)
 {
     m_Util.RunOnMainThread(() => m_ForwardTo.OnPurchaseSucceeded(id, receipt, transactionID));
 }
コード例 #14
0
 public virtual void OnPurchaseSucceeded(string id, string receipt, string transactionID)
 {
     unity.OnPurchaseSucceeded(id, receipt, transactionID);
 }
コード例 #15
0
 private void OnSocialProductPurchased(string productId, string transactionId)
 {
     _callback.OnPurchaseSucceeded(productId, "", transactionId);
 }