Sample code for 30+ languages & platforms
Go 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 Go Downloads

Go
    success := 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.
    http := chilkat.NewHttp()
    http.SetAuthToken("SANDBOX_ACCESS_TOKEN")
    resp := chilkat.NewHttpResponse()

    success = http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/reporting/balances",resp)
    if success != true {
        fmt.Println("No HTTP response: ", http.LastErrorText())
        http.DisposeHttp()
        resp.DisposeHttpResponse()
        return
    }

    if (resp.StatusCode() < 200) || (resp.StatusCode() >= 300) {
        errorInfo := chilkat.NewJsonObject()
        errorInfo.Load(resp.BodyStr())
        fmt.Println("HTTP ", resp.StatusCode(), " ", *errorInfo.StringOf("name"), " ", *errorInfo.StringOf("details[0].issue"))
        fmt.Println("PayPal debug ID: ", *errorInfo.StringOf("debug_id"))
        http.DisposeHttp()
        resp.DisposeHttpResponse()
        errorInfo.DisposeJsonObject()
        return
    }

    result := chilkat.NewJsonObject()
    parsedResult := result.Load(resp.BodyStr())
    if parsedResult != true {
        fmt.Println("Expected a JSON response; HTTP ", resp.StatusCode())
        http.DisposeHttp()
        resp.DisposeHttpResponse()
        errorInfo.DisposeJsonObject()
        result.DisposeJsonObject()
        return
    }

    fmt.Println("Last refresh: ", *result.StringOf("last_refresh_time"))
    i := 0
    for (i < result.SizeOfArray("balances")) {
        result.SetI(i)
        fmt.Println(*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
    }


    http.DisposeHttp()
    resp.DisposeHttpResponse()
    errorInfo.DisposeJsonObject()
    result.DisposeJsonObject()