B4X Requires Chilkat v11.0.0+
B4X
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 B4X Downloads
Dim success As Boolean = 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.
Dim http As ChilkatHttp
http.Initialize("http")
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
Dim resp As ChilkatHttpResponse
resp.Initialize
success = http.HttpNoBody("GET", "https://api-m.sandbox.paypal.com/v1/reporting/balances", resp)
If success <> True Then
Log("No HTTP response: " & http.LastErrorText)
Return
End If
If (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
Dim errorInfo As ChilkatJsonObject
errorInfo.Initialize
errorInfo.Load(resp.BodyStr)
Log("HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue"))
Log("PayPal debug ID: " & errorInfo.StringOf("debug_id"))
Return
End If
Dim result As ChilkatJsonObject
result.Initialize
Dim parsedResult As Boolean = result.Load(resp.BodyStr)
If parsedResult <> True Then
Log("Expected a JSON response; HTTP " & resp.StatusCode)
Return
End If
Log("Last refresh: " & result.StringOf("last_refresh_time"))
Dim i As Int = 0
Do While (i < result.SizeOfArray("balances"))
result.I = i
Log(result.StringOf("balances[i].currency") & " total " & result.StringOf("balances[i].total_balance.value") & " available " & result.StringOf("balances[i].available_balance.value") & " withheld " & result.StringOf("balances[i].withheld_balance.value"))
i = i + 1
Loop