Exemplo n.º 1
0
        public override void GetSKUDetails(string[] sku_array = null)
        {
            CommerceLog("getSKUDetails: Mock Getting Product Details From Product List");
            CommerceError commerceError = null;

            if (sku_array == null)
            {
                sku_array = productList.GetSkusForLookup();
            }
            switch (testMode)
            {
            case 0:
                commerceError = new CommerceError(100, "Mock Object general failure");
                sendInventoryResponse(commerceError);
                break;

            case 1:
            case 3:
            case 4:
            {
                CommerceLog("Starting to generate fake sku list");
                string[] array = sku_array;
                foreach (string text in array)
                {
                    SkuInfo item = new SkuInfo(text + " title", "$1.99", "inapp", "Product 1 Desc", text, "USD", "$", i_purchasable: true);
                    CommerceLog("Adding sku to list: " + text);
                    _retrievedSkuInfo.Add(item);
                }
                CommerceLog("Calling Inventory Response");
                productList.AddStoreInformationBySKU(_retrievedSkuInfo);
                sendInventoryResponse(_retrievedSkuInfo);
                break;
            }

            case 2:
                commerceError = new CommerceError(200, "Mock Object general failure");
                sendInventoryResponse(commerceError);
                break;

            default:
                CommerceLog("Mock Object: getSkuDetails does not cover this case");
                break;
            }
        }
Exemplo n.º 2
0
        public override void PurchaseProductFromStore(string product)
        {
            isPurchaseInProgress = true;
            CommerceLog("Mock PurchaseProduct: Purchasing sku " + product);
            CommerceError commerceError = null;
            PurchaseInfo  purchaseInfo  = null;
            SkuInfo       skuInfo       = null;

            switch (testMode)
            {
            case 0:
                commerceError = new CommerceError(100, "Mock Object general failure");
                sendPurchaseResponse(commerceError);
                break;

            case 1:
                purchaseInfo = new PurchaseInfo("1001", product, 1413836611000L, "product1_token", "Purchased");
                skuInfo      = new SkuInfo("Product 1", "$1.99", "Non-Consumable", "Product 1 Desc", product, "USD", "$", i_purchasable: true);
                sendPurchaseResponse(purchaseInfo, skuInfo);
                break;

            case 2:
                commerceError = new CommerceError(300, "Mock Object general failure");
                sendPurchaseResponse(commerceError);
                break;

            case 3:
                commerceError = new CommerceError(305, "Apple Ask To Buy");
                sendPurchaseResponse(commerceError);
                break;

            case 4:
                purchaseInfo = new PurchaseInfo("1001", product, 1413836611000L, "product1_token", "Purchased");
                skuInfo      = new SkuInfo("Product 1", "$1.99", "Non-Consumable", "Product 1 Desc", product, "USD", "$", i_purchasable: true);
                sendUnexpectedPurchaseResponse(purchaseInfo, skuInfo);
                break;

            default:
                CommerceLog("Mock Object: PurchaseProduct does not cover this case");
                break;
            }
            isPurchaseInProgress = false;
        }
Exemplo n.º 3
0
        private bool onPurchaseFailedEvent(IAPServiceErrors.PCPurchaseError error)
        {
            CommerceLog("purchaseFailedEvent: " + error.PurchaseError.ToJson());
            isPurchaseInProgress = false;
            JsonData      jsonData      = (error.PurchaseError.Contains("error") ? error.PurchaseError["error"] : null);
            CommerceError commerceError = null;

            if (jsonData != null && jsonData.Contains("Code") && jsonData.Contains("Message"))
            {
                string text = jsonData["Code"].ToString();
                int    num;
                switch (text)
                {
                case "1034":
                    commerceError = new CommerceError(301, (string)jsonData["Message"]);
                    break;

                default:
                    num = ((!(text == "25")) ? 1 : 0);
                    goto IL_0100;

                case "22":
                case "23":
                case "24":
                {
                    num = 0;
                    goto IL_0100;
                }
IL_0100:
                    commerceError = ((num != 0) ? new CommerceError(300, (string)jsonData["Message"]) : new CommerceError(309, (string)jsonData["Message"]));
                    break;
                }
            }
            else
            {
                commerceError = new CommerceError(300, error.PurchaseError.ToJson());
            }
            sendPurchaseResponse(commerceError);
            CommerceLog("purchaseFailedEvent: complete");
            return(false);
        }
