public void Pruebas(string id)
        {
            Gateway gateway = CrearAutenticacion();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            RedirectInformation response = gateway.Query("115420");
        }
        public ActionResult returnURL(int?id)
        {
            Transaccion         transaccion = db.Transaccions.Find(id);
            Gateway             gateway     = CrearAutenticacion();
            RedirectInformation response    = gateway.Query(transaccion.requestId);

            if (response.Payment != null)
            {
                transaccion.estadotransaccion = response.Payment[0].Status.status;
                if (transaccion.estadotransaccion == "APPROVED")
                {
                    transaccion.estadotransaccion = "Aprobada";
                }
                else if (transaccion.estadotransaccion == "REJECTED")
                {
                    transaccion.estadotransaccion = "Rechazada";
                }
                else
                {
                    transaccion.estadotransaccion = "Pendiente";
                }
                transaccion.motivotransaccion = response.Payment[0].Status.Message;
                transaccion.transaccionOk     = true;
                transaccion.fecha             = response.Status.Date;
                transaccion.Autorizacion      = response.Payment[0].Authorization;
                db.SaveChanges();
            }
            return(RedirectToAction("Mensajetrasaccion", new { id = transaccion.Id }));
        }
        /// <summary>
        /// Método ActualizarEstadoPedido.
        /// </summary>
        /// <returns>Task{Orders}</returns>
        private async Task <Orders> ActualizarEstadoPedido(Orders ordenPedido)
        {
            var estadoActualOrden = await this.tiendaVirtualRepositorio.ObtenerPorId <Entities.Models.Status>(ordenPedido.Status_Id);

            if (estadoActualOrden.Status_Description == ESTADO_OK_PAGO_APROVADO)
            {
                ordenPedido.OrderStatus = estadoActualOrden;
                return(await Task.FromResult(ordenPedido));
            }
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            var gateWay = new P2P(ConfigurationManager.AppSettings["Login_Ws_PlaceToPay"],
                                  ConfigurationManager.AppSettings["TranKey_Ws_PlaceToPay"],
                                  new Uri(ConfigurationManager.AppSettings["Url_Ws_PlaceToPay"]), Gateway.TP_REST);
            RedirectInformation response = gateWay.Query(ordenPedido.Request_Id);
            var estadoOrden = await this.tiendaVirtualRepositorio.ProcesarEstadoOrden(response.Status.status);

            ordenPedido.OrderStatus = estadoOrden;
            if (estadoOrden.Id != ordenPedido.Status_Id)
            {
                ordenPedido.Status_Id  = estadoOrden.Id;
                ordenPedido.Updated_At = DateTime.Now;
                this.tiendaVirtualRepositorio.Actualizar(ordenPedido);
            }
            return(await Task.FromResult(ordenPedido));
        }
