public async Task <string> MakePayment(string apiSecretKey, string currencyCode, double amount, string cardToken, string description, string memberName) { StripeClient client = new StripeClient(apiSecretKey); PaymentIntentService intentService = new PaymentIntentService(client); PaymentIntent intent = await intentService.CreateAsync(new PaymentIntentCreateOptions { Amount = (int)(amount * 100), Currency = currencyCode.ToLowerInvariant(), Description = $"{memberName}: {description}", ExtraParams = new Dictionary <string, object> { { "payment_method_data", new Dictionary <string, object> { { "type", "card" }, { "card", new Dictionary <string, object> { { "token", cardToken } } } } } } }); intent = await intentService.ConfirmAsync(intent.Id); return(intent.Id); }
public async Task <IActionResult> CreatePaymentIntent([FromBody] CreatePaymentIntentRequest req) { var options = new PaymentIntentCreateOptions { Amount = 1999, Currency = req.Currency, PaymentMethodTypes = new List <string> { req.PaymentMethodType, }, }; var service = new PaymentIntentService(this.client); try { var paymentIntent = await service.CreateAsync(options); return(Ok(new CreatePaymentIntentResponse { ClientSecret = paymentIntent.ClientSecret, })); } catch (StripeException e) { return(BadRequest(new { error = new { message = e.StripeError.Message } })); } catch (System.Exception) { return(BadRequest(new { error = new { message = "unknown failure: 500" } })); } }
public async Task <IActionResult> StripeSessionTest() { var userUid = "2222"; if (userUid == string.Empty) { return(Unauthorized()); } string sessionId = ""; try { var options = new PaymentIntentCreateOptions { Amount = 1099, Currency = "usd", Metadata = new Dictionary <string, string>() { { "integration_check", "accept_a_payment" }, } }; var service = new PaymentIntentService(); var paymentIntent = await service.CreateAsync(options).ConfigureAwait(false); sessionId = paymentIntent.ClientSecret; } catch (Exception ex) { return(BadRequest()); } return(Ok(sessionId)); }
public async Task <PaymentIntent> CreateChargeAsync(string accountId, string customerId, string paymentMethodId, string description, decimal amount, decimal applicationFeeAmount, Dictionary <string, string> metadata = null) { var accountService = new AccountService(); var account = await accountService.GetAsync(accountId); var options = new PaymentIntentCreateOptions { Description = description, Amount = (long)(amount * 100), ApplicationFeeAmount = (long)(applicationFeeAmount * 100), Currency = "usd", PaymentMethodTypes = new List <string> { "card" }, Customer = customerId, PaymentMethod = paymentMethodId, Confirm = true, OffSession = true, Metadata = metadata, TransferData = new PaymentIntentTransferDataOptions() { Destination = accountId } }; if (account.Capabilities.CardPayments == "active") { options.OnBehalfOf = accountId; } var service = new PaymentIntentService(); return(await service.CreateAsync(options)); }
private async Task <ActionResult> PayWithStripeElements([FromBody] AppZeroAPI.Entities.CustomerOrder order) { // Read Stripe API key from config StripeConfiguration.ApiKey = StripeOptions.SecretKey; var paymentIntentCreateOptions = new PaymentIntentCreateOptions { Customer = StripeCustomer(order).Id, Amount = Convert.ToInt32(order.total_payable), Currency = "usd", PaymentMethodTypes = new List <string> { "card" }, Description = "Bestilling fra Losvik kommune", ReceiptEmail = order.customer.email, StatementDescriptor = "Losvik kommune", Metadata = new Dictionary <String, String>() { { "OrderId", order.order_id.ToString() } } }; var service = new PaymentIntentService(); var intent = await service.CreateAsync(paymentIntentCreateOptions); return(Ok(intent)); }
public async Task <PaymentIntent> CreatePaymentIntentAsync(string customerId, string accountId, string description, decimal amount, decimal applicationFeeAmount, string paymentMethodId) { var options = new PaymentIntentCreateOptions { Description = description, Amount = (long)(amount * 100), ApplicationFeeAmount = (long)(applicationFeeAmount * 100), TransferData = new PaymentIntentTransferDataOptions { Destination = accountId, }, Currency = "usd", PaymentMethodTypes = new List <string> { "card" }, Customer = customerId, PaymentMethod = paymentMethodId, Confirm = true, OffSession = true }; var service = new PaymentIntentService(); return(await service.CreateAsync(options)); }
/// <summary> /// Creates a payment intent and returns the payment intent /// </summary> /// <param name="amount_cents"></param> /// <returns></returns> public async Task <PaymentResult> CreatePaymentIntentAsync(string paymentMethodId, int amount_cents = 300) { var paymentIntentService = new PaymentIntentService(); var options = new PaymentIntentCreateOptions() { Amount = amount_cents, Confirm = true, Currency = "usd", CaptureMethod = "manual", ConfirmationMethod = "manual", PaymentMethodId = paymentMethodId, StatementDescriptor = "NowLeave.com" }; //setup the request options var intent = await paymentIntentService.CreateAsync(options, GetRequestOptions()); var requiresClientAction = intent.Status == "requires_action" && intent.NextAction.Type == "use_stripe_sdk"; var res = new PaymentResult() { Success = requiresClientAction == true || intent.Status == "requires_capture" || intent.Status == "succeeded", ClientSecret = intent.ClientSecret, PaymentIntentId = intent.Id, RequiresClientAction = requiresClientAction }; return(res); }
public override async Task <CreateStripePaymentIntentResponse> CreateStripePaymentIntent( CreateStripePaymentIntentRequest request, ServerCallContext context ) { var httpContext = context.GetHttpContext(); var paymentIntentService = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { PaymentMethod = request.PaymentMethodId, Customer = httpContext.GetStripeCustomerId(), ReceiptEmail = httpContext.GetEmail(), Amount = request.Transaction.Currency.ToCents(), Currency = Options.Invoice.Currency, Metadata = new Dictionary <string, string> { ["UserId"] = httpContext.GetUserId(), ["TransactionId"] = request.Transaction.Id } }; var paymentIntent = await paymentIntentService.CreateAsync(options); var response = new CreateStripePaymentIntentResponse { ClientSecret = paymentIntent.ClientSecret }; var message = $"A new payment {paymentIntent.Id} for {paymentIntent.Amount} {paymentIntent.Currency} was created"; return(context.Ok(response, message)); }
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)); }
public async Task <bool> CreateOrUpdatePaymentIntent(string userId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var carts = await _cartItemService.GetAll(userId); if (carts.Count == 0) { return(false); } var service = new PaymentIntentService(); int amount = 0; foreach (var item in carts) { amount += item.Quantity + item.ProductDetail.Product.Price; } var options = new PaymentIntentCreateOptions { Amount = amount * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; await service.CreateAsync(options); return(true); }
public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _basketRepository.GetBasketAsync(basketId); if (basket == null) { return(null); } var shippingPrice = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>().GetByIdAsync((int)basket.DeliveryMethodId); shippingPrice = deliveryMethod.Price; } foreach (var item in basket.Items) { var productItem = await _unitOfWork.Repository <Core.Entities.Product>().GetByIdAsync(item.Id); if (item.Price != productItem.Price) { item.Price = productItem.Price; } } var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100 }; await service.UpdateAsync(basket.PaymentIntentId, options); } await _basketRepository.UpdateBasketAsync(basket); return(basket); }
public async Task <CustomerBasket> CreateOrUpdatePayementIntent(string basketId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _bsktRepo.GetBasketAsync(basketId); if (basket == null) { return(null); } var shippingCharge = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _uow.Repository <DeliveryMethod>().GetByIdAsync(basket.DeliveryMethodId.Value); if (deliveryMethod != null) { shippingCharge = deliveryMethod.Price; } } foreach (var item in basket.Items) { var product = await _uow.Repository <Core.Entities.Product>().GetByIdAsync(item.Id); item.Price = product.Price; } var paymentIntentService = new PaymentIntentService(); if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)((basket.Items.Sum(x => x.Price * x.Quantity) + shippingCharge)) * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; var payment = await paymentIntentService.CreateAsync(options); basket.ClientSecret = payment.ClientSecret; basket.PaymentIntentId = payment.Id; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)((basket.Items.Sum(x => x.Price * x.Quantity) + shippingCharge)) * 100 }; await paymentIntentService.UpdateAsync(basket.PaymentIntentId, options); } await _bsktRepo.CreateOrUpdateBasketAsync(basket); return(basket); }
public async Task <IActionResult> Pay(PaymentIntentCreateRequest request) { var paymentIntents = new PaymentIntentService(); var paymentIntent = await paymentIntents.CreateAsync(new PaymentIntentCreateOptions { Amount = this.CalculateOrderAmount(request.Items), Currency = "usd", }); return(this.Json(new { clientSecret = paymentIntent.ClientSecret })); }
public async Task <IActionResult> Create() { var user = await this.userManager.GetUserAsync(this.User); var userNames = user.FirstName + ' ' + user.LastName; var customerService = new CustomerService(); var customers = await customerService.ListAsync(); var customer = customers.FirstOrDefault(x => x.Name == userNames); if (customer == null) { var customerOptions = new CustomerCreateOptions { Name = userNames, Email = user.Email, Phone = user.PhoneNumber, Metadata = new Dictionary <string, string> { ["HotelId"] = user.HotelId.ToString(), ["UserId"] = user.Id, ["BirthDate"] = user.BirthDate.ToShortDateString(), ["Username"] = user.UserName, }, }; customer = await customerService.CreateAsync(customerOptions); } var priceService = new PriceService(); var price = await priceService.GetAsync("price_1IP1xzLxakYJAQmTh3ple3eB"); var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = price.UnitAmount, Currency = "bgn", SetupFutureUsage = "on_session", Customer = customer.Id, }; var paymentIntent = await service.CreateAsync(options); var model = new PaymentInputModel { Token = paymentIntent.ClientSecret, PaymentId = paymentIntent.Id, StripePublishableKey = this.configuration["Stripe:PublishableKey"], }; return(this.View(model)); }
public async Task <CustomerCart> CreateOrUpdatePaymentIntent(string customerId) { StripeConfiguration.ApiKey = SecretKey;// _config["StripeSettings:SecretKey"]; var basket = await customerService.GetCartDetailsForCustomer(customerId); if (basket == null) { return(null); } var shippingPrice = 0m; if (basket.deliveryMethodId.HasValue) { //var deliveryMethod = await unitOfWork..Repository<DeliveryMethod>() // .GetByIdAsync((int)basket.DeliveryMethodId); // shippingPrice = deliveryMethod.Price; } var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.paymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.cartItems.Sum(i => i.qty * (i.total_payable * 100)) + (long)shippingPrice * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; intent = await service.CreateAsync(options); basket.paymentIntentId = intent.Id; basket.client_secret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.cartItems.Sum(i => i.qty * (i.total_payable * 100)) + (long)shippingPrice * 100, }; await service.UpdateAsync(basket.paymentIntentId, options); } await customerService.UpdateCart(basket); return(basket); }
public async Task <CustomerCart> CreateOrUpdatePaymentIntent(string basketId) { try { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; CustomerCart basket = await _basketRepository.GetByIdAsync(basketId); if (basket == null) { return(null); } var shippingPrice = 0m; var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, }; await service.UpdateAsync(basket.PaymentIntentId, options); } _basketRepository.Update(basket); return(basket); } catch (Exception ex) { throw; } }
public async Task <PaymentIntentDao> CreatePaymentIntent(string paymentCustomerId, long amount, CancellationToken cancellationToken) { Guard.Argument(paymentCustomerId, nameof(paymentCustomerId)).NotNull().NotEmpty().NotWhiteSpace(); try { var options = new PaymentIntentCreateOptions { Customer = paymentCustomerId, Amount = amount, Currency = "gbp", SetupFutureUsage = "on_session" }; var paymentIntent = await _paymentIntentService.CreateAsync(options : options, cancellationToken : cancellationToken); return(paymentIntent.ToPaymentIntentDao()); } catch (Exception ex) { throw new PaymentServiceException($"Unable to create payment intent for customer '{paymentCustomerId}'", ex); } }
public async Task <PaymentIntent> CreatePaymentIntent(string stripeAccountId, decimal amount, string email, Dictionary <string, string> metadata) { var paymentIntentService = new PaymentIntentService(); var paymentIntent = await paymentIntentService.CreateAsync(new PaymentIntentCreateOptions { Amount = (int)(amount * 100), Currency = "usd", ApplicationFeeAmount = (int)Math.Ceiling(amount * 10m), Metadata = metadata, ReceiptEmail = email }, GetRequestOptions(stripeAccountId)); return(paymentIntent); }
private async Task ProcessNewPaymentIntent(CustomerBasket basket, decimal shippingPrice) { var service = new PaymentIntentService(); PaymentIntent intent; var options = new PaymentIntentCreateOptions { Amount = GetLongBasketAmount(basket, shippingPrice), Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; }
public async Task <IActionResult> Pay([FromBody] PayDto dto) { var paymentIntentService = new PaymentIntentService(); PaymentIntent paymentIntent = null; try { if (dto.ConfirmPaymentRequest.PaymentMethodId != null) { var createOptions = new PaymentIntentCreateOptions { PaymentMethod = dto.ConfirmPaymentRequest.PaymentMethodId, Amount = (int)(dto.Amount * 100), Currency = "usd", ConfirmationMethod = "manual", Confirm = true }; if (!string.IsNullOrEmpty(dto.ConfirmPaymentRequest.CustomerId)) { createOptions.Customer = dto.ConfirmPaymentRequest.CustomerId; } paymentIntent = await paymentIntentService.CreateAsync(createOptions); } if (dto.ConfirmPaymentRequest.PaymentIntentId != null) { var confirmOptions = new PaymentIntentConfirmOptions { }; paymentIntent = await paymentIntentService.ConfirmAsync( dto.ConfirmPaymentRequest.PaymentIntentId, confirmOptions ); } } catch (StripeException e) { return(BadRequest(new { error = e.StripeError.Message })); } return(GeneratePaymentResponse(paymentIntent)); }
public async Task <PendingBooking> AddPaymentIntentToPendingBooking(PendingBooking pendingBooking, decimal amtForStripe) { StripeConfiguration.ApiKey = _config["Stripe:SecretKey"]; var paymentIntentService = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(pendingBooking.StripePaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)amtForStripe * 100, Currency = "gbp", PaymentMethodTypes = new List <string> { "card" } }; intent = await paymentIntentService.CreateAsync(options); pendingBooking.StripePaymentIntentId = intent.Id; pendingBooking.StripeClientSecret = intent.ClientSecret; pendingBooking.StripeAmount = (int)intent.Amount / 100; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)amtForStripe * 100 }; intent = await paymentIntentService.UpdateAsync(pendingBooking.StripePaymentIntentId, options); pendingBooking.StripeAmount = (int)intent.Amount / 100; } // commit amended pendingBookings entity await _repo.Commit(); return(pendingBooking); }
public async Task <IActionResult> OnGet( [FromServices] IOptionsMonitor <StripeSettings> optionsMonitor, [FromServices] GetCart getCart, [FromServices] PaymentIntentService paymentIntentService) { var userId = User.GetUserId(); StripeConfiguration.ApiKey = optionsMonitor.CurrentValue.SecretKey; var cart = await getCart.ByUserId(userId); if (cart == null || cart.Products.Count <= 0) { return(RedirectToPage("/Index")); } var paymentIntent = await paymentIntentService.CreateAsync(new PaymentIntentCreateOptions { CaptureMethod = "manual", Amount = cart.Total(), Currency = "gbp", ReceiptEmail = cart.Email, Shipping = new ChargeShippingOptions { Name = cart.Name, Phone = cart.Phone, Address = new AddressOptions { Line1 = cart.Address1, Line2 = cart.Address2, City = cart.City, Country = cart.Country, PostalCode = cart.PostCode, State = cart.State, }, }, }); ClientSecret = paymentIntent.ClientSecret; return(Page()); }
public async Task <string> CreateSessionTest() { // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys var options = new PaymentIntentCreateOptions { Amount = 1099, Currency = "usd", // Verify your integration in this guide by including this parameter Metadata = new Dictionary <string, string>() { { "integration_check", "accept_a_payment" }, } }; var service = new PaymentIntentService(); var paymentIntent = await service.CreateAsync(options).ConfigureAwait(false); return(paymentIntent.ClientSecret); }
/// <summary> /// Create a Stripe Payment Intent Auth /// </summary> /// <param name="logguedUser"></param> /// <param name="productId"></param> /// <returns></returns> public async Task <string> PaymentIntentAsync(int logguedUser, int productId, bool setupFutureUsage) { var user = await _userService.GetUserAsync(logguedUser); var product = await _productService.GetProductAsync(productId); var amount = GetProductPriceInteger(product); if (amount <= 0) { throw new NotAllowedException("Price must to be great than 0"); } if (string.IsNullOrEmpty(user.StripeCustomerId)) { await CreateStripeCustomerAsync(user); } var options = new PaymentIntentCreateOptions { Amount = amount, Currency = "eur", Customer = user.StripeCustomerId, Description = "Buying product " + product.Name + ". {ID: " + product.Id + "}" }; if (setupFutureUsage) { options.SetupFutureUsage = "on_session"; } var service = new PaymentIntentService(); var paymentIntent = await service.CreateAsync(options); var statusInfo = "Stripe Payment Intent Requested"; await CreateOrderAsync(paymentIntent.ClientSecret, user, product, amount, statusInfo); return(paymentIntent.ClientSecret); }
public async Task <OrderPaymentIntent> CreatePaymentIntentAsync(Order_Receipt order) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = Convert.ToInt64(order.TotalPrice) * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; var confirmOptions = new PaymentIntentConfirmOptions { PaymentMethod = "pm_card_visa" }; var intent = await service.CreateAsync(options); order.PaymentIntent = new OrderPaymentIntent { PaymentIndentId = intent.Id, ClientSecret = intent.ClientSecret }; service.Confirm( intent.Id, confirmOptions ); repository.Update(order); return(order.PaymentIntent); }
public async Task <PaymentIntentResult> CreatePaymentIntent(int amount, string email) { StripeConfiguration.ApiKey = _config.Secretkey; var service = new PaymentIntentService(); var options = new PaymentIntentCreateOptions { Amount = amount, Currency = "gbp", ReceiptEmail = email, Description = "Amatis Training", }; PaymentIntent intent = await service.CreateAsync(options); //this is what we want to pass back to the client for making the payment PaymentIntentResult result = new PaymentIntentResult() { ClientSecret = intent.ClientSecret, PublishableKey = _config.PublishableKey, PaymentIntentId = intent.Id }; return(result); }
public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _basketRepository.GetBasketAsync(basketId); if (basket == null) { return(null); } var shippingPrice = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _storeRepo.Repository <DeliveryMethod>().GetByIdAsync(basket.DeliveryMethodId.Value); shippingPrice = deliveryMethod.Price; } foreach (var item in basket.Items) { var productItem = await _storeRepo.Repository <Product>().GetByIdAsync(item.Id); if (item.Price != productItem.Price) { item.Price = productItem.Price; } } var paymentIntentService = new PaymentIntentService(); long amountAsLong = (long)basket.Items.Sum(x => (x.Price * 100) * x.Quantity) + (long)(shippingPrice * 100); if (string.IsNullOrWhiteSpace(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = amountAsLong, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; PaymentIntent intent = await paymentIntentService.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = amountAsLong }; await paymentIntentService.UpdateAsync(basket.PaymentIntentId, options); } await _basketRepository.UpdateBasketAsync(basket); return(basket); }
public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _basketRepository.GetBasketAsync(basketId); #region 21.271.4 Checking to see if there is a basket to avoid the exeption -> PaymentController if (basket == null) { return(null); } #endregion #region 21.260.2 Rest of the method -> PaymentsController //getting the shipping option var shippingPrice = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>() .GetByIdAsync((int)basket.DeliveryMethodId); shippingPrice = deliveryMethod.Price; } // checking if the prices in basket are accurate foreach (var item in basket.Items) { var productItem = await _unitOfWork.Repository <Product>().GetByIdAsync(item.Id); if (item.Price != productItem.Price) { item.Price = productItem.Price; } } // hoking into stripe var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, Currency = "usd", PaymentMethodTypes = new List <string> { "card" } }; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100 }; await service.UpdateAsync(basket.PaymentIntentId, options); } await _basketRepository.UpdateBasketAsync(basket); return(basket); #endregion }
public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _basketRepository.GetBasketAsync(basketId); if (basket == null) { return(null); } var shippingPrice = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>() .GetByIdAsync((int)basket.DeliveryMethodId); shippingPrice = deliveryMethod.Price; } foreach (var item in basket.Items) { var productItem = await _unitOfWork.Repository <Product>() .GetByIdAsync(item.Id); if (item.Price != productItem.Price) { item.Price = productItem.Price; } } var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, Currency = "inr", PaymentMethodTypes = new List <string>() { "card" } }; options.Shipping = new ChargeShippingOptions { Name = "mrinal jha", Address = new AddressOptions { Line1 = "hindon vihar noida", PostalCode = "201305", City = "Noida", State = "UP", Country = "INDIA", } }; options.Description = "Mrinal soft development services."; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100 }; await service.UpdateAsync(basket.PaymentIntentId, options); } await _basketRepository.UpdateBasketAsync(basket); return(basket); }
public async Task <CustomerBasket> CreateOrUpdatePaymentIntent(string basketId, string email) { StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"]; var basket = await _basketRepository.GetBasketAsync(basketId); if (basket == null) { return(null); } var shippingPrice = 0m; if (basket.DeliveryMethodId.HasValue) { var deliveryMethod = await _deliveryRepo.GetDeliveryMethod((int)basket.DeliveryMethodId); shippingPrice = deliveryMethod.Price; } foreach (var item in basket.Items) { var productItem = await _productRepo.GetProductByIdAsync(item.Id); if (item.Price != productItem.Price) { item.Price = productItem.Price; } } var service = new PaymentIntentService(); PaymentIntent intent; if (string.IsNullOrEmpty(basket.PaymentIntentId)) { var options = new PaymentIntentCreateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, Currency = "eur", PaymentMethodTypes = new List <string> { "card" }, Customer = "cus_J63t1pVjvPzKF8", PaymentMethod = "pm_card_nl", Confirm = true, ReceiptEmail = email, }; intent = await service.CreateAsync(options); basket.PaymentIntentId = intent.Id; basket.ClientSecret = intent.ClientSecret; } else { var options = new PaymentIntentUpdateOptions { Amount = (long)basket.Items.Sum(i => i.Quantity * (i.Price * 100)) + (long)shippingPrice * 100, }; await service.UpdateAsync(basket.PaymentIntentId, options); } await _basketRepository.UpdateBasketAsync(basket); return(basket); }