Exemplo n.º 4
0
        public virtual void PurchaseProduct(string product, string payload)
        {
            CommerceError commerceError = null;

            CommerceLog("PurchaseProduct: Purchasing product " + product + ", with payload " + payload);
            if (!IsBillingSupported())
            {
                commerceError = new CommerceError(100, "Billing Not Supported");
                sendPurchaseResponse(commerceError);
                return;
            }
            Product productByKey = GetProductByKey(product);

            if (productByKey == null)
            {
                commerceError = new CommerceError(306, "Product key' " + product + "' Not Found");
                sendPurchaseResponse(commerceError);
                return;
            }
            if (!productByKey.IsPurchasable())
            {
                commerceError = new CommerceError(307, "Product key' " + product + "' Not Purchasable. No store information retrieved?");
                sendPurchaseResponse(commerceError);
                return;
            }
            if (payload != null && payload != "")
            {
                CommerceLog("PurchaseProduct: Triggering purchase product with payload");
                PurchaseProductFromStore(productByKey.GetStoreSKU(), payload);
            }
            else
            {
                CommerceLog("PurchaseProduct: Triggering purchase product without payload");
                PurchaseProductFromStore(productByKey.GetStoreSKU());
            }
            CommerceLog("PurchaseProduct: Finishing purchasing " + product);
        }
Exemplo n.º 5
0
        private void handleRestorePlayerPurchases(List <PurchaseInfo> playerInventory, List <SkuInfo> skuInfos, CommerceError cError)
        {
            string text = "";

            if (cError.HasError())
            {
                text = "RestorePlayerPurchases: Error Found: Number " + cError.GetErrorNo() + ", Desc " + cError.GetErrorDesc();
                Service.Get <EventDispatcher>().DispatchEvent(new CommerceServiceErrors.RestoreVerifiedError(cError));
                return;
            }
            object obj = text;

            text = string.Concat(obj, "Total Purchases to Restore: ", playerInventory.Count, "\n");
            foreach (PurchaseInfo item in playerInventory)
            {
            }
            verifyPurchaseRestoreWithService(playerInventory, skuInfos);
        }
Exemplo n.º 6
0
        private void handleUnexpectedPurchaseRetrieval(PurchaseInfo PI, SkuInfo purSkuInfo, CommerceError cError)
        {
            string text = "";

            if (!cError.HasError())
            {
                text = "handleUnexpectedPurchaseRetrieval: Purchase Success so far purchaseinfo object\n" + PI.ToString();
            }
            Service.Get <EventDispatcher>().DispatchEvent(new CommerceServiceEvents.UnexpectedPurchase(PI, purSkuInfo));
        }
