PayPal付款标准收益获得而不是从移动设备发帖,因此无法验证记录付款



我已经集成了贝宝(Paypal)付款标准,几年后以获取付款。

我的应用程序在ASP.NET中。当前处于沙盒模式。

我的网站上有一个付费按钮,带有所有必需参数的贝宝网站的后背包。当用户单击按钮时,它将重定向以通过其帐户或借记/信用卡付款。成功的交易中,用户将发送回我的应用程序。当用户回到我的应用程序时,我会在request.form Collection中获得各种参数。我验证响应并相应地显示成功/失败消息。

上面的流程在用户在桌面的浏览器上时工作正常。

但是,当用户在移动设备中并使用移动浏览器时。用户被降落在PayPal移动友好页面上。用户用他的帐户付款。然后显示成功消息。但是,当用户重定向到我的应用程序时,我在request.form集合中没有任何值。因此,我无法验证PayPal的响应。

此外,我了解到,当在桌面浏览器上通过邮政方法响应我的网站时,请求。form包含数据。

,而对于移动浏览器paypal返回响应的情况,请求。form不包含任何数据。

为什么PayPal通过GET返回响应?在这种情况下,即使在Querystring中也无法使用数据,那么我该如何验证响应,是否成功?

我已经阅读了文档,它说移动PayPal付款标准没有其他特定设置。

我不想迁移以表达结帐或任何其他配置。

我也搜索了许多与同一线程有关的线程,但没有找到任何适合我的解决方案,因此提出了一个新问题。

我在我的webapi asp.net项目中为paypal做了这样的事情。希望它能帮助您:

[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));
            }
        }

和我的映射器和类PayPalviewModel

  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
            };
        }
    }

最新更新