private IPaymentPostData CreatePostedData(HttpRequestMessage request) { string postedData = request.GetPostedData(); if (postedData == null) { return(null); } PaymentPostData result = new PaymentPostData(); foreach (string keyValue in postedData.Split('&')) { if (keyValue.StartsWith("Data=")) { result.Data = WebUtility.UrlDecode(keyValue.Substring(5)); } if (keyValue.StartsWith("InterfaceVersion=")) { result.InterfaceVersion = WebUtility.UrlDecode(keyValue.Substring(17)); } if (keyValue.StartsWith("Seal=")) { result.Seal = WebUtility.UrlDecode(keyValue.Substring(5)); } } return(result); }
public void Validate_IsValid_NoException() { PaymentPostData postData = new PaymentPostData() { Data = "data", Seal = _expectedSeal, }; PaymentPostDataValidator.Validate(_configuration, postData); }
public IActionResult CreatePaymentFor(int orderId) { GetOrderRequest request = new GetOrderRequest { OrderId = orderId }; GetOrderResponse response = _orderService.GetOrder(request); OrderPaymentRequest orderPaymentRequest = _mapper.Map <OrderView, OrderPaymentRequest>(response.Order); PaymentPostData paymentPostData = _paymentService.GeneratePostDataFor(orderPaymentRequest); return(View("PaymentPost", paymentPostData)); }
public void Validate_DataIsWhitespace_ThrowsException() { PaymentPostData postData = new PaymentPostData() { Data = " ", Seal = _expectedSeal, }; ExceptionAssert.ThrowsWhitespaceValidationException(nameof(postData.Data), () => { PaymentPostDataValidator.Validate(_configuration, postData); }); }
public void Validate_DataIsEmpty_ThrowsException() { PaymentPostData postData = new PaymentPostData() { Data = string.Empty, Seal = _expectedSeal, }; ExceptionAssert.ThrowsEmptyValidationException(nameof(postData.Data), () => { PaymentPostDataValidator.Validate(_configuration, postData); }); }
public void Validate_SealIsWhitespace_ThrowsException() { PaymentPostData postData = new PaymentPostData() { Data = "data", Seal = " ", }; ExceptionAssert.Throws <InvalidOperationException>($"The seal is invalid.{Environment.NewLine}Expected value: {_expectedSeal}.", () => { PaymentPostDataValidator.Validate(_configuration, postData); }); }
public void GetResponse_ResponseIsInvalid_ThrowsException() { Kassa kassa = new Kassa(_configuration); PaymentPostData postData = new PaymentPostData() { Data = "test=test", Seal = "seal", }; ExceptionAssert.Throws <InvalidOperationException>($"The seal is invalid.{Environment.NewLine}Expected value: f5db08a8cfdc7245247e8ad08d88e12e96435ce1bd11c781ab170c80d6a4668d.", () => { kassa.GetResponse(postData); }); }
public void GetResponse_ResponseValid_ReturnsResult() { Kassa kassa = new Kassa(_configuration); PaymentPostData postData = new PaymentPostData() { Data = $"merchantId={_configuration.MerchantId}|amount=4200", Seal = "0e14ed66182e64d1eed8623d946032648dafa6043f87fc7e4fb8eb2e40469781", }; IPaymentResponse response = kassa.GetResponse(postData); Assert.IsNotNull(response); Assert.AreEqual(42.0m, response.Amount); }
public ActionResult CreatePaymentFor(int orderId) { GetOrderRequest request = new GetOrderRequest() { OrderId = orderId }; GetOrderResponse response = _orderService.GetOrder(request); OrderPaymentRequest orderPaymentRequest = response.Order.ConvertToOrderPaymentRequest(); PaymentPostData paymentPostData = _paymentService.GeneratePostDataFor(orderPaymentRequest); return(View("PaymentPost", paymentPostData)); }
public void Validate_InterfaceVersionIsInvalid_ThrowsNoException() { /* * It appears that the api can send a V2 response when our request * was V1 so this should not throw an exception. */ PaymentPostData postData = new PaymentPostData() { Data = "data", InterfaceVersion = "HP_1.1", Seal = _expectedSeal, }; PaymentPostDataValidator.Validate(_configuration, postData); }
public PaymentPostData CreatePaymentPostData(int orderId) { GetOrderRequest request = new GetOrderRequest() { OrderId = orderId }; GetOrderResponse response = _orderService.GetOrder(request); OrderPaymentRequest orderPaymentRequest = response.Order.ConvertToOrderPaymentRequest(); PaymentPostData paymentPostData = _paymentService.GeneratePostDataFor(orderPaymentRequest); return(paymentPostData); }
public ActionResult <PaymentPostData> CreatePaymentFor(int orderId) { var request = new GetOrderRequest() { OrderId = orderId }; GetOrderResponse response = _orderService.GetOrder(request); OrderPaymentRequest orderPaymentRequest = DTOs.OrderMapper.ConvertToOrderPaymentRequest(response.Order); PaymentPostData paymentPostData = _paymentService.GeneratePostDataFor(orderPaymentRequest); return(paymentPostData); }
public void ConvertPostData_WithPostData_ReturnsNameValueCollection() { PaymentPostData postData = new PaymentPostData() { Data = "1", InterfaceVersion = "2", Seal = "3" }; NameValueCollection content = HttpClient.ConvertPostData(postData); Assert.IsNotNull(content); Assert.AreEqual(3, content.Count); Assert.AreEqual("1", content["Data"]); Assert.AreEqual("2", content["InterfaceVersion"]); Assert.AreEqual("3", content["Seal"]); }
public void PostData_WithPostData_CorrectOutput() { PaymentPostData postData = new PaymentPostData() { Data = "1", InterfaceVersion = "2", Seal = "3" }; using (HttpClient client = new HttpClient()) { using (TemporaryFile file = new TemporaryFile()) { client.PostData(new Uri("file://" + file.File.FullName), postData); string postedData = File.ReadAllText(file.File.FullName); Assert.AreEqual("Data=1&Seal=3&InterfaceVersion=2", postedData); } } }
public ActionResult CreatePaymentFor(int orderId) { PaymentPostData paymentPostData = CreatePaymentPostData(orderId); return(View("PaymentPost", paymentPostData)); }
public PaymentPostData GeneratePostDataFor(OrderPaymentRequest orderRequest) { PaymentPostData paymentPostData = new PaymentPostData(); NameValueCollection postDataAndValue = new NameValueCollection(); paymentPostData.PostDataAndValue = postDataAndValue; // When a real PayPal account is used, the form should be sent to // https://www.paypal.com/cgi-bin/webscr. // For testing use "https://www.sandbox.paypal.com/cgi-bin/webscr" paymentPostData.PaymentPostToUrl = _configuration["PayPalPaymentPostToUrl"]; // For shopping cart purchases. postDataAndValue.Add("cmd", "_cart"); // Indicates the use of third- party shopping cart. postDataAndValue.Add("upload", "1"); // This is the seller’s e-mail address. // You must supply your own address here!!! postDataAndValue.Add("business", _configuration["PayPalBusinessEmail"]); // This field does not take part in the shopping process. // It simply will be passed to the IPN script at the time // of transaction confirmation. postDataAndValue.Add("custom", orderRequest.Id.ToString()); // This parameter represents the default currency code. postDataAndValue.Add("currency_code", orderRequest.CurrencyCode); postDataAndValue.Add("first_name", orderRequest.CustomerFirstName); postDataAndValue.Add("last_name", orderRequest.CustomerSecondName); postDataAndValue.Add("address1", orderRequest.DeliveryAddressAddressLine); postDataAndValue.Add("city", orderRequest.DeliveryAddressCity); postDataAndValue.Add("state", orderRequest.DeliveryAddressState); postDataAndValue.Add("country", orderRequest.DeliveryAddressCountry); postDataAndValue.Add("zip", orderRequest.DeliveryAddressZipCode); // This is the URL where the user will be redirected after the payment // is successfully performed. If this parameter is not passed, the buyer // remains on the PayPal site. postDataAndValue.Add("return", _httpContextAccessor?.HttpContext?.Resolve("/Payment/PaymentComplete")); // This is the URL where the user will be redirected when // he cancels the payment. // If the parameter is not passed, the buyer remains on the PayPal site. postDataAndValue.Add("cancel_return", _httpContextAccessor?.HttpContext?.Resolve("/Payment/PaymentCancel")); // This is the URL where PayPal will pass information about the // transaction (IPN). If the parameter is not passed, the value from // the account settings will be used. If this value is not defined in // the account settings, IPN will not be used. postDataAndValue.Add("notify_url", _httpContextAccessor?.HttpContext?.Resolve("/Payment/PaymentCallBack")); int itemIndex = 1; foreach (OrderItemPaymentRequest item in orderRequest.Items) { postDataAndValue.Add("item_name_" + itemIndex.ToString(), item.ProductName); postDataAndValue.Add("amount_" + itemIndex.ToString(), item.Price.ToString()); postDataAndValue.Add("item_number_" + itemIndex.ToString(), item.Id.ToString()); postDataAndValue.Add("quantity_" + itemIndex.ToString(), item.Qty.ToString()); itemIndex++; } postDataAndValue.Add("handling_cart", orderRequest.ShippingCharge.ToString()); postDataAndValue.Add("address_override", "1"); return(paymentPostData); }