Exemplo n.º 7
0
        private bool onProductListReceivedEvent(IAPServiceEvents.PCProductDetailsReturned productDetailsReturned)
        {
            List <CSGInfo> list  = new List <CSGInfo>();
            List <CSGInfo> list2 = new List <CSGInfo>();

            csgConfig.ProductId = productDetailsReturned.ProductDetails.Context.ProductContext.ProductId;
            List <PCPricePlan>          pricingPlans          = productDetailsReturned.ProductDetails.Product.PricingPlans;
            List <PCOrderablePricePlan> orderablePricingPlans = productDetailsReturned.ProductDetails.Context.ProductContext.OrderablePricingPlans;

            if (orderablePricingPlans == null || pricingPlans == null)
            {
                CommerceError commerceError = null;
                commerceError = new CommerceError(201, "Inventory Query Failed");
                sendInventoryResponse(commerceError);
                return(false);
            }
            CommerceLog($"PCProductDetailsReturned. total price plans: {orderablePricingPlans.Count}");
            retrievedSkuInfo = new List <SkuInfo>();
            Dictionary <long, PCPricePlan>          dictionary  = new Dictionary <long, PCPricePlan>();
            Dictionary <long, PCOrderablePricePlan> dictionary2 = new Dictionary <long, PCOrderablePricePlan>();

            foreach (PCPricePlan item2 in pricingPlans)
            {
                dictionary.Add(item2.Id, item2);
            }
            foreach (PCOrderablePricePlan item3 in orderablePricingPlans)
            {
                dictionary2.Add(item3.Id, item3);
            }
            foreach (PCPricePlan item4 in pricingPlans)
            {
                CommerceLog($"Processing availablePlan: Id={item4.Id}, Amount={item4.ChargeAmount}, Currency={item4.Currency}, Subscription={item4.Subscription}, BillingCycle={item4.SubscriptionBillingCycle}, BillingIterations={item4.SubscriptionBillingCycleIterations}, CycleName={item4.SubscriptionBillingCycleName}");
                string      text = "";
                PCPricePlan current;
                PCPricePlan pCPricePlan = (current = item4);
                CommerceLog($"Setting Main plan: Id={current.Id}, Amount={current.ChargeAmount}, Currency={current.Currency}, Subscription={current.Subscription}, BillingCycle={current.SubscriptionBillingCycle}, BillingIterations={current.SubscriptionBillingCycleIterations}, CycleName={current.SubscriptionBillingCycleName}");
                if (current.AdditionalProperties != null)
                {
                    foreach (AdditionalPricePlanProperties additionalProperty in current.AdditionalProperties)
                    {
                        if (!(additionalProperty.Name == "FALLBACK_PLAN"))
                        {
                            continue;
                        }
                        CommerceLog("Found FALLBACK_PLAN in AdditionalProperties");
                        if (long.TryParse(additionalProperty.Values[0], out var result))
                        {
                            CommerceLog("Found fallback_id=" + result);
                            if (dictionary.ContainsKey(result))
                            {
                                pCPricePlan = dictionary[result];
                                CommerceLog($"Setting Fallback plan: Id={pCPricePlan.Id}, Amount={pCPricePlan.ChargeAmount}, Currency={pCPricePlan.Currency}, Subscription={pCPricePlan.Subscription}, BillingCycle={pCPricePlan.SubscriptionBillingCycle}, BillingIterations={pCPricePlan.SubscriptionBillingCycleIterations}, CycleName={pCPricePlan.SubscriptionBillingCycleName}");
                            }
                        }
                    }
                }
                if (current.ExternalReferences != null)
                {
                    foreach (ExternalReference externalReference in current.ExternalReferences)
                    {
                        if (externalReference.ExternalId == "CPI_PricingPlan")
                        {
                            text = externalReference.Value.ToString();
                            CommerceLog("CSG CPI_PricingPlan=" + text);
                        }
                    }
                }
                string trialDuration = "";
                string text2         = "";
                text2 = getDuration(pCPricePlan.SubscriptionBillingCycleIterations.ToString(), (DurationCode)pCPricePlan.SubscriptionBillingCycle);
                if (pCPricePlan.Id != current.Id)
                {
                    CommerceLog("Plan has a fallback plan therefore has Trial");
                    trialDuration = getDuration(current.SubscriptionBillingCycleIterations.ToString(), (DurationCode)current.SubscriptionBillingCycle);
                }
                bool flag = dictionary2.ContainsKey(current.Id);
                CommerceLog("Is this plan (" + current.Id + ") purchaseable? " + flag);
                SkuInfo skuData = new SkuInfo(pCPricePlan.DisplayName, GetCurrencyFormattedNumber(pCPricePlan.ChargeAmount, pCPricePlan.Currency), "", pCPricePlan.Description, current.Id.ToString(), pCPricePlan.Currency, GetCurrencySymbol(pCPricePlan.Currency), flag);
                CSGInfo item    = new CSGInfo(current.Id.ToString(), text, text2, trialDuration, skuData);
                if (flag)
                {
                    list.Add(item);
                }
                else
                {
                    list2.Add(item);
                }
                CommerceLog("Adding sku to list: " + current.Id);
            }
            CommerceLog("<color=magenta>Calling Inventory Response</color>");
            foreach (CSGInfo item5 in list)
            {
                CommerceLog("Processing orderable plan=" + item5.PlanId);
                Product productByDuration = productList.GetProductByDuration(item5.SkuDuration, item5.TrialDuration);
                if (productByDuration != null && productByDuration.NeedsSkuInformation())
                {
                    productByDuration.SetCSGData(item5.PlanId, item5.ExternalReference);
                    productByDuration.AddStoreInformation(item5.SkuData);
                    retrievedSkuInfo.Add(item5.SkuData);
                    CommerceLog("Updated product for plan=" + item5.PlanId + " product=" + productByDuration);
                }
            }
            foreach (CSGInfo item6 in list2)
            {
                CommerceLog("Processing non orderable plan=" + item6.PlanId);
                Product productByDuration = productList.GetProductByDuration(item6.SkuDuration, item6.TrialDuration);
                if (productByDuration != null && productByDuration.NeedsSkuInformation())
                {
                    productByDuration.SetCSGData(item6.PlanId, item6.ExternalReference);
                    productByDuration.AddStoreInformation(item6.SkuData);
                    retrievedSkuInfo.Add(item6.SkuData);
                    CommerceLog("Updated product for plan=" + item6.PlanId + " product=" + productByDuration);
                }
            }
            sendInventoryResponse(retrievedSkuInfo);
            CommerceLog("Finished getting Price Plan Info");
            return(false);
        }
