小编Ale*_*ini的帖子

无法使用 Paypal API 退款

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); …
Run Code Online (Sandbox Code Playgroud)

php curl paypal paypal-sandbox

5
推荐指数
1
解决办法
1232
查看次数

标签 统计

curl ×1

paypal ×1

paypal-sandbox ×1

php ×1