我已经在 PayPal 文档中搜索了两个小时,但找不到答案,甚至搜索了 Google。
在这里检查: https://developer.paypal.com/docs/api/#api-operations
我已经在 Maven (REST API) 中添加了 PayPal 的 SDK,现在我不确定该怎么做。
我想使用 PayPal API(所有货币)获取账户余额。
最佳答案
GetBalance来自Classsic 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;
}
?>
关于java - 获取 PayPal 余额 (GetBalance API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31897393/