Exemple #1
0
        /// <summary>
        /// Gets the recurring charge asynchronous.
        /// </summary>
        /// <param name="myShopifyDomain">The myshopify URL.</param>
        /// <param name="shopifyAccessToken">The shopify access token.</param>
        /// <param name="chargeId">The charge identifier.</param>
        /// <param name="fields">The fields.</param>
        /// <returns></returns>
        public async Task <ShopifyRecurringChargeObject> GetRecurringChargeAsync(string myShopifyDomain, string shopifyAccessToken, long chargeId, string fields = null)
        {
            _CheckmyShopifyDomain(myShopifyDomain);
            _CheckShopAccessToken(shopifyAccessToken);
            RecurringChargeService service = new RecurringChargeService(myShopifyDomain, shopifyAccessToken);

            _Logger.LogInformation($"Retriving recurring charge with id ='{chargeId}'");
            var data = await service.GetAsync(chargeId, fields);

            var ret = new ShopifyRecurringChargeObject()
            {
                CancelledOn     = data.CancelledOn,
                BillingOn       = data.BillingOn,
                ActivatedOn     = data.ActivatedOn,
                CappedAmount    = data.CappedAmount,
                ConfirmationUrl = data.ConfirmationUrl,
                CreatedAt       = data.CreatedAt,
                Id          = data.Id,
                Name        = data.Name,
                Price       = data.Price,
                ReturnUrl   = data.ReturnUrl,
                Status      = data.Status,
                Terms       = data.Terms,
                Test        = data.Test,
                TrialDays   = data.TrialDays,
                TrialEndsOn = data.TrialEndsOn,
                UpdatedAt   = data.UpdatedAt
            };

            _Logger.LogInformation($"Found recurring charge '{ret.Id} - {ret.Name} - {ret.Price} - {(ret.Test.Value ? "is_test" : "not_test")} - {ret.TrialDays} days - {ret.ReturnUrl}'.");
            return(ret);
        }
Exemple #2
0
        public async System.Threading.Tasks.Task <ActionResult> Confirm(long charge_id)
        {
            string myShopifyUrl = db.ShopLinks.Where(w => w.PremiumID == charge_id).FirstOrDefault().Shop;
            string accessToken  = db.ShopLinks.Where(w => w.PremiumID == charge_id).FirstOrDefault().Token;



            try
            {
                var service = new RecurringChargeService(myShopifyUrl, accessToken);

                var charge = await service.GetAsync(charge_id);

                if (charge.Status == "accepted")
                {
                    await service.ActivateAsync(charge_id);

                    ShopLink link = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault();
                    link.IsPremium = true;
                    db.Entry(link).Property(w => w.IsPremium).IsModified = true;
                    db.SaveChanges();
                }
                else if (charge.Status == "declined")
                {
                    return(RedirectToAction("Failed", "Premium"));
                }

                return(RedirectToAction("Install", "Home", new { shop = myShopifyUrl }));
            }
            catch
            {
                return(RedirectToAction("UrlBreak", "Home"));
            }
        }