Beispiel #4
0
        public void Should_Parse_A_Cancelled_Subscription_Rest_Response()
        {
            string result =
                "{" +
                "   \"requestId\":373," +
                "   \"status\":" +
                "   {" +
                "       \"status\":\"REJECTED\"," +
                "       \"reason\":\"?C\"," +
                "       \"message\":\"La petici\\u00f3n ha sido cancelada por el usuario\"," +
                "       \"date\":\"2017-05-17T16:13:52-05:00\"" +
                "   }," +
                "   \"request\":" +
                "   {" +
                "       \"locale\":\"es_CO\"," +
                "       \"payer\":null," +
                "       \"buyer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Ramiro\"," +
                "           \"surname\":\"Schultz\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"payment\":null," +
                "       \"subscription\":" +
                "       {" +
                "           \"reference\":\"TEST_20200517_211300\"," +
                "           \"description\":\"Molestiae expedita mollitia natus eligendi.\"" +
                "       }," +
                "       \"fields\":null," +
                "       \"returnUrl\":\"http:\\/\\/redirect.p2p.dev\\/client\"," +
                "       \"paymentMethod\":null," +
                "       \"cancelUrl\":null," +
                "       \"ipAddress\":\"127.0.0.1\"," +
                "       \"userAgent\":\"Mozilla\\/5.0 (X11; Linux x86_64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/57.0.2987.98 Safari\\/537.36\"," +
                "       \"expiration\":\"2017-05-18T21:13:00+00:00\"," +
                "       \"captureAddress\":false," +
                "       \"skipResult\":false," +
                "       \"noBuyerFill\":false" +
                "   }," +
                "   \"payment\":null," +
                "   \"subscription\":null" +
                "}";

            var information = new RedirectInformation(result);

            Assert.AreEqual(373, information.RequestId);
            Assert.AreEqual(Status.ST_REJECTED, information.Status.StatusText);

            Assert.True(information.IsSuccessful());
            Assert.False(information.IsApproved());

            Assert.AreEqual("TEST_20200517_211300", information.Request.Subscription.Reference);

            Assert.Null(information.Subscription);
        }
        public string[] statusRequest(string request_id)
        {
            string[]            responseProcess = new string[2];
            RedirectInformation responseR       = gateway.Query(request_id);

            responseProcess[0] = responseR.Status.status;
            responseProcess[1] = responseR.Status.Message;
            return(responseProcess);
        }
        public async Task <PaymentStateResponse> GetOrderDetails(int?id)
        {
            var order = await _ordersDao.GetOrder(id);

            PaymentStateResponse paymentStateResponse = new PaymentStateResponse();

            paymentStateResponse.IsRejected       = false;
            paymentStateResponse.Id               = order.Id;
            paymentStateResponse.CustomerName     = order.CustomerName;
            paymentStateResponse.CreatedAt        = order.CreatedAt;
            paymentStateResponse.CustomerDocument = order.CustomerDocument;
            paymentStateResponse.CustomerEmail    = order.CustomerEmail;
            paymentStateResponse.OrderDetails     = order.OrderDetails;
            paymentStateResponse.Payments         = order.Payments;
            paymentStateResponse.Status           = order.Status;
            paymentStateResponse.UpdatedAt        = order.UpdatedAt;
            paymentStateResponse.ValorOrder       = order.ValorOrder;

            if (order.Payments.Count > 0)
            {
                var pay = orderHasDeclinedPayments(order);

                if (pay != null)
                {
                    if (pay.Status != "PAYED")
                    {
                        Gateway             gateway  = GetGateway();
                        RedirectInformation response = gateway.Query(pay.RequestId.ToString());

                        if (response.IsSuccessful())
                        {
                            VerifyPaymentState(response, order, pay);
                            if (pay.Status == "REJECTED")
                            {
                                paymentStateResponse.IsRejected = true;
                            }
                        }
                        else
                        {
                            paymentStateResponse.Messagge = response.Status.Message;
                        }
                        await _paymentService.UpdatePayment(pay);

                        await _ordersDao.UpdateOrder(order);
                    }
                }
                else
                {
                    // Tiene pagos rechazados
                    paymentStateResponse.IsRejected = true;
                }
            }
            return(paymentStateResponse);
        }
        public void CrearCollect()
        {
            Token token = new Token("e35935ecac1c134e4de2240aff62d11e6196bf7d3a6594ad0dc54528fff67276", null, "7157190631451111");

            Instrument     instrument     = new Instrument(token);
            Person         buyer          = new Person("10000004", "CC", "Daniel", "Betancur", "*****@*****.**");
            Amount         amount         = new Amount(1000);
            Payment        payment        = new Payment("123456789", "TEST", amount);
            CollectRequest collectRequest = new CollectRequest(buyer,
                                                               payment,
                                                               instrument);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            Gateway             gateway = CrearAutenticacion();
            RedirectInformation collect = gateway.Collect(collectRequest);
        }
        public override RedirectInformation Collect(CollectRequest collectRequest)
        {
            try
            {
                string endpoint = "api/collect";
                string method   = "POST";
                var    response = this.MakeRequest(method, endpoint, collectRequest);

                return(JsonConvert.DeserializeObject <RedirectInformation>(response));
            }
            catch (Exception ex)
            {
                Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"));
                RedirectInformation redirectInformation = new RedirectInformation(0, status, null, null, null);

                return(redirectInformation);
            }
        }
        public override RedirectInformation Query(string requestId)
        {
            JToken responseJObject = null;

            try {
                string endpoint = "api/session/" + requestId;
                string method   = "POST";
                var    response = this.MakeRequest(method, endpoint);
                responseJObject = JObject.Parse(response);
                JToken fields = responseJObject["request"]["fields"];
                responseJObject["request"]["fields"] = null;

                RedirectInformation information = JsonConvert.DeserializeObject <RedirectInformation>(responseJObject.ToString());

                List <NameValuePair> items = new List <NameValuePair>();
                foreach (var field in fields)
                {
                    NameValuePair item = JsonConvert.DeserializeObject <NameValuePair>(field.ToString(), Serializer.JsonSerializer.Settings);
                    items.Add(item);
                }

                information.Request.Fields = new Fields(items);

                return(information);
            }
            catch (Exception ex)
            {
                Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"));

                if (responseJObject != null)
                {
                    status = new Status(responseJObject["status"]["status"].ToString(), responseJObject["status"]["reason"].ToString(), responseJObject["status"]["message"].ToString(), responseJObject["status"]["date"].ToString());
                }

                RedirectInformation redirectInformation = new RedirectInformation(0, status, null, null, null);

                return(redirectInformation);
            }
        }
        private void VerifyPaymentState(RedirectInformation response, Order order, Models.Payment pay)
        {
            switch (response.Status.status)
            {
            case "APPROVED":
                order.Status    = "PAYED";
                order.UpdatedAt = Convert.ToDateTime(response.Status.Date);
                pay.Status      = response.Status.status;
                pay.FechaUpdate = Convert.ToDateTime(response.Status.Date);
                break;

            case "PENDING":
                pay.Status      = response.Status.status;
                pay.FechaUpdate = Convert.ToDateTime(response.Status.Date);
                break;

            case "REJECTED":
                pay.Status      = response.Status.status;
                pay.FechaUpdate = Convert.ToDateTime(response.Status.Date);
                pay.Message     = response.Status.Message;
                break;
            }
        }
 public ProfileModel(RedirectInformation Info)
 {
     RedirectInfo = Info;
 }
