Esempio n. 1
0
    public override void Initialize()
    {
        if (this.m_ProductsDict == null)
        {
            this.InitialProductItems();
        }

        string unconfirmedPurchaseID = PlayerPrefs.GetString(UNCONFIRMED_PURCHASE_ID_KEY, string.Empty);

        if (string.IsNullOrEmpty(unconfirmedPurchaseID))
        {
            string unconfirmedProductID = PlayerPrefs.GetString(UNCONFIRMED_PRODUCT_ID_KEY, string.Empty);
            if (string.IsNullOrEmpty(unconfirmedProductID))
            {
                NdIdleContext idleContext = new NdIdleContext();
                this.ChangeContext(idleContext);
                this.State = ShopActionState.Idle;
            }
            else
            {
                this.m_CurrentPurchaseID = unconfirmedProductID;
                NdRequestPurchaseIDContext requestContext = new NdRequestPurchaseIDContext();
                this.ChangeContext(requestContext);
                this.State = ShopActionState.Operating;
            }
        }
        else
        {
            NdConfirmContext confirmContext = new NdConfirmContext();
            this.ChangeContext(confirmContext);
            this.State = ShopActionState.Operating;
        }
    }
Esempio n. 2
0
    public override void PurchaseProduct(string productID)
    {
        Debug.Log(productID);
        Debug.Log(this.m_CurrentContext);

        NdIdleContext idleContext = this.m_CurrentContext as NdIdleContext;

        if (idleContext != null)
        {
            Debug.Log("real start!");
            this.State = ShopActionState.Operating;
            idleContext.PurchaseProduct(productID);
        }
    }
Esempio n. 3
0
    public override void Execute()
    {
        if (!m_IsConfirm)
        {
            string purchaseID = PlayerPrefs.GetString(NdShopUtility.UNCONFIRMED_PURCHASE_ID_KEY);
            string productID  = PlayerPrefs.GetString(NdShopUtility.UNCONFIRMED_PRODUCT_ID_KEY);
            ConfirmNdPurchaseRequestParameter request = new ConfirmNdPurchaseRequestParameter();
            request.PurchaseID = purchaseID;
            request.ProductID  = productID;
            CommunicationUtility.Instance.ConfirmNdPurchase(request, this.ShopModule, "ReceivedConfirmResponse", true);

            this.m_IsConfirm = true;
        }
        else
        {
            NdShopUtility ndShopUtility = (NdShopUtility)this.ShopModule;
            if (ndShopUtility.IsReceivedConfirmResponse)
            {
                NdIdleContext context = new NdIdleContext();
                this.ShopModule.ChangeContext(context);

                if (string.IsNullOrEmpty(ndShopUtility.CurrentConfirmError))
                {
                    this.ShopModule.State = ShopActionState.Success;
                    string productID             = PlayerPrefs.GetString(NdShopUtility.UNCONFIRMED_PRODUCT_ID_KEY);
                    ShopItemInformation shopItem = ndShopUtility.ProductsDict[productID];
                    this.ShopModule.OnPurchaseSuccessed(shopItem);
                }
                else
                {
                    this.ShopModule.State = ShopActionState.Fail;
                    this.ShopModule.OnPurchaseFailed(new PurchaseFailInformation()
                    {
                        Reason = PurchaseFailedReason.ComfirmFail, ErrorDescription = ndShopUtility.CurrentConfirmError
                    });
                }
                PlayerPrefs.DeleteKey(NdShopUtility.UNCONFIRMED_PURCHASE_ID_KEY);
                PlayerPrefs.DeleteKey(NdShopUtility.UNCONFIRMED_PRODUCT_ID_KEY);
                PlayerPrefs.Save();
            }
        }
    }
Esempio n. 4
0
    public override void Execute()
    {
        if (NdCenter.Instace.CurrentBuyState == BuyState.Success)
        {
            NdConfirmContext confirmContext = new NdConfirmContext();
            this.ShopModule.ChangeContext(confirmContext);
        }
        else if (NdCenter.Instace.CurrentBuyState == BuyState.Fail)
        {
            PlayerPrefs.DeleteKey(NdShopUtility.UNCONFIRMED_PRODUCT_ID_KEY);
            PlayerPrefs.DeleteKey(NdShopUtility.UNCONFIRMED_PURCHASE_ID_KEY);
            PlayerPrefs.Save();

            NdIdleContext context = new NdIdleContext();
            this.ShopModule.ChangeContext(context);
            this.ShopModule.State = ShopActionState.Fail;

            this.ShopModule.OnPurchaseFailed(new PurchaseFailInformation()
            {
                Reason = PurchaseFailedReason.Cancel, ErrorDescription = NdCenter.Instace.BuyError
            });
        }
    }