AutoIt Requires Chilkat v11.0.0+
AutoIt
PayPal: Show available, withheld and total balances by currency
See more PayPal Examples
Read the merchant balance snapshot using reporting access. Keep each currency separate and show the last refresh time so accounting knows when PayPal last updated the figures.
Chilkat AutoIt Downloads
Local $bSuccess = False
; See Unlock Chilkat before making requests.
; For the merchant's internal backoffice application. Load the sandbox token
; from the merchant's credential store. Keep it out of publicly distributed apps.
; See Get a PayPal access token.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/reporting/balances",$oResp)
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
Exit
EndIf
If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
$oErrorInfo = ObjCreate("Chilkat.JsonObject")
$oErrorInfo.Load($oResp.BodyStr)
ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
Exit
EndIf
$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsedResult = $oResult.Load($oResp.BodyStr)
If ($bParsedResult <> True) Then
ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
Exit
EndIf
ConsoleWrite("Last refresh: " & $oResult.StringOf("last_refresh_time") & @CRLF)
Local $i = 0
While ($i < $oResult.SizeOfArray("balances"))
$oResult.I = $i
ConsoleWrite($oResult.StringOf("balances[i].currency") & " total " & $oResult.StringOf("balances[i].total_balance.value") & " available " & $oResult.StringOf("balances[i].available_balance.value") _
& " withheld " & $oResult.StringOf("balances[i].withheld_balance.value") & @CRLF)
$i = $i + 1
Wend