Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsedResult
LOCAL i
lnSuccess = 0
* 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.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/reporting/balances",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsedResult = loResult.Load(loResp.BodyStr)
IF (lnParsedResult <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
? "Last refresh: " + loResult.StringOf("last_refresh_time")
i = 0
DO WHILE (i < loResult.SizeOfArray("balances"))
loResult.I = i
? loResult.StringOf("balances[i].currency") + " total " + loResult.StringOf("balances[i].total_balance.value") + " available " + loResult.StringOf("balances[i].available_balance.value") + " withheld " + loResult.StringOf("balances[i].withheld_balance.value")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loResp
RELEASE loErrorInfo
RELEASE loResult