php - 如何使用 PayPal Express Payments (PHP)
问题描述
我正在使用此处找到的 PayPal PHP SDK:https ://github.com/paypal/Checkout-PHP-SDK
我对如何完成这个过程有些困惑。
一开始,这似乎很简单:
- 设置您的凭据
- 创建订单
- 检查结果,并重定向到批准链接
- 用户付款并被发送到您设置的成功链接。
即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 是什么,我从哪里得到它?
谢谢!
解决方案
这个 APPROVED-ORDER-ID 是什么,我从哪里得到它
在那一刻,来自token=
. 它应该对应于您在步骤 2(“创建订单”)的响应中收到的订单 ID
对于第 3 步,最好不要使用任何重定向。相反,实现这个前端 UI,它提供了一个非常出色的上下文体验,让您的网站在后台加载:https ://developer.paypal.com/demo/checkout/#/pattern/server
现代网站没有理由进行不必要的重定向
推荐阅读
- firebase - 使用 Flutter 同步 Firestore 时在 Null 上调用了方法 []
- .net - 使用 .Net Framework 运行 .Net Core 应用程序
- vue.js - 尝试在strapi中忘记密码时出现400错误
- kestrel-http-server - Kestrel 服务器日志在哪里?
- javascript - 选定日期后 3 天自动在字段中显示日期
- c# - 获取选定选项卡文本的事件处理程序在后台更新线程中引发错误
- reactjs - 如何在移动屏幕中将组件移动到中心反应
- javascript - 如果我的字符串测试函数的输入为空,则返回 false
- asp.net-core - 将子域重定向到子目录(.Net Core App)
- python - ModuleNotFoundError:没有名为“psycopg2.errors”的模块