Beispiel #1
0
        protected LazyConnectedService()
        {
            var context = new CompleteModel();

            _repo   = new ConnectedLazyRepository <TEntityEF>(new Context <TEntityEF>(context, context.Set <TEntityEF>()));
            _mapper = new Mapper(MapperProfiles.InitializeAutoMapper());
        }
Beispiel #2
0
        internal InternalService()
        {
            _mapper = new Mapper(MapperProfiles.InitializeAutoMapper());
            var context = new CompleteModel();

            _repo = new EagerDisconnectedRepository <TEntityEF>(new Context <TEntityEF>(context, context.Set <TEntityEF>()));
        }
        public IActionResult Complete(CompleteModel model)
        {
            StripeConfiguration.SetApiKey(_stripeOptions.SecretKey);

            var myCharge = new StripeChargeCreateOptions();

            // find the customer with stripe
            var customerService = new StripeCustomerService();
            var customer        = customerService.List().FirstOrDefault(c => c.Email == model.Email);

            if (customer == null)
            {
                var newCustomer = new StripeCustomerCreateOptions
                {
                    Email       = model.Email,
                    Description = model.Name,
                    Metadata    = new Dictionary <string, string>()
                    {
                        { "Website", model.Website },
                        { "TagLine", model.Tagline },
                        { "Notes", model.Notes }
                    }
                };
                customer = customerService.Create(newCustomer);
            }

            // always set these properties
            var numberOfEpisodes = model.NumberOfEpisodes;
            var subTotal         = (_businessOptions.PricePerEpisode * model.NumberOfEpisodes);
            var gst   = (subTotal * 0.05m);
            var total = Math.Round((subTotal + gst), 2);

            model.SubTotal = subTotal;
            model.Gst      = gst;
            model.Total    = total;


            myCharge.Amount   = (int)(total * 100);
            myCharge.Currency = "cad";
            myCharge.Metadata = new Dictionary <string, string>()
            {
                { "CustomerId", customer.Id },
                { "CustomerEmail", model.Email }
            };

            // set this if you want to
            myCharge.Description = "ASP.NET Monsters Sponsorship";
            myCharge.Source      = new StripeSourceOptions {
                TokenId = model.StripeToken
            };

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;

            var          chargeService = new StripeChargeService();
            StripeCharge stripeCharge  = chargeService.Create(myCharge);

            return(View(model));
        }
Beispiel #4
0
        public IActionResult Complete(CompleteModel model)
        {
            StripeConfiguration.SetApiKey(_stripeOptions.SecretKey);

            var myCharge = new StripeChargeCreateOptions();

            // find the customer with stripe
            var customerService = new StripeCustomerService();
            var customer        = customerService.List().FirstOrDefault(c => c.Email == model.EmailAddress);

            if (customer == null)
            {
                var newCustomer = new StripeCustomerCreateOptions
                {
                    Email       = model.EmailAddress,
                    Description = model.FullName,
                    Metadata    = new Dictionary <string, string>()
                    {
                        { "Telephone", model.Telephone }
                    }
                };
                customer = customerService.Create(newCustomer);
            }

            // always set these properties
            var groupSize = model.GroupSize;

            if (groupSize < 3)
            {
                groupSize = 3;
            }
            var total = (int)(1500 * groupSize);
            var gst   = (int)(total * 0.05);

            myCharge.Amount   = (total + gst) * 100;
            myCharge.Currency = "cad";
            myCharge.Metadata = new Dictionary <string, string>()
            {
                { "CustomerId", customer.Id },
                { "CustomerEmail", model.EmailAddress }
            };

            // set this if you want to
            myCharge.Description = "ASP.NET Monsters Training";
            myCharge.Source      = new StripeSourceOptions {
                TokenId = model.StripeToken
            };

            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;

            var          chargeService = new StripeChargeService();
            StripeCharge stripeCharge  = chargeService.Create(myCharge);

            return(View());
        }