예제 #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);
        }
예제 #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"));
            }
        }
예제 #3
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"));
            }
        }
예제 #4
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}'");
        }
예제 #5
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
            });
        }
예제 #6
0
 public void TestInitialize()
 {
     Rand = new Random().Next().ToString();
     _recurringChargeService = new RecurringChargeService();
     MethodService           = new PaymentMethodService();
 }