/
den3011den
/
Tangy
Обзор
Документация
Войти
/
den3011den
/
Tangy
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
TangyWeb_API/Controllers/StripePaymentController.cs
72 строки
2 KB
Денис Богомолов
Отиена заказа
15 апр 2022, 13:08
15 апр 2022, 13:08
5ca873f
Код
Авторство
О чём код?
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Stripe.Checkout; using Tangy_Models; namespace TangyWeb_API.Controllers { [Route("api/[controller]/[action]")] public class StripePaymentController : Controller { private readonly IConfiguration _configuration; public StripePaymentController(IConfiguration configuration) { _configuration = configuration; } [HttpPost] [Authorize] [ActionName("Create")] public async Task<IActionResult> Create([FromBody] StripePaymentDTO paymentDTO) { try { var domain = _configuration.GetValue<string>("Tangy_Client_URL"); var options = new SessionCreateOptions { SuccessUrl = domain + paymentDTO.SuccessUrl, CancelUrl = domain + paymentDTO.CancelUrl, LineItems = new List<SessionLineItemOptions>(), Mode = "payment", PaymentMethodTypes = new List<string> { "card" } }; foreach (var item in paymentDTO.Order.OrderDetails) { var sessionLineItem = new SessionLineItemOptions { PriceData = new SessionLineItemPriceDataOptions { UnitAmount = (long)(item.Price * 100), // 20.00 -> 2000 Currency = "rub", ProductData = new SessionLineItemPriceDataProductDataOptions { Name = item.Product.Name } }, Quantity = item.Count }; options.LineItems.Add(sessionLineItem); } var service = new SessionService(); Session session = service.Create(options); return Ok(new SuccessModelDTO() { Data = session.Id+";"+session.PaymentIntentId }); } catch (Exception ex) { return BadRequest(new ErrorModelDTO() { ErrorMessage = ex.Message }); } } } }