获取 PayPal 余额 (GetBalance API)

Sys*_*oid 2 java api paypal

我已经在 PayPal 文档中搜索了两个小时,但找不到答案,甚至还搜索了谷歌。

在这里检查:https : //developer.paypal.com/docs/api/#api-operations

我已经在 Maven (REST API) 中添加了 PayPal 的 SDK,现在我不确定该怎么做。

我想使用 PayPal API(所有货币)获取帐户余额。

pp_*_*uan 5

GetBalance 来自 Classsic API,目前尚未包含在 REST API 中,但您可以直接使用 HTTPRequest 实现 NVP 调用,如下所示,

API 端点:

https://api-3t.paypal.com/nvp
Run Code Online (Sandbox Code Playgroud)

POST 请求负载:

USER=seller_api1.paypal.com
&PWD=56A9R4JPVFPMER2X
&SIGNATURE=AFcWxV21C7fd0v3bYYYRCpSSRl31AociN2kspFBnMbzOGg6NdiC7ZXtg
&VERSION=109.0
&METHOD=GetBalance
&RETURNALLCURRENCIES=1
Run Code Online (Sandbox Code Playgroud)

回复:

L_AMT0=265.17
L_CURRENCYCODE0=USD
TIMESTAMP=2015-08-09T14:21:25Z
CORRELATIONID=802b0b6666022
ACK=Success
VERSION=109.0
BUILD=000000
Run Code Online (Sandbox Code Playgroud)

您也可以使用您喜欢的编程语言获取Classic API SDK,这次选择“Merchant”SDK。

我的示例 PHP 代码可帮助您了解流程,

<?php
$version = "124";
$user = "API UserName";
$pwd = "API Password";
$signature = "API Signature";
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";

$resArray = CallGetBalance ( $API_Endpoint, $version, $user, $pwd, $signature );
$ack = strtoupper ( $resArray ["ACK"] );
if ($ack == "SUCCESS") {
    $balance = urldecode ( $resArray ["L_AMT0"] );
    $currency = urldecode ( $resArray ["L_CURRENCYCODE0"] );
    echo "Account Balance: " . $balance . " " . $currency;
}


function CallGetBalance($API_Endpoint, $version, $user, $pwd, $signature) {
    // setting the curl parameters.
    $ch = curl_init ();
    curl_setopt ( $ch, CURLOPT_URL, $API_Endpoint );
    curl_setopt ( $ch, CURLOPT_VERBOSE, 1 );
    curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
    curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
    curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt ( $ch, CURLOPT_POST, 1 );

    // NVPRequest for submitting to server
    $nvpreq = "METHOD=GetBalance" . "&RETURNALLCURRENCIES=1" . "&VERSION=" . $version . "&PWD=" . $pwd . "&USER=" . $user . "&SIGNATURE=" . $signature;
    curl_setopt ( $ch, CURLOPT_POSTFIELDS, $nvpreq );
    $response = curl_exec ( $ch );

    $nvpResArray = deformatNVP ( $response );

    curl_close ( $ch );

    return $nvpResArray;
}

/*
 * This function will take NVPString and convert it to an Associative Array and it will decode the response. It is usefull to search for a particular key and displaying arrays. @nvpstr is NVPString. @nvpArray is Associative Array.
 */
function deformatNVP($nvpstr) {
    $intial = 0;
    $nvpArray = array ();

    while ( strlen ( $nvpstr ) ) {
        // postion of Key
        $keypos = strpos ( $nvpstr, '=' );
        // position of value
        $valuepos = strpos ( $nvpstr, '&' ) ? strpos ( $nvpstr, '&' ) : strlen ( $nvpstr );

        /* getting the Key and Value values and storing in a Associative Array */
        $keyval = substr ( $nvpstr, $intial, $keypos );
        $valval = substr ( $nvpstr, $keypos + 1, $valuepos - $keypos - 1 );
        // decoding the respose
        $nvpArray [urldecode ( $keyval )] = urldecode ( $valval );
        $nvpstr = substr ( $nvpstr, $valuepos + 1, strlen ( $nvpstr ) );
    }
    return $nvpArray;
}

?>
Run Code Online (Sandbox Code Playgroud)


Juh*_*nia 5

因此,对于其他正在努力解决这个问题的人来说,文档的“交易搜索”部分下有一个 API 端点,这根本没有任何意义。

GET /v1/reporting/balances
Run Code Online (Sandbox Code Playgroud)

您将获得一份余额列表,其中包含您帐户中维护的每种货币的余额。

请参阅此处的文档:

https://developer.paypal.com/docs/api/transaction-search/v1/

  • 这仅适用于 PayPal 合作伙伴网络中的人员。“使用交易搜索 API 获取 PayPal 帐户的交易历史记录。要代表第三方使用 API,您必须是 PayPal 合作伙伴网络的一部分。请联系您的合作伙伴经理以了解后续步骤。要注册在合作伙伴计划中,请参阅与 PayPal 合作。有关 API 的更多信息,请参阅交易搜索 API 集成指南。- [交易API文档](https://developer.paypal.com/docs/api/transaction-search/v1/) (2认同)