在用户批准付款后

在用户批准付款后

本文介绍了Paypal REST API:如何在用户批准付款后检索付款 ID.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 https://developer.paypal.com 上的指南进行操作/webapps/developer/docs/integration/web/accept-paypal-payment/ ,我已成功创建付款并重定向用户以批准它.

By following the guide on https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/ , I have successfully created a payment and redirect the user to approve it.

创建的付款如下所示,我将其保存在用户会话中以供进一步参考.

The created payment is something look like bellow, and I save it in user's session for further reference.

{
  "id": "PAY-6RV70583SB702805EKEYSZ6Y",
  "create_time": "2013-03-01T22:34:35Z",
  "update_time": "2013-03-01T22:34:36Z",
  "state": "created",
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "7.47",
        "currency": "USD",
        "details": {
          "subtotal": "7.47"
        }
      },
      "description": "This is the payment transaction description."
    }
  ],
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-60U79048BN7719609",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute",
      "rel": "execute",
      "method": "POST"
    }
  ]
}

在用户批准付款后,Paypal 会将用户重定向到 return_url.例如,http://?token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2.

After user approved the payment, Paypal will redirect the user to the return_url. For example, http://<return_url>?token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2.

为了执行付款,必须向 https://api.sandbox.paypal.com/v1/payments/payment/{payment_id}/execute/ 发出 POST 请求.

In order to execute the payment, a POST request has to made to https://api.sandbox.paypal.com/v1/payments/payment/{payment_id}/execute/.

问题

在 URL 中 Paypal 提供的唯一两条信息是 tokenPayerID.如何找到对应的payment_id?

The only two pieces of information provided from Paypal in the URL is token and PayerID. How can I find the corresponding payment_id?

可能的解决方案

tokenapproval_url 的一部分,解析 URL 并存储 token ->支付关系可以解决问题.但我正在寻找一个不需要解析的更好的解决方案.

The token is part of the approval_url, parse the URL and store the token -> payment relationship can solve the problem. But I'm looking for a better solution that doesn't require parsing.

推荐答案

我认为 paypal 文档对此并不清楚.但是您可以做一些简单的事情来解决您通过返回网址中的参数传递 de PaymentID 的问题.

I think the paypal documentation isn't clear about this. But you can do something simple to resolve your problem passing de PaymentID through a parameter in your return url.

像这样:return_url = 'http://www.yourdomain.com/paypal/success/?paymentID=PAY-1234567'

Like this:return_url = 'http://www.yourdomain.com/paypal/success/?paymentID=PAY-1234567'

当 Paypal 重定向到您的网站时,它将返回 paymentID 和其他参数.

When the Paypal redirect to your site, then, it will return the paymentID together with the other parameters.

葡萄牙语:

Não acho que isso esteja claro na documentação do Paypal.A solução que eu usei foi simples, eu passo o PaymentID como parâmetro na minha URL de retorno que informo para o Paypal.Assim, quando o Paypal redirectionar para meu site de volta ele matem o parâmetro com o PaymentID que eu tinha passado.

Não acho que isso esteja claro na documentação do Paypal. A solução que eu usei foi simples, eu passo o PaymentID como parâmetro na minha URL de retorno que informo para o Paypal. Assim, quando o Paypal redirecionar para meu site de volta ele matem o parâmetro com o PaymentID que eu tinha passado.

这篇关于Paypal REST API:如何在用户批准付款后检索付款 ID.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:45