Beispiel #1
0
        private void PurchaseResponseCallback(PurchaseResponse eventName)
        {
            if (eventName.Status == "NOT_SUPPORTED")
            {
                EB.Debug.LogError("PurchaseResponseCallback: NOT_SUPPORTED");

                if (_config.OnPurchaseFailed != null)
                {
                    _config.OnPurchaseFailed(eventName.Status);
                }
                return;
            }

            if (eventName.Status == "FAILED")
            {
                EB.Debug.LogError("PurchaseResponseCallback: FAILED");

                if (_config.OnPurchaseFailed != null)
                {
                    _config.OnPurchaseFailed(eventName.Status);
                }

                return;
            }

            if (eventName.PurchaseReceipt.CancelDate > 0)
            {
                if (_config.OnPurchaseCanceled != null)
                {
                    _config.OnPurchaseCanceled();
                }

                return;
            }

            //Note: sounds like this could be called as soon as the customer connects if they didn't receive their success response last time they bought something (e.g. connectivity loss or device shuts down)
            var receipt = eventName.PurchaseReceipt;

            EB.Debug.Log("purchaseSuccessfulEvent: " + receipt.ToJson());

            Transaction transaction = new Transaction();

            transaction.transactionId = receipt.ReceiptId;
            transaction.signature     = "";

            // doing this here so we don't have to modify the Amazon plugin code.
            Hashtable payload = new Hashtable();

            payload["sku"]    = receipt.Sku;
            payload["userId"] = eventName.AmazonUserData.UserId;

            transaction.payload   = EB.JSON.Stringify(payload);
            transaction.productId = receipt.Sku;

            if (_config.ReceiptPersistance != null)
            {
                _config.ReceiptPersistance.AddPendingPurchaseReceipt(eventName.ToJson(), string.Empty);                   // save the token in case it doesn't get verified correctly, so we can retry later.
            }
            else
            {
                EB.Debug.Log("++++++++ NO RECEIPT PERSISTANCE!!");
            }

            if (_config.Verify != null)
            {
                _config.Verify(transaction);
            }
            else
            {
                Complete(transaction);
            }
        }