我已经在 PayPal 文档中搜索了两个小时,但找不到答案,甚至搜索了 Google。
在这里检查: https://developer.paypal.com/docs/api/#api-operations
我已经在 Maven(REST API)中添加了 PayPal 的 SDK,现在我不确定该怎么做。
我想使用 PayPal API(所有货币)获取帐户余额。
GetBalance 来自经典 API,目前尚未包含在 REST API 中,但您可以像这样直接使用 HTTPRequest 实现 NVP 调用,
API端点:
https://api-3t.paypal.com/nvp
POST 请求负载:
USER=seller_api1.paypal.com
&PWD=56A9R4JPVFPMER2X
&SIGNATURE=AFcWxV21C7fd0v3bYYYRCpSSRl31AociN2kspFBnMbzOGg6NdiC7ZXtg
&VERSION=109.0
&METHOD=GetBalance
&RETURNALLCURRENCIES=1
回应:
L_AMT0=265.17
L_CURRENCYCODE0=USD
TIMESTAMP=2015-08-09T14:21:25Z
CORRELATIONID=802b0b6666022
ACK=Success
VERSION=109.0
BUILD=000000
您也可以使用您喜欢的编程语言获取Classic API SDKs,这次选择“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;
}
?>
因此,对于其他正在解决这个问题的人来说,文档的“交易搜索”部分下有一个 API 端点,这根本没有任何意义。
GET /v1/reporting/balances
您将获得一份余额列表,其中包含您在帐户中维护的每种货币的余额。
请参阅此处的文档:
https://developer.paypal.com/docs/api/transaction-search/v1/
这个答案适用于那些正在寻找 Node js 的 REST API 或没有任何 SDK 的人。
GetBalance(获取特定帐户的余额)
文档链接:https://developer.paypal.com/docs/limited-release/balance-accounts/v2/api/
REST API [获取]:https://api.sandbox.paypal.com/v2/wallet/balance-accounts
需求:
curl -v -X GET https://api.sandbox.paypal.com/v2/wallet/balance-accounts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token"
回复:
{
"total_available": {
"currency_code": "USD",
"value": "2800"
},
"total_reserved": {
"currency_code": "USD",
"value": "1920"
},
"balance_accounts": [
{
"available": {
"currency_code": "USD",
"value": "1000.00"
},
"reserved": {
"currency_code": "USD",
"value": "00.00"
},
"links": []
},
{
"available": {
"currency_code": "AUD",
"value": "1000"
},
"reserved": {
"currency_code": "AUD",
"value": "00.00"
}
},
{
"available": {
"currency_code": "CAD",
"value": "1000"
},
"reserved": {
"currency_code": "CAD",
"value": "100"
},
"links": []
},
{
"available": {
"currency_code": "GBP",
"value": "1000"
},
"reserved": {
"currency_code": "GBP",
"value": "1000"
},
"links": []
}
],
"links": [
{
"rel": "self",
"href": "https://api.sandbox.paypal.com/v2/wallets/balance-accounts"
}
]
}
我一直在测试你们的答案,看起来这些方法是用来获取沙箱贝宝账户持有人的余额的。虽然我的目标是获取应用程序用户的帐户余额,但这可能吗?