Exemplo n.º 1
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service  = new Stripe.CustomerService();
            var customer = service.Create(new Stripe.CustomerCreateOptions
            {
                Email = model.Email
            }
                                          );

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email, StripeCustomerId = customer.Id
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public Stripe.Customer CreateCustomer()
        {
            var options = new Stripe.CustomerCreateOptions {
            };
            var service = new Stripe.CustomerService();

            return(service.Create(options));
        }
Exemplo n.º 3
0
 public StripeAdapter()
 {
     _customerService      = new Stripe.CustomerService();
     _subscriptionService  = new Stripe.SubscriptionService();
     _invoiceService       = new Stripe.InvoiceService();
     _paymentMethodService = new Stripe.PaymentMethodService();
     _taxRateService       = new Stripe.TaxRateService();
     _taxIdService         = new Stripe.TaxIdService();
     _chargeService        = new Stripe.ChargeService();
     _refundService        = new Stripe.RefundService();
     _cardService          = new Stripe.CardService();
     _bankAccountService   = new Stripe.BankAccountService();
 }
Exemplo n.º 4
0
        public async Task IapCheckAsync(User user, PaymentMethodType paymentMethodType)
        {
            if (paymentMethodType != PaymentMethodType.AppleInApp)
            {
                throw new BadRequestException("Payment method not supported for in-app purchases.");
            }

            if (user.Premium)
            {
                throw new BadRequestException("Already a premium user.");
            }

            if (!string.IsNullOrWhiteSpace(user.GatewayCustomerId))
            {
                var customerService = new Stripe.CustomerService();
                var customer        = await customerService.GetAsync(user.GatewayCustomerId);

                if (customer != null && customer.Balance != 0)
                {
                    throw new BadRequestException("Customer balance cannot exist when using in-app purchases.");
                }
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Payment(string stripeEmail, string stripeToken)
        {
            var customers = new Stripe.CustomerService();
            var charges   = new Stripe.ChargeService();
            var user      = _userManager.GetUserAsync(User).Result;

            int.TryParse(HttpContext.Request.Cookies["counter"], out int counter);
            var orderProducts = await GetOrderProductsList(counter);

            decimal price = 0;

            foreach (var item in orderProducts)
            {
                var stock = await _context.Stock.FirstAsync(x => x.Id == item.StockId);

                stock.Qty -= item.Qty;
                for (int i = 0; i < item.Qty; i++)
                {
                    price += item.Product.Price;
                }

                if (stock.Qty == 0)
                {
                    stock.IsLastElementOrdered = true;
                }

                _context.Update(stock);
                await _context.OrderProducts.AddAsync(item);
            }

            var customer = customers.Create(new Stripe.CustomerCreateOptions
            {
                Email   = stripeEmail,
                Source  = stripeToken,
                Name    = user.FirstName + " " + user.LastName,
                Address = new Stripe.AddressOptions {
                    City = user.City, Country = "Poland", PostalCode = user.PostCode, Line1 = user.Address1, Line2 = user.Address2
                },
                Phone = user.PhoneNumber,
            });

            var charge = charges.Create(new Stripe.ChargeCreateOptions
            {
                Amount       = Convert.ToInt64(price * 100),
                Description  = "Sample Charge",
                Currency     = "PLN",
                Customer     = customer.Id,
                ReceiptEmail = stripeEmail,
            });

            System.Diagnostics.Debug.WriteLine($"Zamówienie użytkownika {user.UserName} o id = {user.   Id}");


            //można to zrobić mapperem ale trzeba go dokładnie skonfigurować
            var order = new Order
            {
                FirstName     = user.FirstName,
                LastName      = user.LastName,
                Email         = user.Email,
                Address1      = user.Address1,
                Address2      = user.Address2,
                City          = user.City,
                PostCode      = user.PostCode,
                OrderProducts = orderProducts,
                OrderDate     = DateTime.Now,
                UserId        = user.Id,
                ChargeId      = charge.Id
            };

            await _context.AddAsync(order);

            // czyszczenie koszyka
            HttpContext.Response.Cookies.Delete("counter");

            // todo dodanie zamówienia do tabeli orders i przypisywać je danemu użytkownikowi

            await _context.SaveChangesAsync();

            System.Diagnostics.Debug.WriteLine("Poprawne zamowienie");

            return(RedirectToAction("OrdersHistory", "Account"));
        }