Beispiel #12
0
        public void Should_Parse_A_Subscription_Rest_Response()
        {
            string result =
                "{" +
                "   \"requestId\":372," +
                "   \"status\":" +
                "   {" +
                "       \"status\":\"APPROVED\"," +
                "       \"reason\":\"00\"," +
                "       \"message\":\"La petici\\u00f3n ha sido aprobada exitosamente\"," +
                "       \"date\":\"2017-05-17T16:00:47-05:00\"" +
                "   }," +
                "   \"request\":" +
                "   {" +
                "       \"locale\":\"es_CO\"," +
                "       \"payer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Ulises\"," +
                "           \"surname\":\"Bosco\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"buyer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Ulises\"," +
                "           \"surname\":\"Bosco\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"payment\":null," +
                "       \"subscription\":" +
                "       {" +
                "           \"reference\":\"TEST_20200517_205952\"," +
                "           \"description\":\"Architecto illum et aut nihil.\"" +
                "       }," +
                "       \"fields\":null," +
                "       \"returnUrl\":\"http:\\/\\/redirect.p2p.dev\\/client\"," +
                "       \"paymentMethod\":null," +
                "       \"cancelUrl\":null," +
                "       \"ipAddress\":\"127.0.0.1\"," +
                "       \"userAgent\":\"Mozilla\\/5.0 (X11; Linux x86_64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/57.0.2987.98 Safari\\/537.36\"," +
                "       \"expiration\":\"2017-05-18T20:59:52+00:00\"," +
                "       \"captureAddress\":false," +
                "       \"skipResult\":false," +
                "       \"noBuyerFill\":false" +
                "   }," +
                "   \"payment\":null," +
                "   \"subscription\":" +
                "   {" +
                "       \"type\":\"token\"," +
                "       \"status\":" +
                "       {" +
                "           \"status\":\"OK\"," +
                "           \"reason\":\"00\"," +
                "           \"message\":\"Token generated successfully\"," +
                "           \"date\":\"2017-05-17T16:00:42-05:00\"" +
                "       }," +
                "       \"instrument\":" +
                "       [" +
                "           {" +
                "               \"keyword\":\"token\"," +
                "               \"value\":\"4b85ecd661bd6b2e1e69dbd42473c52ed9209c17f5157ede301fde94f66c5a2a\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"subtoken\"," +
                "               \"value\":\"0751944147051111\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"franchise\"," +
                "               \"value\":\"CR_VS\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"franchiseName\"," +
                "               \"value\":\"VISA\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"issuerName\"," +
                "               \"value\":null," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"lastDigits\"," +
                "               \"value\":\"1111\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"validUntil\"," +
                "               \"value\":\"2020-12-15\"," +
                "               \"displayOn\":\"none\"" +
                "           }," +
                "           {" +
                "               \"keyword\":\"installments\"," +
                "               \"value\":\"1\"," +
                "               \"displayOn\":\"none\"" +
                "           }" +
                "       ]" +
                "   }" +
                "}";

            var information = new RedirectInformation(result);

            Assert.AreEqual(372, information.RequestId);
            Assert.AreEqual(Status.ST_APPROVED, information.Status.StatusText);

            Assert.True(information.IsSuccessful());
            Assert.True(information.IsApproved());

            Assert.AreEqual("TEST_20200517_205952", information.Request.Subscription.Reference);
            Assert.AreEqual("Ulises", information.Request.Payer.Name);
            Assert.AreEqual("Bosco", information.Request.Payer.Surname);
            Assert.AreEqual("*****@*****.**", information.Request.Payer.Email);

            var token = (Token)information.Subscription.ParseInstrument();

            Assert.IsInstanceOf <Token>(token);
            Assert.True(token.IsSuccessful());

            Assert.AreEqual("4b85ecd661bd6b2e1e69dbd42473c52ed9209c17f5157ede301fde94f66c5a2a", token.TokenText);
            Assert.AreEqual("0751944147051111", token.Subtoken);
            Assert.AreEqual("CR_VS", token.Franchise);
            Assert.AreEqual("VISA", token.FranchiseName);
            Assert.AreEqual("1111", token.LastDigits);
            Assert.AreEqual("12/20", token.GetExpiration());
            Assert.AreEqual(1, token.Installments);

            Assert.AreEqual(JsonFormatter.ParseJObject("{" +
                                                       "\"status\": {" +
                                                       "\"status\": \"OK\"," +
                                                       "\"reason\": \"00\"," +
                                                       "\"message\": \"Token generated successfully\"," +
                                                       "\"date\": \"2017-05-17T16:00:42-05:00\"" +
                                                       "}," +
                                                       "\"token\": \"4b85ecd661bd6b2e1e69dbd42473c52ed9209c17f5157ede301fde94f66c5a2a\"," +
                                                       "\"subtoken\": \"0751944147051111\"," +
                                                       "\"franchise\": \"CR_VS\"," +
                                                       "\"franchiseName\": \"VISA\"," +
                                                       "\"lastDigits\": \"1111\"," +
                                                       "\"validUntil\": \"2020-12-15\"," +
                                                       "\"installments\": 1" +
                                                       "}"), token.ToJsonObject());
        }
