Ale*_*ini 5 php curl paypal paypal-sandbox
https://api.sandbox.paypal.com/v2/checkout/orders我正在使用 PHP 和 cURL 集成 PayPal,并设法通过和
https://api.sandbox.paypal.com/v2/checkout/orders/<order_id>/capture端点创建订单并捕获付款
我尝试退款的订单已成功捕获,查看详细信息,显示其状态为“已完成”并且 Final_capture 字段为 true,因此订单已下达,我可以在商家帐户中看到交易成功结束
现在,我尝试使用从捕获调用中获得的捕获 ID 来测试退款,但它总是失败,并出现以下响应正文错误
{
"error":"invalid_subject",
"error_description":"Subject Authentication failed"
}
我追踪到主题身份验证失败问题背后的问题是错误的 Paypal-Auth-Assertion 标头,我已经打印并仔细检查了多次,它似乎是正确的。这是我用来拨打电话的代码
// Codeigniter function to read from $_POST
$capture_id = $this->input->post('paypal_capture_id');
$auth_1 = base64_encode("{\"alg\":\"none\"}");
$auth_2 = base64_encode("{\"payer_id\":<payer_id>,\"iss\":<client_id>}");
$auth_assertion_header = $auth_1 . "." . $auth_2 . ".";
$curlSES=curl_init();
curl_setopt($curlSES,CURLOPT_URL,"https://api.sandbox.paypal.com/v2/payments/captures/$capture_id/refund");
curl_setopt($curlSES, CURLOPT_POST, true);
curl_setopt($curlSES, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '. $access_token,
'PayPal-Auth-Assertion:' . $auth_assertion_header
));
curl_setopt($curlSES, CURLOPT_POSTFIELDS, '{}'); // empty payload means full refund
curl_setopt($curlSES, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($curlSES);
Run Code Online (Sandbox Code Playgroud)
其中 payer_id 和 client_id 使用用于沙箱环境的商家 ID 帐户填写,而 client_id 是 Paypal 提供的应用程序的秘密 ID,$access_token 之前是从我在应用程序的其他部分中使用的函数生成的,它工作正常。
此外,如果我尝试使用 Postman(以及PayPal API 浏览器)进行相同的调用,它会产生不同的错误,即
{
"error": "invalid_request",
"error_description": "No permissions to set target_client_id"
}
Run Code Online (Sandbox Code Playgroud)
此错误的搜索结果没有真正的帮助,所以我迷失了我在那里做错的事情,尽管它似乎与 Paypal-Auth-Assertion 无关,因为如果我提供,它会回退到主题身份验证失败错误故意输入错误的值。
小智 0
当我尝试对合作伙伴帐户的捕获订单进行退款时,我遇到了同样的问题。在我看来,您正在使用示例中转义的字符串 json 。尝试使用 json_encode 函数,如下所示:
$header = base64_encode(json_encode(['alg' => 'none']));
$body = base64_encode(json_encode(['payer_id' => $merchantId, 'iss' => $clientId]));
$authHeader = $header . "." . $body . ".";
Run Code Online (Sandbox Code Playgroud)
我能够使用此 $authHeader 对捕获的订单进行退款。
问候
| 归档时间: |
|
| 查看次数: |
1232 次 |
| 最近记录: |