Exemplo n.º 1
0
        private async Task <ActionResult> PayWithStripeElements(Sjop.Models.Order order)
        {
            // Read Stripe API key from config
            StripeConfiguration.ApiKey = _stripeSettings.SecretKey;

            var paymentIntentCreateOptions = new PaymentIntentCreateOptions
            {
                Customer           = StripeCustomer(order).Id,
                Amount             = Convert.ToInt32(order.OrderTotalprice * 100),
                Currency           = "nok",
                PaymentMethodTypes = new List <string> {
                    "card"
                },
                Description         = "Bestilling fra Losvik kommune",
                ReceiptEmail        = order.Customer.Email,
                StatementDescriptor = "Losvik kommune",
                Metadata            = new Dictionary <String, String>()
                {
                    { "OrderId", order.Id.ToString() }
                }
            };

            var service = new PaymentIntentService();
            var intent  = await service.CreateAsync(paymentIntentCreateOptions);

            return(Ok(intent));
        }
Exemplo n.º 2
0
        private Customer StripeCustomer(Sjop.Models.Order order)
        {
            var options = new CustomerCreateOptions
            {
                Name             = order.Customer.Name,
                Email            = order.Customer.Email,
                Phone            = order.Customer.Phone,
                PreferredLocales = new List <string> {
                    "nb", "en"
                }
            };

            var service  = new CustomerService();
            var customer = service.Create(options);

            return(customer);
        }
Exemplo n.º 3
0
        private async Task <ActionResult> PayWithStripeCheckout(Sjop.Models.Order order)
        {
            // Read Stripe API key from config
            StripeConfiguration.ApiKey = _stripeSettings.SecretKey;

            // Add orderlines to Checkout session
            var lines = new List <SessionLineItemOptions>();

            foreach (var ol in order.OrderLines)
            {
                _logger.LogInformation($"linjepris: {ol.TotalPrice}");
                var newline = new SessionLineItemOptions
                {
                    Name        = ol.ProductName,
                    Description = ol.ProductDescription,
                    Amount      = Convert.ToInt64(ol.TotalPrice * 100),
                    Currency    = "nok",
                    Quantity    = ol.Quantity
                };
                lines.Add(newline);
            }
            var options = new SessionCreateOptions
            {
                ClientReferenceId  = order.Id.ToString(),
                CustomerEmail      = order.Customer.Email,
                Locale             = "nb",
                PaymentMethodTypes = new List <string> {
                    "card",
                },
                LineItems  = lines,
                SuccessUrl = _site.BaseUrl + "/PaymentSuccess?session_id={CHECKOUT_SESSION_ID}",
                CancelUrl  = _site.BaseUrl + "/PaymentFailed",
            };

            var     service = new SessionService();
            Session session = await service.CreateAsync(options);

            order.PaymentProviderSessionId = session.Id;
            _context.Update(order);
            await _context.SaveChangesAsync();

            return(Ok(session));
        }
Exemplo n.º 4
0
        private Task <ActionResult> PayWithVipps(Sjop.Models.Order order)
        {
            throw new NotImplementedException();

            // return BadRequest();
        }
Exemplo n.º 5
0
 private Task <ActionResult> PayWithStripeBilling(Sjop.Models.Order order)
 {
     throw new NotImplementedException();
 }