Exemple #1
0
        public async System.Threading.Tasks.Task <ActionResult> Buy()
        {
            string myShopifyUrl = Session["shop"].ToString();
            string accessToken  = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault().Token;


            try
            {
                var service = new RecurringChargeService(myShopifyUrl, accessToken);
                var charge  = new RecurringCharge()
                {
                    Name  = "Premium Account",
                    Price = 7,
                    /* Test= true,*/
                    //Test = true, //Marks this charge as a test, meaning it won't charge the shop owner.
                    ReturnUrl = "https://www.leaderpush.com/Premium/Confirm"
                };

                charge = await service.CreateAsync(charge);

                ShopLink link = db.ShopLinks.Where(w => w.Shop == myShopifyUrl).FirstOrDefault();
                link.PremiumID = charge.Id;
                db.Entry(link).Property(w => w.PremiumID).IsModified = true;
                db.SaveChanges();

                return(Redirect(charge.ConfirmationUrl));
            }
            catch
            {
                return(RedirectToAction("UrlBreak", "Home"));
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates the recurring charge asynchronously.
        /// </summary>
        /// <param name="myShopifyDomain">My shopify URL.</param>
        /// <param name="shopifyAccessToken">The shopify access token.</param>
        /// <param name="charge">Valid charge object.</param>
        /// <returns></returns>
        public async Task <ShopifyRecurringChargeObject> CreateRecurringChargeAsync(string myShopifyDomain, string shopifyAccessToken, ShopifyRecurringChargeObject charge)
        {
            _CheckmyShopifyDomain(myShopifyDomain);
            _CheckShopAccessToken(shopifyAccessToken);
            _Logger.LogInformation($"Creating recurring charge '{charge.Name} - {charge.Price} - {(charge.Test.Value ? "is_test" : "not_test")} - {charge.TrialDays} days - {charge.ReturnUrl}'.");
            RecurringChargeService service = new RecurringChargeService(myShopifyDomain, shopifyAccessToken);
            var ret = await service.CreateAsync(new RecurringCharge()
            {
                Name      = charge.Name,
                Price     = charge.Price,
                Terms     = charge.Terms,
                ReturnUrl = charge.ReturnUrl,
                TrialDays = charge.TrialDays,
                Test      = charge.Test
            });

            _Logger.LogInformation($"Done creating '{ret.Name}' with id = {ret.Id}.");

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