14

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"
    }
  ]
}

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

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

Question

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

Possible Solution

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.

4

5 回答 5

10

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

像这样: return_url = ' http://www.yourdomain.com/paypal/success/支付ID=PAY-1234567 '

当 Paypal 重定向到您的站点时,它将返回 paymentID 以及其他参数。


葡萄牙语:

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。

于 2013-09-23T23:52:47.057 回答
5

在将用户重定向到 PayPal 批准 url 之前,您必须记住您身边的付款 ID(通常附加在您的用户会话中 - 购物车或订单或作为会话 cookie)。一旦将其与 PayerID 一起重定向回您的返回 URL - 您将需要从您的用户会话中提取 PaymentID 并执行付款。

于 2013-09-03T04:04:52.320 回答
1

在第一个 API 请求返回成功响应后,可以使用以下方法在 PHP 中获取 Payment Id:

$payment->getId();

在线代码示例 ( http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html ) 显示了如何发送请求,但是它不包含 getId() 方法。

为了找到这一点,我必须在文件 sample\payments\CreatePayment.php 中查看下载的 SDK 文件,其中包含以下示例代码,显示了此方法的使用:

ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
于 2017-07-11T09:25:59.610 回答
0

我发现这个链接非常有帮助,如果有人想查看它:https ://github.com/paypal/PayPal-NET-SDK/issues/79

于 2017-06-21T21:27:01.157 回答
-1
  1. paymentid

创建付款后,返回json,您可以获得paymentid。像这样:“id”:“PAY-01K00482KX842131HKORKVKY”

  1. payerid

您可以在用户批准付款后使用 API:GET /v1/payments/payment/{paymentId} 获取付款人 ID,您会在返回的 json 中找到 payerid,如下所示:

{
    "id":"PAY-01K00482KX842131HKORKVKY",
    "create_time":"2014-06-19T09:17:31Z",
    "update_time":"2014-06-19T09:17:31Z",
    "state":"created",
    "intent":"sale",
    "payer":{
            "payment_method":"paypal",
            "payer_info":{
                    "email":"buyer@samsung.com",
                    "first_name":"buyer",
                    "last_name":"samsung",
                    "payer_id":"H2DKRTTYWW8HS",
                    "shipping_address":{                                              "line1":"Lushan Road Num.188",                                              "line2":"JianYe",
                                              "city":"Tucson",
                                                   "state":"AZ",   
                                                   "postal_code":"85715", 
                                                   "country_code":"US",
                                                    "recipientName":"buyer samsung"}}},
    "transactions":[{
                           "amount":{
                                        "total":"12.00",
                                        "currency":"USD",
                                        "details"{"subtotal":"12.00"}},
                 "description":"creating a payment"}],
    "links":[
                   {"href":"xxxxxxx","rel":"self","method":"GET"},
              {"href":"xxxxxxx","rel":"approval_url","method":"REDIRECT"},
              {"href":"xxxxxxx","rel":"execute","method":"POST"}]}
于 2014-06-19T10:36:29.883 回答