Esempio n. 1
0
        public override void RestorePurchases()
        {
            CommerceLog("Mock RestorePurchases: Started");
            CommerceError  commerceError = null;
            SkuInfo        item          = new SkuInfo("Product 1", "$1.99", "Non-Consumable", "Product 1 Desc", "com.cp.product1", "USD", "$", i_purchasable: true);
            List <SkuInfo> list          = new List <SkuInfo>();

            list.Add(item);
            PurchaseInfo        item2 = new PurchaseInfo("1001", "com.cp.product1", 1413836611000L, "product1_token", "Purchased");
            List <PurchaseInfo> list2 = new List <PurchaseInfo>();

            list2.Add(item2);
            switch (testMode)
            {
            case 0:
                commerceError = new CommerceError(100, "Mock Object general failure");
                sendPurchaseRestoreVerifiedResponse(commerceError);
                break;

            case 1:
            case 3:
            case 4:
                sendPurchaseRestoreResponse(list2, list);
                break;

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

            default:
                CommerceLog("Mock Object: getSkuDetails does not cover this case");
                break;
            }
        }
Esempio n. 2
0
 private bool onPurchaseSuccessfulEvent(IAPServiceEvents.PCPurchaseSuccess transaction)
 {
     CommerceLog("purchaseSuccessfulEvent: " + transaction.PurchaseDetails.ToJson());
     currentPurchaseInfo    = new PurchaseInfo(transaction.PurchaseDetails);
     currentPurchaseSkuInfo = SkuInfo.GetSkuFromList(retrievedSkuInfo, currentPurchaseInfo.sku);
     sendPurchaseResponse(currentPurchaseInfo, currentPurchaseSkuInfo);
     return(false);
 }
Esempio n. 3
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));
        }
Esempio n. 4
0
 public void AddStoreInformationBySKU(List <SkuInfo> skuInfoList)
 {
     foreach (Product item in productInformation)
     {
         if (item.NeedsSkuInformation())
         {
             SkuInfo skuFromList = SkuInfo.GetSkuFromList(skuInfoList, item.GetStoreSKU());
             if (skuFromList != null)
             {
                 item.AddStoreInformation(skuFromList);
             }
         }
     }
 }
Esempio n. 5
0
        private void handlePurchaseRetrieval(PurchaseInfo PI, SkuInfo purSkuInfo, CommerceError cError)
        {
            string text = "";

            if (cError.HasError())
            {
                text = "handlePurchaseRetrieval: Error Found: Number " + cError.GetErrorNo() + ", Desc " + cError.GetErrorDesc() + ", skuToLookup " + cError.GetSkuToLookup();
                Service.Get <EventDispatcher>().DispatchEvent(new CommerceServiceErrors.PurchaseVerifiedError(cError));
            }
            else
            {
                text = "handlePurchaseRetrieval: Purchase Success so far purchaseinfo object\n" + PI.ToString();
                verifyPurchaseWithService(PI);
            }
        }
Esempio n. 6
0
 protected void sendUnexpectedPurchaseResponse(PurchaseInfo pi, SkuInfo si, CommerceError cError = null)
 {
     if (PurchaseResponse != null)
     {
         CommerceLog("sendUnexpectedPurchaseResponse: not null");
         if (cError == null)
         {
             cError = new CommerceError();
         }
         UnexpectedPurchaseResponse(pi, si, cError);
     }
     else
     {
         CommerceLog("sendUnexpectedPurchaseResponse: listner is null and not pointing to anything");
     }
 }
Esempio n. 7
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;
            }
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
 public UnexpectedPurchase(PurchaseInfo pi, SkuInfo si)
 {
     PI = pi;
     SI = si;
 }
Esempio n. 10
0
 public void AddStoreInformationByKey(string KeyCode, SkuInfo skuInfo)
 {
     productInformation.Find((Product x) => x.shared_key == KeyCode)?.AddStoreInformation(skuInfo);
 }
Esempio n. 11
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);
        }