我正在使用 PayPal 付款沙箱 API。在我的沙盒应用程序中,付款已启用。但是当我点击 API 端点时,它给出了AUTHORIZATION_ERROR虽然我的client_id&client_secret是正确的。以下是代码示例:
function get_paypal_auth_token($client_id, $client_secret) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERPWD, $client_id.":".$client_secret);
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result);
}
function create_paypal_payment($data) {
$client_id = "XXXXXX";
$client_secret = "XXXXXXXSECRET";
$auth_data = get_paypal_auth_token($client_id, $client_secret);
$url = "https://api.sandbox.paypal.com/v1/payments/payouts";
$data_json = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$auth_data->access_token));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);
curl_close($curl);
return json_decode($resp);
}
此 API 的预期结果应该与支出有关。
另外,我用另一个帐户的凭据尝试它,然后它给出了INSUFFICIENT_FUNDS错误。
那么谁能告诉我如何为我的 PayPal 帐户添加余额?
UYOU
狐的传说