Beispiel #1
0
        public ActionResult PayOrder(long idOrder)
        {
            OrderToPayDTO orderToPayDTO = Gateway.GetOrderToPayById(idOrder);

            PlaceToPay APIPlaceToPay = new PlaceToPay();

            APIPlaceToPay.Pay(orderToPayDTO);

            return(RedirectToAction(ActionsOrder.Index.ToString()));
        }
        public static OrderToPayDTO GetOrderToPayById(long idOrder)
        {
            try
            {
                Orders        order;
                OrderToPayDTO orderToPayDTO;
                using (StoreXYEntities db = new StoreXYEntities())
                {
                    order         = db.Orders.FirstOrDefault(x => x.id == idOrder);
                    orderToPayDTO = new OrderToPayDTO(order);
                }

                return(orderToPayDTO);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
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());
            }
        }