public async Task <RedirectResponse> NavigatesAsync(RedirectRequest model) { var response = new RedirectResponse(); try { Item entity = await _itemQueryHandler.GetBySegmentAsync(model.Segment); if (entity != null && !string.IsNullOrWhiteSpace(entity.OriginUrl)) { // logging history to the DB await _statisticCommandHandler.ExecuteAsync(new CreateStatisticCommand { IpAddress = model.IpAddress, ItemId = entity.Id }); response.IsSuccess = true; response.OriginUrl = entity.OriginUrl; } } catch (Exception exception) { response.IsSuccess = false; response.Message = exception.Message; } return(response); }
public override RedirectResponse Request(RedirectRequest redirectRequest) { try { this._action = "/createRequest"; string request = Serializer.JsonSerializer.SerializeObject(redirectRequest); var node = JsonConvert.DeserializeXmlNode(request, "payload"); XElement createRequest = new XElement(p2p + "createRequest", XElement.Parse(node.OuterXml)); string response = this.CallWebService(createRequest); JObject res = JObject.Parse(response); var data = res["ns1:createRequestResponse"]["createRequestResult"]; return(JsonConvert.DeserializeObject <RedirectResponse>(data.ToString())); } catch (Exception ex) { Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz")); RedirectResponse redirectResponse = new RedirectResponse(null, null, status); return(redirectResponse); } }
public void Should_Parse_Correctly_A_Payment_Request_With_String_Data() { string data = "{ " + " \"payment\":{ " + " \"reference\":\"Testing_S_2020\"," + " \"amount\":{ " + " \"currency\":\"COP\"," + " \"total\":\"10000\"," + " \"taxes\":[" + " { " + " \"kind\":\"valueAddedTax\"," + " \"amount\":\"1.2\"," + " \"base\":\"8\"" + " }" + " ]" + " }" + " }," + " \"returnUrl\":\"http:\\/\\/your-return-url.com\"" + "}"; var request = new RedirectRequest(data); Assert.AreEqual("http://your-return-url.com", request.ReturnUrl); Assert.AreEqual("Testing_S_2020", request.GetReference()); Assert.IsNotNull(request.Payment); }
/// <summary> /// Método CrearOrdenPedido. /// </summary> /// <returns>Task{Orders}</returns> public async Task <Orders> CrearOrdenPedido(Orders ordenPedido, string direccionIP, string agenteUsuario) { 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); Amount montoPago = new Amount(TOTAL_PAGO); Payment pagoPedido = new Payment(PRODUCTO, PRODUCTO, montoPago); var tiempoExpiracionPago = DateTime.Now.AddMinutes(10); ordenPedido.OrderStatus = await this.tiendaVirtualRepositorio.ProcesarEstadoOrden(ESTADOINICIALORDEN); ordenPedido.Status_Id = ordenPedido.OrderStatus.Id; ordenPedido.Created_At = DateTime.Now; this.tiendaVirtualRepositorio.Insertar(ordenPedido); var urlRedireccionamientoLocal = string.Format("{0}/{1}{2}", ordenPedido.UrlRaiz, "ordenes/visualizarestado/false/", ordenPedido.Id); RedirectRequest solicitudRedireccionamiento = new RedirectRequest(pagoPedido, urlRedireccionamientoLocal, direccionIP, agenteUsuario, tiempoExpiracionPago.ToString("s", CultureInfo.InvariantCulture)); solicitudRedireccionamiento.Buyer = new Person(string.Empty, string.Empty, ordenPedido.Customer_Name, string.Empty, ordenPedido.Customer_Email, mobile: ordenPedido.Customer_Mobile); solicitudRedireccionamiento.Locale = "es_CO"; solicitudRedireccionamiento.CancelUrl = urlRedireccionamientoLocal; RedirectResponse response = gateWay.Request(solicitudRedireccionamiento); if (response.Status.status != ESTADO_OK_CREACION_ORDENPEDIDO) { this.tiendaVirtualRepositorio.Eliminar(ordenPedido); throw new Exception(response.Status.Message); } ordenPedido.Request_Id = response.RequestId; ordenPedido.UrlProcesamiento = response.ProcessUrl; this.tiendaVirtualRepositorio.Actualizar(ordenPedido); return(await Task.FromResult(ordenPedido)); }
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 RedirectRequest Get(Uri uri) { var request = new RedirectRequest(uri) { Proxy = GetWebProxy() }; if (Settings.ForceHttp) { request.BeforeSubmit += (sender, args) => { if (request.Uri.Scheme == Uri.UriSchemeHttps) { request.Uri = new UriBuilder(request.Uri) { Scheme = Uri.UriSchemeHttp }.Uri; request.Headers["X-Forwarded-Proto"] = Uri.UriSchemeHttps; } else { request.Headers.Remove("X-Forwarded-Proto"); } }; } return(request); }
public void Should_Parse_Correctly_A_Payment_Request_With_Object_Instance() { var request = new RedirectRequest(null, null, null, "http://your-return-url.com", "CR_VS"); Assert.IsNull(request.Payer); Assert.AreEqual("http://your-return-url.com", request.ReturnUrl); Assert.AreEqual("CR_VS", request.PaymentMethod); }
public CollectInformationREST(int requestId, Status status, RedirectRequest request, List <Transaction> payment, SubscriptionInformation subscription) { this.requestId = requestId; this.status = status; this.request = request; this.payment = payment; this.subscription = subscription; }
public void Should_Parse_Correctly_A_Payment_Request_With_Full_Object_Instance() { var request = new RedirectRequest(null, null, null, null, "http://your-return-url.com", "CR_VS", null, null, null, null, false, false, false, null); Assert.IsNull(request.Fields); Assert.AreEqual("http://your-return-url.com", request.ReturnUrl); Assert.AreEqual("CR_VS", request.PaymentMethod); Assert.False(request.CaptureAddress); Assert.False(request.NoBuyerFill); Assert.False(request.SkipResult); }
public void CrearSubcribcion() { string email, nombre, apellido, espagador; email = "*****@*****.**"; nombre = "Daniel"; apellido = "betancur"; espagador = "no"; try { Gateway gateway = CrearAutenticacion(); Amount amount = new Amount(20000.002); string referencia = "pruebasd_" + db.Transaccions.ToList().Count(); Subscription subcripcion = new Subscription(referencia, "No hay descripcion"); Transaccion transaccion = new Transaccion(); transaccion.Id = db.Transaccions.ToList().Count() + 1; if (nombre != null && email != null && apellido != null) { RedirectRequest request; Person buyer = new Person("10000004", "CC", nombre, apellido, email); if (espagador == "on") { Person payer = new Person("10000004", "CC", nombre, apellido, email); request = new RedirectRequest(subcripcion, "http://localhost:63562/Transacciones/returnURL" + "?" + "id=" + transaccion.Id, "192.168.0.2", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0", (DateTime.Now).AddMinutes(40).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"), payer, buyer); } else { request = new RedirectRequest(subcripcion, "http://localhost:63562/Transacciones/returnURL" + "?" + "id=" + transaccion.Id, "192.168.0.2", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0", (DateTime.Now).AddMinutes(40).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"), null, buyer); } ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; RedirectResponse response = gateway.Request(request); transaccion.requestId = response.RequestId; transaccion.URL = response.ProcessUrl; transaccion.referencia = referencia; db.Transaccions.Add(transaccion); db.SaveChanges(); Response.Redirect(response.ProcessUrl); } } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }
/// <summary> /// Request endpoint. /// </summary> /// <param name="redirectRequest">redirect request instance object.</param> /// <returns>redirect response instance object.</returns> public override RedirectResponse Request(RedirectRequest redirectRequest) { XmlDocument response = new XmlDocument(); XmlDocument payload = JsonConvert.DeserializeXmlNode(redirectRequest.ToJsonObject().ToString(), "payload"); XElement body = new XElement(wsdl.GetName("createRequest"), XElement.Parse(payload.InnerXml)); response.LoadXml(MakeRequest(body)); response = RemoveNullFields(response); XmlNode data = response.SelectSingleNode("descendant::createRequestResult"); JObject json = JObject.Parse(JsonConvert.SerializeXmlNode(data)); return(new RedirectResponse(json.GetValue("createRequestResult").ToString())); }
public override RedirectResponse Request(RedirectRequest redirectRequest) { try { string endpoint = "api/session"; string method = "POST"; var response = this.MakeRequest(method, endpoint, redirectRequest); return(JsonConvert.DeserializeObject <RedirectResponse>(response)); } catch (Exception ex) { Status status = new Status("ERROR", "WR", PlacetoPayException.ReadException(ex), (DateTime.Now).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz")); RedirectResponse redirectResponse = new RedirectResponse(null, null, status); return(redirectResponse); } }
/// <summary> /// Request endpoint. /// </summary> /// <param name="redirectRequest">object</param> /// <returns>RedirectResponse</returns> public override RedirectResponse Request(object redirectRequest) { if (redirectRequest.GetType() == typeof(string)) { redirectRequest = new RedirectRequest((string)redirectRequest); } if (redirectRequest.GetType() == typeof(JObject)) { redirectRequest = new RedirectRequest((JObject)redirectRequest); } if (!(redirectRequest.GetType() == typeof(RedirectRequest))) { throw new PlacetoPayException("Wrong class request"); } return(Carrier().Request((RedirectRequest)redirectRequest)); }
public string[] CreatePayment(string reference, string description, double amountValue, string userIP, string userAgent, string id_order) { string return_url = WebConfigurationManager.AppSettings["RETURN_BASE_URL"].ToString(); string[] responseProcess = new string[4]; Amount amount = new Amount(amountValue); Payment payment = new Payment(reference, description, amount); RedirectRequest request = new RedirectRequest(payment, return_url + id_order, userIP, userAgent, DateTime.Now.AddHours(1).ToString("dd-MM-yyyy HH:mm:ss")); RedirectResponse response = gateway.Request(request); responseProcess[0] = response.Status.Message; responseProcess[1] = response.RequestId; responseProcess[2] = response.ProcessUrl; responseProcess[3] = response.Status.status; return(responseProcess); }
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()); } }
/// <summary> /// Request endpoint. /// </summary> /// <param name="redirectRequest">RedirectRequest</param> /// <returns>RedirectResponse</returns> public abstract RedirectResponse Request(RedirectRequest redirectRequest);
public string get_redirect_correct(RedirectRequest request) { return("Right!"); }
public void Should_Parse_Correctly_A_Dispersion() { string data = JsonConvert.SerializeObject(new { buyer = new { name = "Simon", email = "*****@*****.**", }, payment = new { reference = "TEST_3", description = "Testing Payment", amount = new { currency = "COP", total = 243590, }, dispersion = new[] { new { agreement = 29, agreementType = "AIRLINE", amount = new { taxes = new[] { new { kind = "valueAddedTax", amount = 30590, }, new { kind = "airportTax", amount = 16300, }, }, currency = "COP", total = 207890, }, }, new { agreement = 0, agreementType = "MERCHANT", amount = new { taxes = new[] { new { kind = "valueAddedTax", amount = 5700, }, }, currency = "COP", total = 35700, }, }, }, }, expiration = (DateTime.Now).AddDays(+1).ToString("yyyy-MM-ddTHH\\:mm\\:sszzz"), returnUrl = "https://dnetix.co/ping/rtest", ipAddress = "127.0.0.1", userAgent = "NUnit", }); JsonReader reader = new JsonTextReader(new StringReader(data)) { DateParseHandling = DateParseHandling.None }; JObject json = JObject.Load(reader); var request = new RedirectRequest(json).ToJsonObject(); Assert.True(true); }
public override RedirectResponse Request(RedirectRequest redirectRequest) { return(this.Carrier().Request(redirectRequest)); }
public string get_redirect_correct(RedirectRequest request) { return "Right!"; }
public string post_redirect_wrong(RedirectRequest request) { return "Wrong!"; }
public async Task <IActionResult> Post([FromBody] RedirectRequest request) { await notifyAlias(request.ClientId, "transferUrl", request.DestinationUrl); return(Ok()); }
public void Should_Parse_Correctly_A_Payment_Request() { string data = JsonConvert.SerializeObject(new { locale = "en_US", payer = new { name = "Simon", surname = "Godoy", email = "*****@*****.**", documentType = "CC", document = "123456789", mobile = "3012563232", address = new { street = "Fake street 123", city = "Medellin", state = "Antioquia", postalCode = "050012", country = "CO", phone = "4442310", }, }, buyer = new { name = "Sugeis", surname = "Meza", email = "*****@*****.**", documentType = "CC", document = "987654321", mobile = "3006108301", address = new { street = "Fake street 321", city = "Bogota", state = "Bogota", postalCode = "010012", country = "CO", phone = "+574442311", }, }, payment = new { reference = "Testing_2020", description = "Testing payment for NUnit", amount = new { taxes = new[] { new { kind = "valueAddedTax", amount = 1.9, }, }, details = new[] { new { kind = "tip", amount = 1.0, }, new { kind = "insurance", amount = 0.1, }, }, currency = "USD", total = 10.283, }, recurring = new { periodicity = "D", interval = 7, nextPayment = "2017-06-01", maxPeriods = 4, notificationUrl = "http://recurring-notification.com/hello", }, shipping = new { name = "Jhonder", surname = "Gonzalez", email = "*****@*****.**", documentType = "CC", document = "918273645", mobile = "3006108302", address = new { street = "Fake street 213", city = "Medellin", state = "Antioquia", postalCode = "050012", country = "CO", phone = "4442312", }, }, allowPartial = true, }, expiration = "2018-05-18T21:42:21+00:00", ipAddress = "127.0.0.1", userAgent = "NUnit", returnUrl = "http://your-return-url.com", cancelUrl = "http://your-cancel-url.com", skipResult = true, noBuyerFill = true, captureAddress = true, paymentMethod = "CR_VS,_ATH_", }); JObject json = JObject.Parse(data); var request = new RedirectRequest(json); Assert.AreEqual((string)json["locale"], request.Locale); Assert.AreEqual("EN", request.GetLanguage()); Assert.AreEqual((string)json["payment"]["reference"], request.GetReference()); Assert.True(request.Payment.AllowPartial); Assert.AreEqual((string)json["returnUrl"], request.ReturnUrl); Assert.AreEqual((string)json["cancelUrl"], request.CancelUrl); }
public void Should_Parse_Correctly_A_Subscription_Request() { string data = JsonConvert.SerializeObject(new { buyer = new { name = "Sugeis", surname = "Meza", email = "*****@*****.**", documentType = "CC", document = "987654321", mobile = "3006108301", address = new { street = "Fake street 321", city = "Bogota", state = "Bogota", postalCode = "010012", country = "CO", phone = "+574442311", }, }, subscription = new { reference = "Testing_S_2020", description = "Testing payment for NUnit", }, ipAddress = "127.0.0.1", userAgent = "NUnit", }); JObject json = JObject.Parse(data); string additional = JsonConvert.SerializeObject(new { expiration = "2018-05-18T21:42:21+00:00", returnUrl = "http://your-return-url.com", cancelUrl = "http://your-cancel-url.com", skipResult = true, noBuyerFill = true, captureAddress = true, paymentMethod = "CR_VS,_ATH_", userAgent = "NUnit", ipAddress = "127.0.0.12", }); JObject jsonAdditional = JObject.Parse(additional); var request = new RedirectRequest(json); request.SetReturnUrl((string)jsonAdditional["returnUrl"]) .SetIpAddress((string)jsonAdditional["ipAddress"]) .SetUserAgent((string)jsonAdditional["userAgent"]) .SetExpiration((string)jsonAdditional["expiration"]) .SetCancelUrl((string)jsonAdditional["cancelUrl"]); Assert.AreEqual((string)json["subscription"]["reference"], request.GetReference()); Assert.AreEqual((string)jsonAdditional["returnUrl"], request.ReturnUrl); Assert.AreEqual((string)jsonAdditional["ipAddress"], request.IpAddress); Assert.AreEqual((string)jsonAdditional["userAgent"], request.UserAgent); Assert.AreEqual((string)jsonAdditional["expiration"], request.Expiration); Assert.AreEqual((string)jsonAdditional["cancelUrl"], request.CancelUrl); }
/// <summary> /// Make request endpoint. /// </summary> /// <param name="redirectRequest">RedirectRequest</param> /// <returns>RedirectResponse</returns> public override RedirectResponse Request(RedirectRequest redirectRequest) { string result = MakeRequest("POST", "api/session", redirectRequest.ToJsonObject()); return(new RedirectResponse(result)); }
public string post_redirect_wrong(RedirectRequest request) { return("Wrong!"); }