Beispiel #1
0
        public async Task <IAppUser> CreateCustomer(Customer model, CancellationToken cancellationToken)
        {
            var sCustomer = _stripe.CreateCustomer();

            //TODO: generate customer secret
            var customer = new Customer
            {
                Name  = model.Name,
                Email = model.Email,
                //TODO: hash w customer.secret
                Password         = SecurePasswordHasher.Hash(model.Password),
                Phone            = model.Phone,
                StripeCustomerID = sCustomer.Id
            };

            _context.Customers.Add(customer);
            await _context.SaveChangesAsync(cancellationToken);

            return(VerifyCustomer(customer, model.Password));
        }
Beispiel #2
0
        public void ProcessPayment(PaymentModel model)
        {
            var user    = currentUserService.CurrentUser();
            var userDto = Context.Users.FirstOrDefault(x => x.Id == user.Id);
            var plan    = stripeService.GetPlans().FirstOrDefault(x => x.Id == model.PlanId);


            if (userDto.StripeId == null)
            {
                var customer = stripeService.CreateCustomer(model.Token.email, model.Token.id);
                userDto.StripeId = customer.Id;
                Context.SaveChanges();
            }
            else
            {
                var currentSub = stripeService.CurrentSubForCustomer(userDto.StripeId);
                if (currentSub != null)
                {
                    stripeService.CancelSub(currentSub.Id);
                }
            }
            stripeService.CreateSubscription(plan.Id, userDto.StripeId);
        }