Beispiel #13
0
        public void Should_Parse_A_Rest_Finished_Response()
        {
            string result =
                "{" +
                "   \"requestId\":360," +
                "   \"status\":" +
                "   {" +
                "       \"status\":\"APPROVED\"," +
                "       \"reason\":\"00\"," +
                "       \"message\":\"La petici\\u00f3n ha sido aprobada exitosamente\"," +
                "       \"date\":\"2017-05-17T14:53:54-05:00\"" +
                "   }," +
                "   \"request\":" +
                "   {" +
                "       \"locale\":\"es_CO\"," +
                "       \"payer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Leilani\"," +
                "           \"surname\":\"Zulauf\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"buyer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Leilani\"," +
                "           \"surname\":\"Zulauf\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"payment\":" +
                "       {" +
                "           \"reference\":\"TEST_20200516_154231\"," +
                "           \"description\":\"Et et dolorem tenetur et cum.\"," +
                "           \"amount\":" +
                "           {" +
                "               \"currency\":\"USD\"," +
                "               \"total\":\"0.3\"" +
                "           }," +
                "           \"allowPartial\":false" +
                "       }," +
                "       \"subscription\":null," +
                "       \"fields\":null," +
                "       \"returnUrl\":\"http:\\/\\/redirect.p2p.dev\\/client\"," +
                "       \"paymentMethod\":null," +
                "       \"cancelUrl\":null," +
                "       \"ipAddress\":\"127.0.0.1\"," +
                "       \"userAgent\":\"Mozilla\\/5.0 (X11; Linux x86_64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/57.0.2987.98 Safari\\/537.36\"," +
                "       \"expiration\":\"2017-05-17T15:42:31+00:00\"," +
                "       \"captureAddress\":false," +
                "       \"skipResult\":false," +
                "       \"noBuyerFill\":false" +
                "   }," +
                "   \"payment\":" +
                "   [" +
                "       {" +
                "           \"status\":" +
                "           {" +
                "               \"status\":\"APPROVED\"," +
                "               \"reason\":\"00\"," +
                "               \"message\":\"Aprobada\"," +
                "               \"date\":\"2017-05-16T10:43:39-05:00\"" +
                "           }," +
                "           \"internalReference\":1447466623," +
                "           \"paymentMethod\":\"paypal\"," +
                "           \"paymentMethodName\":\"PayPal\"," +
                "           \"amount\":" +
                "           {" +
                "               \"from\":" +
                "               {" +
                "                   \"currency\":\"USD\"," +
                "                   \"total\":0.3" +
                "               }," +
                "               \"to\":" +
                "               {" +
                "                   \"currency\":\"USD\"," +
                "                   \"total\":0.3" +
                "               }," +
                "               \"factor\":1" +
                "           }," +
                "           \"authorization\":\"2DG26929XX8381738\"," +
                "           \"reference\":\"TEST_20200516_154231\"," +
                "           \"receipt\":\"1447466623\"," +
                "           \"franchise\":\"PYPAL\"," +
                "           \"refunded\":false," +
                "           \"processorFields\":" +
                "           [" +
                "               {" +
                "                   \"keyword\":\"trazabilyCode\"," +
                "                   \"value\":\"PAY-9BU08130ME378305MLENR4CI\"," +
                "                   \"displayOn\":\"none\"" +
                "               }" +
                "           ]" +
                "       }" +
                "   ]," +
                "   \"subscription\":null" +
                "}";

            var information = new RedirectInformation(result);

            Assert.AreEqual(360, information.RequestId);
            Assert.AreEqual(Status.ST_APPROVED, information.Status.StatusText);

            Assert.True(information.IsSuccessful());
            Assert.True(information.IsApproved());

            Assert.AreEqual("TEST_20200516_154231", information.Request.Payment.Reference);
            Assert.AreEqual("Leilani", information.Request.Payer.Name);
            Assert.AreEqual("Zulauf", information.Request.Payer.Surname);
            Assert.AreEqual("*****@*****.**", information.Request.Payer.Email);
            Assert.AreEqual("USD", information.Request.Payment.Amount.Currency);
            Assert.AreEqual("0.3", information.Request.Payment.Amount.Total.ToString("G", CultureInfo.InvariantCulture));

            Assert.AreEqual("2DG26929XX8381738", information.LastAuthorization());
            Assert.AreEqual("1447466623", information.LastTransaction().Receipt.ToString());
            Assert.AreEqual("PYPAL", information.LastTransaction().Franchise);
            Assert.AreEqual(new JObject {
                { "trazabilyCode", "PAY-9BU08130ME378305MLENR4CI" }
            }, information.LastTransaction().AdditionalData());

            Assert.That(information.ToJsonObject().ContainsKey("requestId"));
        }