Exemplo n.º 8
0
        protected void sendBillingEnabledResponse(bool success)
        {
            CommerceError cError = new CommerceError();

            sendBillingEnabledResponse(success, cError);
        }
Exemplo n.º 9
0
 protected void sendBillingEnabledResponse(CommerceError cError)
 {
     sendBillingEnabledResponse(success: false, cError);
 }
Exemplo n.º 10
0
        protected void sendPurchaseVerifiedResponse(bool success)
        {
            CommerceError cError = new CommerceError();

            sendPurchaseVerifiedResponse(success, cError);
        }
Exemplo n.º 11
0
 protected void sendPurchaseVerifiedResponse(CommerceError cError)
 {
     sendPurchaseVerifiedResponse(success: false, cError);
 }
Exemplo n.º 12
0
 protected void sendPurchaseRestoreResponse(List <PurchaseInfo> pil, List <SkuInfo> sil, CommerceError cError = null)
 {
     if (PurchaseRestoreResponse != null)
     {
         CommerceLog("sendPurchaseRestoreResponse: not null");
         if (cError == null)
         {
             cError = new CommerceError();
         }
         PurchaseRestoreResponse(pil, sil, cError);
     }
     else
     {
         CommerceLog("sendPurchaseRestoreResponse: is null");
     }
 }
Exemplo n.º 13
0
 protected void sendPurchaseRestoreResponse(CommerceError cError)
 {
     sendPurchaseRestoreResponse(null, null, cError);
 }
Exemplo n.º 14
0
 protected void sendPlayerInventoryResponse(CommerceError cError)
 {
     sendPlayerInventoryResponse(null, cError);
 }
Exemplo n.º 15
0
 protected void sendUnexpctedPurchaseResponse(CommerceError cError)
 {
     sendUnexpectedPurchaseResponse(null, null, cError);
 }