Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.0.0+

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.

PayPal documentation

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 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.
set http = Server.CreateObject("Chilkat.Http")
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
set resp = Server.CreateObject("Chilkat.HttpResponse")

success = http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/reporting/balances",resp)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response: " & http.LastErrorText) & "</pre>"
    Response.End
End If

If ((resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    set errorInfo = Server.CreateObject("Chilkat.JsonObject")
    success = errorInfo.Load(resp.BodyStr)
    Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue")) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "PayPal debug ID: " & errorInfo.StringOf("debug_id")) & "</pre>"
    Response.End
End If

set result = Server.CreateObject("Chilkat.JsonObject")
parsedResult = result.Load(resp.BodyStr)
If (parsedResult <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response; HTTP " & resp.StatusCode) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Last refresh: " & result.StringOf("last_refresh_time")) & "</pre>"
i = 0
Do While (i < result.SizeOfArray("balances"))
    result.I = i
    Response.Write "<pre>" & Server.HTMLEncode( 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")) & "</pre>"
    i = i + 1
Loop

%>
</body>
</html>