【发布时间】:2020-07-23 09:46:39
【问题描述】:
我正在使用 PHP 和 cURL 集成 PayPal,并通过https://api.sandbox.paypal.com/v2/checkout/orders 和
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);
其中 payer_id 和 client_id 使用用于沙盒环境的商家 id 帐户填充,client_id 是 Paypal 提供的应用程序的秘密 id,$access_token 之前是从我在其他部分使用的函数生成的应用程序,它工作正常。
此外,如果我尝试使用 Postman(以及 PayPal API explorer)进行相同的调用,则会产生不同的错误,即
{
"error": "invalid_request",
"error_description": "No permissions to set target_client_id"
}
没有针对此错误的搜索结果真的很有帮助,所以我不知道我在那里做错了什么,尽管它似乎与 Paypal-Auth-Assertion 无关,因为它回退到主题身份验证失败错误如果我故意提供错误的值。
【问题讨论】:
标签: php curl paypal paypal-sandbox