首页 > 解决方案 > 如何使用 PayPal Express Payments (PHP)

问题描述

我正在使用此处找到的 PayPal PHP SDK:https ://github.com/paypal/Checkout-PHP-SDK

我对如何完成这个过程有些困惑。

一开始,这似乎很简单:

  1. 设置您的凭据
  2. 创建订单
  3. 检查结果,并重定向到批准链接
  4. 用户付款并被发送到您设置的成功链接。

http://example.com/pay/complete/paypal?token=8UK32254ES097084V&PayerID=SEQNPLB2JR9LY

这就是事情变得有点不稳定的地方。

方便的是,返回一个令牌和一个 PayerID。

根据文档,您现在需要“捕获订单”并提供以下代码:

use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
// Here, OrdersCaptureRequest() creates a POST request to /v2/checkout/orders
// $response->result->id gives the orderId of the order created above
$request = new OrdersCaptureRequest("APPROVED-ORDER-ID");
$request->prefer('return=representation');
try {
    // Call API with your client and get a response for your call
    $response = $client->execute($request);
    
    // If call returns body in response, you can get the deserialized version from the result attribute of the response
    print_r($response);
}catch (HttpException $ex) {
    echo $ex->statusCode;
    print_r($ex->getMessage());
}

令人困惑的是,OrdersCaptureRequest 需要一个“APPROVED-ORDER-ID”

但返回的只是一个“令牌”和一个“PayerID”。

所以我的问题是,这个 APPROVED-ORDER-ID 是什么,我从哪里得到它?

谢谢!

标签: phppaypal

解决方案


这个 APPROVED-ORDER-ID 是什么,我从哪里得到它

在那一刻,来自token=. 它应该对应于您在步骤 2(“创建订单”)的响应中收到的订单 ID


对于第 3 步,最好不要使用任何重定向。相反,实现这个前端 UI,它提供了一个非常出色的上下文体验,让您的网站在后台加载:https ://developer.paypal.com/demo/checkout/#/pattern/server

现代网站没有理由进行不必要的重定向


推荐阅读