贝宝付款沙箱提供AUTHORIZATION_ERROR

时间:2019-05-15 06:26:37

标签: php api paypal

我正在使用PayPal付款沙盒API。在我的沙盒应用中,启用了付款。但是,当我点击API端点时,尽管我的AUTHORIZATION_ERRORclient_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帐户添加余额吗?

2 个答案:

答案 0 :(得分:0)

请按照以下步骤在您的sandbox account中加钱

  1. 使用您的沙盒帐户登录到Paypal沙盒。
  2. 点击我的帐户–>充值
  3. 点击帐户类型
  4. 输入金额

答案 1 :(得分:0)

您有时只会收到此错误吗?我认为他们的沙箱遇到了问题,因为自几天前以来,我的系统还大约有50%的时间收到此错误。您可以尝试向他们的服务器发送直接请求以确认这一点。

相关问题