Beispiel #14
0
        public void Should_Parse_A_Rest_Created_Response()
        {
            string result =
                "{" +
                "   \"requestId\":368," +
                "   \"status\":" +
                "   {" +
                "       \"status\":\"PENDING\"," +
                "       \"reason\":\"PC\"," +
                "       \"message\":\"La petici\\u00f3n se encuentra activa\"," +
                "       \"date\":\"2017-05-17T14:44:05-05:00\"" +
                "   }," +
                "   \"request\":" +
                "   {" +
                "       \"locale\":\"es_CO\"," +
                "       \"payer\":null," +
                "       \"buyer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Jakob\"," +
                "           \"surname\":\"Macejkovic\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108300\"" +
                "       }," +
                "       \"payment\":" +
                "       {" +
                "           \"reference\":\"TEST_20200517_144129\"," +
                "           \"description\":\"Quisquam architecto optio rem in non expedita.\"," +
                "           \"amount\":" +
                "           {" +
                "               \"taxes\":" +
                "               [" +
                "                   {" +
                "                       \"kind\":\"valueAddedTax\"," +
                "                       \"amount\":20," +
                "                       \"base\":140" +
                "                   }" +
                "               ]," +
                "               \"currency\":\"USD\"," +
                "               \"total\":\"199.8\"" +
                "           }," +
                "           \"allowPartial\":false" +
                "       }," +
                "       \"subscription\":null," +
                "       \"fields\":null," +
                "       \"returnUrl\":\"http:\\/\\/local.dev\\/redirect\\/client\"," +
                "       \"paymentMethod\":null," +
                "       \"cancelUrl\":null," +
                "       \"ipAddress\":\"192.168.33.20\"," +
                "       \"userAgent\":\"Mozilla\\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/58.0.3029.96 Safari\\/537.36\"," +
                "       \"expiration\":\"2017-05-18T14:41:29+00:00\"," +
                "       \"captureAddress\":false," +
                "       \"skipResult\":false," +
                "       \"noBuyerFill\":false" +
                "   }," +
                "   \"payment\":null," +
                "   \"subscription\":null" +
                "}";

            var information = new RedirectInformation(result);

            Assert.AreEqual(368, information.RequestId);
            Assert.AreEqual(Status.ST_PENDING, information.Status.StatusText);

            Assert.True(information.IsSuccessful());
            Assert.False(information.IsApproved());

            Assert.AreEqual("TEST_20200517_144129", information.Request.Payment.Reference);
            Assert.AreEqual("1040035000", information.Request.Buyer.Document);

            Assert.Null(information.LastApprovedTransaction());
            Assert.Null(information.LastAuthorization());
            Assert.Null(information.LastTransaction());

            Assert.That(information.ToJsonObject().ContainsKey("requestId"));
        }
