PayPal payment standard returns GET instead of POST from mobile devices, therefore, cannot confirm payment

I have integrated PayPal Payment Standard a couple of years ago to receive payment.

My application is in Asp.Net. Now it is in sandbox mode.

I have a "Pay Now" button on my website, where PostBackURL to the PayPal website with all the necessary parameters. When a user clicks on a button, it redirects to PayPal, which their user can pay through their account or debit / credit card. And with a successful transaction, the user is sent back to my application. When the user returns to my application, I get various parameters, such as "payment_status" in the Request.Form collection. I check the response and show a success / failure message.

The above thread works fine when the user is in a browser on the desktop.

But when the user is on mobile devices and works with a mobile browser. The user has landed on the PayPal mobile phone page. There, the user pays at his own expense. A success message is then displayed. But when the user is redirected to my application, I do not get any values โ€‹โ€‹in the Request.Form collection. In this regard, I can not confirm the answer from PayPal.

Further, I found out that when on desktop browsers PayPal returns a response via the POST method to my site, therefore, Request.Form contains data.

Whereas in the case of mobile browsers, PayPal returns a response via the GET method, therefore Request.Form does not contain any data.

Why does PayPal return a response via GET? In this case, the data is not available even in the request, how can I check the answer, is the payment successful or not?

I read the documentation and he says there are no other specific settings for the PayPal mobile payment standard.

I do not want to switch to express order or any other configuration.

I also searched a lot of threads on SO related to them, and did not find a suitable solution that satisfies my need, therefore asking a new question.

+6
source share
1 answer

I did this for PayPal in my ASPAP ASPP project .. hope it helps you:

[AllowAnonymous] [HttpPost] [Route("api/PayPal/IPN")] [ResponseType(typeof(OrderPayPalDTO))] public async Task<IHttpActionResult> PayPalIPN() { try { decimal tot; var data = this.Request.Content.ReadAsStringAsync().Result; if (data == null) return BadRequest(); // Parse the query string variables into a NameValueCollection. NameValueCollection qscoll = HttpUtility.ParseQueryString(data); PayPalViewModel payPalModel = new PayPalViewModel(); var payPal = payPalModel.ToPayPalVM(qscoll); //HRE IS A EXTENSION METHOD TO MAP to a CLASS if (payPal == null) return InternalServerError(new Exception()); //Try cast total from paypal if (!decimal.TryParse(payPal.mc_gross, out tot)) return InternalServerError(new Exception(Constant.Error.PAYMENT_ERROR_TOTAL_CAST)); // If status is Ok /or Completed if (payPal.payment_status.Equals(Constant.PaymentStatus.PAYED) || payPal.payment_status.Equals(Constant.PaymentStatus.COMPLETED)) { // update payment bool ok = await this.UpdatePayment(order, user); if (!ok) return InternalServerError(new Exception(Constant.Error.PAYMENT_ERROR_UPDATE)); } return Ok(order); } catch (Exception ex) { _logger.LogException(ex); return (Constant.CONFIGURATION_GLOBALS.IS_DEVELOPMENT_MODE) ? InternalServerError(ex) : InternalServerError(new Exception(Constant.Error.ERROR_GENERIC_500)); } } 

And my cartographer and PayPalViewModel class

  public class PayPalViewModel { public string mc_gross { get; set; } public string custom { get; set; } public string payment_status { get; set; } public string payment_type { get; set; } public string mc_currency { get; set; } public string payer_id { get; set; } public DateTime payment_date { get; set; } public string payment_gross { get; set; } /// <summary> /// ToPayPalVM From NameValueCollection /// </summary> /// <returns></returns> public PayPalViewModel ToPayPalVM(NameValueCollection qscoll) { if (qscoll == null) return null; DateTime date = DateTime.Now; string mcGross = qscoll["mc_gross"]; string paymentType = qscoll["payment_type"]; string mcCurrency = qscoll["mc_currency"]; string paymentStatus = qscoll["payment_status"]; string payerId = qscoll["payer_id"]; string paymentDate = qscoll["payment_date"]; string paymentGross = qscoll["payment_gross"]; string cust = qscoll["custom"]; var datePay = DateTime.TryParse(paymentDate, out date); return new PayPalViewModel { mc_gross = mcGross, custom = cust, payment_status = paymentStatus, payment_type = paymentType, mc_currency = mcCurrency, payer_id = payerId, payment_gross = paymentGross, payment_date = (datePay) ? date : DateTime.Now }; } } 
+2
source

Source: https://habr.com/ru/post/1013491/


All Articles