Ejemplo n.º 1
0
        public void BuyPayout(IAP.Item item, System.Action <string, IAP.Transaction> callback, object extraInfo = null)
        {
            if (!string.IsNullOrEmpty(item.LimitedTimeGiftId))//新增限时礼包的物品关联处理
            {
                if (extraInfo == null)
                {
                    var ht = Johny.HashtablePool.Claim();
                    ht["limitedTimeGiftId"] = item.LimitedTimeGiftId;
                    extraInfo = ht;
                }
                else
                {
                    ((Hashtable)extraInfo).Add("limitedTimeGiftId", item.LimitedTimeGiftId);
                }
            }

            _api.BuyPayout(string.Format("{0}{1}", _externalId, _iapManager.ProviderName), item.payoutId, _iapManager.ProviderName, item.value, new ArrayList(), delegate(string error, Hashtable data)
            {
                if (!string.IsNullOrEmpty(error))
                {
                    callback(error, null);
                    return;
                }

                if (data == null || data.Count == 0)
                {
                    callback("BuyPayout result is empty", null);
                    return;
                }

                IAP.Transaction transaction = new IAP.Transaction();
                transaction.transactionId   = EB.Dot.String("store.info.transactionid", data, null);
                transaction.productId       = item.productId;
#if USE_TENCENTSDK || USE_VIVOSDK || USE_HUAWEISDK
                transaction.payload = EB.Dot.String("store.info.extraInfo", data, null);
#else
                transaction.payload = EB.Dot.String("store.info.extraInfo", data, item.developerPayload.Replace("{platform}", _iapManager.ProviderName));
#endif
                transaction.signature     = EB.Dot.String("store.info.sign", data, transaction.signature);
                transaction.platform      = _iapManager.ProviderName;
                transaction.serverPayload = _iapManager.GetPayload(transaction);

                transaction.IAPPlatform = _iapManager.ProviderName;//多渠道支付时用到

                callback(null, transaction);

                //生成订单后把订单存储在本地
                SparxTransactionHelper.AddTransInLocal(transaction);
            }, extraInfo);
        }
Ejemplo n.º 2
0
        private void VerifyPayout(IAP.Transaction transaction)
        {
            IAP.Item payout = _payouts.Find(delegate(IAP.Item obj) {
                return(obj.productId == transaction.productId);
            });

            if (payout == null)
            {
                EB.Debug.Log("【商城】无法验证,找不到商品:productId:{0};transactionId:{1}", transaction.productId, transaction.transactionId);
                _verify.Add(transaction);
                return;
            }
            Hashtable data = Johny.HashtablePool.Claim();

            data["cents"]         = payout.cents;
            data["currency"]      = payout.currencyCode;
            data["externalTrkid"] = _externalId + (string.IsNullOrEmpty(transaction.IAPPlatform)?_iapManager.ProviderName:transaction.IAPPlatform);
            data["payoutid"]      = payout.payoutId;
            data["platform"]      = transaction.platform;

            if (!string.IsNullOrEmpty(transaction.limitedTimeGiftId))
            {
                data["limitedTimeGiftId"] = transaction.limitedTimeGiftId;
            }

            if (_iapManager.ProviderName == "itunes")
            {
                data["receipt-data"] = transaction.payload;
            }
            else
            {
                data["response-data"]      = transaction.payload;
                data["response-signature"] = transaction.signature;
            }

            CheckSupplementTransaction(transaction.transactionId);
            EB.Debug.Log("【商城】校验:{0}", transaction.transactionId);
            isRequest = true;
            _api.VerifyPayout(_iapManager.ProviderName, data, delegate(string err, Hashtable res){
                EB.Debug.Log("【商城】校验回调:{0}", transaction.transactionId);
                isRequest = false;
                OnVerifyPayout(payout, transaction, err, res);
                if (chargeSuccessCallBack != null && res != null && string.IsNullOrEmpty(err))
                {
                    chargeSuccessCallBack(res);
                }
            });
        }
Ejemplo n.º 3
0
 ///补单验单回调
 private void OnVerifyPayoutAgain(IAP.Item item, IAP.SupplementTransaction trans, string err, Hashtable data)
 {
     if (!string.IsNullOrEmpty(err))
     {
         CheckSupplementTransaction(trans.transactionId);
         RemoveSomeTransaction();
         _VerifyAgain.Add(trans);
         return;
     }
     _lastFetchTime = 0;
     Fetch();
     FetchOffers();
     _iapManager.Complete(trans);
     _config.Listener.OnOfferPurchaseRedeemer(data);
     _config.Listener.OnOfferPurchaseSuceeded(item, trans);
 }
Ejemplo n.º 4
0
        ///正常验单回调
        private void OnVerifyPayout(IAP.Item item, IAP.Transaction trans, string err, Hashtable data)
        {
            if (!string.IsNullOrEmpty(err))
            {
                EB.Debug.Log("【商城】订单校验有错误transactionId:{0}", trans.transactionId);
                if (EB.Dot.Bool("verify.retry", data, true))
                {
                    EB.Debug.Log("【商城】订单再次重新尝试校验transactionId:{0}", trans.transactionId);
                    int delay = (int)EB.Dot.Single("verify.delay", data, 3.0f) * 1000;
                    EB.Coroutines.SetTimeout(delegate()
                    {
                        if (!_verify.Contains(trans))
                        {
                            _verify.Add(trans);
                        }
                    }, delay);
                }
                else
                {
                    EB.Debug.Log("【商城】订单无效移除,并加进补单列表transactionId:{0};err:{1}", trans.transactionId, err);
                    _config.Listener.OnOfferPurchaseFailed(err);
                    CheckSupplementTransaction(trans.transactionId);
                    RemoveSomeTransaction();
                    _VerifyAgain.Add(new SupplementTransaction(trans));
                    SparxTransactionHelper.DelTransInLocal(trans);
                }
                FetchOffersDelayed();
                return;
            }

            _lastFetchTime = 0;
            Fetch();
            FetchOffers();
            _iapManager.Complete(trans);

            _config.Listener.OnOfferPurchaseRedeemer(data);
            _config.Listener.OnOfferPurchaseSuceeded(item, trans);
            EB.Debug.Log("【商城】订单成功transactionId:{0}", trans.transactionId);
            SparxTransactionHelper.DelTransInLocal(trans);
            CheckSupplementTransaction(trans.transactionId);
        }
Ejemplo n.º 5
0
        public void PurchaseOffer(IAP.Item item, Hashtable table = null)
        {
            if (table != null)
            {
                if (table.ContainsKey("callBack"))
                {
                    chargeSuccessCallBack = table["callBack"] as System.Action <Hashtable>;
                }
                if (table.ContainsKey("loadingEvent"))
                {
                    loadingUIEvent = table["loadingEvent"] as System.Action <bool>;
                }
            }

            if (_iapManager != null)
            {
                _iapManager.PurchaseItem(item);
            }
            else
            {
                _config.Listener.OnOfferPurchaseFailed("ID_SPARX_ERROR_MUST_BE_LOGGED_IN");
            }
        }