Beispiel #15
0
        public void Should_Parse_A_Rest_Updated_Response()
        {
            string result =
                "{ " +
                "   \"requestId\":371," +
                "   \"status\":" +
                "   {" +
                "       \"status\":\"PENDING\"," +
                "       \"reason\":\"PT\"," +
                "       \"message\":\"La petición se encuentra pendiente\"," +
                "       \"date\":\"2017-05-17T15:57:44-05:00\"" +
                "   }," +
                "   \"request\":" +
                "   {" +
                "       \"locale\":\"es_CO\"," +
                "       \"payer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Simon\"," +
                "           \"surname\":\"Godoy\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3006108399\"," +
                "           \"address\":" +
                "           {" +
                "               \"street\":\"123 Main Street\"," +
                "               \"city\":\"Chesterfield\"," +
                "               \"postalCode\":\"63017\"," +
                "               \"country\":\"US\"" +
                "           }" +
                "       }," +
                "       \"buyer\":" +
                "       {" +
                "           \"document\":\"1040035000\"," +
                "           \"documentType\":\"CC\"," +
                "           \"name\":\"Sugeis\"," +
                "           \"surname\":\"Meza\"," +
                "           \"email\":\"[email protected]\"," +
                "           \"mobile\":\"3002566565\"" +
                "       }," +
                "       \"payment\":" +
                "       {" +
                "           \"reference\":\"TEST_20200517_205552\"," +
                "           \"description\":\"Payment test.\"," +
                "           \"amount\":" +
                "           {" +
                "               \"currency\":\"USD\"," +
                "               \"total\":\"178\"" +
                "           }," +
                "           \"allowPartial\":false" +
                "       }," +
                "       \"subscription\":null," +
                "       \"fields\":null," +
                "       \"returnUrl\":\"http:\\/\\/redirect.p2p.dev\\/client\"," +
                "       \"paymentMethod\":null," +
                "       \"cancelUrl\":null," +
                "       \"ipAddress\":\"127.0.0.1\"," +
                "       \"userAgent\":\"Mozilla\\/5.0 (X11; Linux x86_64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/57.0.2987.98 Safari\\/537.36\"," +
                "       \"expiration\":\"2017-05-18T20:55:52+00:00\"," +
                "       \"captureAddress\":false," +
                "       \"skipResult\":false," +
                "       \"noBuyerFill\":false" +
                "   }," +
                "   \"payment\":" +
                "   [" +
                "       {" +
                "           \"status\":" +
                "           {" +
                "               \"status\":\"REJECTED\"," +
                "               \"reason\":\"01\"," +
                "               \"message\":\"Negada, Transacción declinada\"," +
                "               \"date\":\"2017-05-17T15:56:37-05:00\"" +
                "           }," +
                "           \"internalReference\":1447498827," +
                "           \"paymentMethod\":\"masterpass\"," +
                "           \"paymentMethodName\":\"MasterCard\"," +
                "           \"amount\":" +
                "           {" +
                "               \"from\":" +
                "               {" +
                "                   \"currency\":\"USD\"," +
                "                   \"total\":178" +
                "               }," +
                "               \"to\":" +
                "               {" +
                "                   \"currency\":\"COP\"," +
                "                   \"total\":511433.16" +
                "               }," +
                "               \"factor\":2873.22" +
                "           }," +
                "           \"authorization\":\"000000\"," +
                "           \"reference\":\"TEST_20200517_205552\"," +
                "           \"receipt\":\"1495054597\"," +
                "           \"franchise\":\"RM_MC\"," +
                "           \"refunded\":false," +
                "           \"processorFields\":" +
                "           [" +
                "               {" +
                "                   \"keyword\":\"lastDigits\"," +
                "                   \"value\":\"****0206\"," +
                "                   \"displayOn\":\"none\"" +
                "               }," +
                "               {" +
                "                   \"keyword\":\"id\"," +
                "                   \"value\":\"e6bc23b9f16980bc3e5422dbb6218f59\"," +
                "                   \"displayOn\":\"none\"" +
                "               }" +
                "           ]" +
                "       }" +
                "   ]," +
                "   \"subscription\":null" +
                "}";

            var information = new RedirectInformation(result);

            Assert.AreEqual(371, information.RequestId);
            Assert.AreEqual(Status.ST_PENDING, information.Status.StatusText);

            Assert.True(information.IsSuccessful());
            Assert.False(information.IsApproved());

            Assert.AreEqual("TEST_20200517_205552", information.Request.Payment.Reference);
            Assert.AreEqual("1040035000", information.Request.Buyer.Document);

            Assert.Null(information.LastApprovedTransaction());
            Assert.AreEqual(1495054597, information.LastTransaction().Receipt);
            Assert.Null(information.LastAuthorization());
        }
