public async Task <IActionResult> Payment(int idOrden) { var order = await _ordersService.GetOrder(idOrden); if (order == null) { return(NotFound()); } Gateway gateway = _ordersService.GetGateway(); Person person = new Person( document: order.CustomerDocument, documentType: "CC", name: order.CustomerName, surname: order.CustomerName.Replace(" ", ""), email: order.CustomerEmail, mobile: order.CustomerMobile ); Amount amount = new Amount(Convert.ToDouble(order.ValorOrder), currency); PlacetoPay.Integrations.Library.CSharp.Entities.Payment payment = new PlacetoPay.Integrations.Library.CSharp.Entities.Payment($"TEST_{DateTime.Now:yyyyMMdd_hhmmss}_{order.Id}", $"Pago básico de prueba orden {order.Id} ", amount, false, person); RedirectRequest request = new RedirectRequest(payment, urlLocalhostDetails + order.Id.ToString(), ipAddress, "PlacetoPay Sandbox", (order.CreatedAt.AddMinutes(60)).ToString(formatDate), person, person); RedirectResponse response = gateway.Request(request); if (response.IsSuccessful()) { Models.Payment pago = new Models.Payment() { OrderId = order.Id, Fecha = Convert.ToDateTime(response.Status.Date), RequestId = Convert.ToInt32(response.RequestId), UrlPago = response.ProcessUrl, Status = response.Status.status, Reason = response.Status.Reason, Message = response.Status.Message }; if (await _paymentsService.CreatePayment(pago) == 0) { // NotFound Response Status 404. return(NotFound()); } return(RedirectToAction("Payment", "Orders", new { idOrden = order.Id, urlPago = response.ProcessUrl })); } else { return(RedirectToAction("Details", "Orders", new { id = order.Id, message = response.Status.Message })); } }
public async Task <ActionResult <Payment> > PostPayment(Payment payment) { Payment paymentResult = await paymentsService.CreatePayment(payment); if (paymentResult is null) { return(BadRequest()); } //Not good in practice just to show differences between created payment response and get payment response return(CreatedAtAction(nameof(GetPaymentDetails), new { id = paymentResult.Id }, paymentResult)); }
public Task <CreatePaymentResponse> CreatePayment( [FromBody] CreatePaymentRequest request) { return(_paymentsService.CreatePayment(request)); }