Exemple #1
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"));
            }
        }
Exemple #2
0
        /// <summary>
        /// Activates the recurring charge asynchronously.
        /// </summary>
        /// <param name="myShopifyDomain">My shopify URL.</param>
        /// <param name="shopifyAccessToken">The shopify access token.</param>
        /// <param name="chargeId">The charge identifier.</param>
        /// <returns></returns>
        public async Task ActivateRecurringChargeAsync(string myShopifyDomain, string shopifyAccessToken, long chargeId)
        {
            _CheckmyShopifyDomain(myShopifyDomain);
            _CheckShopAccessToken(shopifyAccessToken);
            _Logger.LogInformation($"Activating recurring charge id '{chargeId}'");
            RecurringChargeService service = new RecurringChargeService(myShopifyDomain, shopifyAccessToken);
            await service.ActivateAsync(chargeId);

            _Logger.LogInformation($"Done activating recurring charge id '{chargeId}'");
        }