Beispiel #16
0
        public override RedirectInformation Collect(CollectRequest collectRequest)
        {
            try
            {
                this._action = "/collect";

                string request = Serializer.JsonSerializer.SerializeObject(collectRequest);

                var node = JsonConvert.DeserializeXmlNode(request, "payload");

                XElement collect = new XElement(p2p + "collect", XElement.Parse(node.OuterXml));

                string response = this.CallWebService(collect);

                response = Regex.Replace(response, @"(\s*)""@(.*)"":", @"$1""$2"":", RegexOptions.IgnoreCase);
                JObject res = JObject.Parse(response);

                if (res["ns1:collectResponse"]["collectResult"]["payment"] != null)
                {
                    var transaction = res["ns1:collectResponse"]["collectResult"]["payment"]["transaction"];
                    res["ns1:collectResponse"]["collectResult"]["payment"] = null;
                    var data = res["ns1:collectResponse"]["collectResult"];
                    RedirectInformationSOAP redirectInformationSOAP = JsonConvert.DeserializeObject <RedirectInformationSOAP>(data.ToString(), Serializer.JsonSerializer.Settings);

                    if (transaction.Type.ToString() == "Object")
                    {
                        List <TransactionSOAP> transactions    = new List <TransactionSOAP>();
                        TransactionSOAP        transactionSOAP = JsonConvert.DeserializeObject <TransactionSOAP>(transaction.ToString());
                        transactions.Add(transactionSOAP);
                        redirectInformationSOAP.Payment = transactions;
                    }
                    else
                    {
                        List <TransactionSOAP> transactions = new List <TransactionSOAP>();
                        TransactionSOAP        transactionSOAP;
                        foreach (var item in transaction.Children())
                        {
                            transactionSOAP = JsonConvert.DeserializeObject <TransactionSOAP>(item.ToString());
                            transactions.Add(transactionSOAP);
                        }
                        redirectInformationSOAP.Payment = transactions;
                    }

                    List <Transaction> paymentTransaction = new List <Transaction>();
                    foreach (var tSOAP in redirectInformationSOAP.Payment)
                    {
                        Transaction T = new Transaction(tSOAP.Status, tSOAP.Reference, tSOAP.InternalReference, tSOAP.PaymentMethod, tSOAP.PaymentMethodName, tSOAP.IssuerName, tSOAP.Amount, tSOAP.Authorization, tSOAP.Receipt, tSOAP.Franchise, tSOAP.Refunded, tSOAP.ProcessorFields.item);
                        paymentTransaction.Add(T);
                    }

                    RedirectInformation redirectInformation = new RedirectInformation(redirectInformationSOAP.RequestId, redirectInformationSOAP.Status, redirectInformationSOAP.Request, paymentTransaction, null);

                    return(redirectInformation);
                }
                else if (res["ns1:collectResponse"]["collectResult"]["subscription"] != null)
                {
                    var data = res["ns1:getRequestInformationResponse"]["getRequestInformationResult"];
                    RedirectInformationSOAP    redirectInformationSOAP    = JsonConvert.DeserializeObject <RedirectInformationSOAP>(data.ToString());
                    SubscriptionInfomationSOAP subscriptionInfomationSOAP = redirectInformationSOAP.Subscription;
                    SubscriptionInformation    subscriptionInformation    = new SubscriptionInformation(subscriptionInfomationSOAP.Type, subscriptionInfomationSOAP.Status, subscriptionInfomationSOAP.Instrument.item);
                    RedirectInformation        redirectInformation        = new RedirectInformation(redirectInformationSOAP.RequestId, redirectInformationSOAP.Status, redirectInformationSOAP.Request, null, subscriptionInformation);

                    return(redirectInformation);
                }
                else
                {
                    var data = res["ns1:collectResponse"]["collectResult"];
                    return(JsonConvert.DeserializeObject <RedirectInformation>(data.ToString()));
                }
            }
            catch (Exception ex)
            {
                Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"));
                RedirectInformation redirectInformation = new RedirectInformation(0, status, null, null, null);

                return(redirectInformation);
            }
        }