Esempio n. 1
0
        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 }));
            }
        }
Esempio n. 2
0
        public void Redirection_Response_Without_Status()
        {
            var carrierResponse = new RedirectResponse(new JObject {
                { "requestId", new Random().Next(0, 100000) },
                { "processUrl", "http://localhost/payment/process" },
            });

            Assert.False(carrierResponse.IsSuccessful());
        }
Esempio n. 3
0
        public void Redirection_Response_With_Status()
        {
            var carrierResponse = new RedirectResponse(new JObject {
                { "requestId", new Random().Next(0, 100000) },
                { "processUrl", "http://localhost/payment/process" },
                { "status", new JObject {
                      { "status", "OK" }, { "reason", 2 }, { "message", "Aprobada" }, { "date", "2019-03-10T12:36:36-05:00" }
                  } }
            });

            Assert.True(carrierResponse.IsSuccessful());
        }
Esempio n. 4
0
        public void Pay(OrderToPayDTO orderToPayDTO)
        {
            Gateway gateway = new PlacetoPay.Integrations.Library.CSharp.PlacetoPay("6dd490faf9cb87a9862245da41170ff2",
                                                                                    "024h1IlD",
                                                                                    new Uri("https://test.placetopay.com/redirection/"),
                                                                                    Gateway.TP_REST);


            Amount  amount        = new Amount(orderToPayDTO.Price);
            Payment payment       = new Payment("Pay_" + orderToPayDTO.Id, "", amount);
            var     host          = Dns.GetHostEntry(Dns.GetHostName());
            string  IPAddressUsed = string.Empty;

            foreach (var ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    IPAddressUsed = ip.ToString();
                }
            }
            RedirectRequest request = new RedirectRequest(payment,
                                                          "https://localhost:44369/Order",
                                                          IPAddressUsed,
                                                          "Chrome",
                                                          DateTime.Now.AddDays(1).ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'"));

            RedirectResponse response = gateway.Request(request);

            if (response.IsSuccessful())
            {
                BusinessModel.Gateway.UpdateOrder(orderToPayDTO.Id, OrderStatusEnum.PAYED.ToString());
            }
            else if (response.Status.status == "ERROR")
            {
                BusinessModel.Gateway.UpdateOrder(orderToPayDTO.Id, OrderStatusEnum.REJECTED.ToString());
            }
        }