Xendit Go library is a way for you to integrate Xendit products using your Go application!

Xendit Go library currently supports these products:

  • Credit / Debit Cards (via Payments API)
  • E-Wallets (via Payments API)
  • Virtual Accounts (via Payments API)
  • Retail Outlets (via Payments API)
  • QR Code (via Payments API)
  • Customers
  • Invoices
  • Payouts
  • Balances
  • Transactions


Install xendit-go with:

go get github.com/xendit/xendit-go/v4

Put the package under your project folder and add the following in import:

import xendit "github.com/xendit/xendit-go/v4"

Check out our Go library source on Github for the complete installation guide and to verify the latest version.


The SDK needs to be instantiated using your secret API key obtained from the Xendit Dashboard. You can sign up for a free Dashboard account here.

xnd := xendit.NewClient("API-KEY")

Sample Usage

You can use the APIs below to interface with Xendit's BalanceApi. To start using the API, you need to configure the secret key and initiate the client instance.

package main

import (
    xendit "github.com/xendit/xendit-go/v4"
    balance_and_transaction "github.com/xendit/xendit-go/v4/balance_and_transaction"

func main() {
    // The selected balance type
    // (default to "CASH")
    accountType := "CASH" // [OPTIONAL] | string

    // Currency for filter for customers with multi currency accounts
    currency := "IDR" // [OPTIONAL] | string

    // The sub-account user-id that you want to make this transaction for. This header
    // is only used if you have access to xenPlatform. See xenPlatform for more
    // information
    forUserId := "5dbf20d7c8eb0c0896f811b6" // [OPTIONAL] | string

    xenditClient := xendit.NewClient("API-KEY")

    resp, r, err := xenditClient.BalanceApi.GetBalance(context.Background()).
        ForUserId(forUserId). // [OPTIONAL]

    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `BalanceApi.GetBalance``: %v\n", err.Error())

        b, _ := json.Marshal(err.FullError())
        fmt.Fprintf(os.Stderr, "Full Error Struct: %v\n", string(b))

        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
    // response from `GetBalance`: Balance
    fmt.Fprintf(os.Stdout, "Response from `BalanceApi.GetBalance`: %v\n", resp)

For sample of other available APIs, please refer to our Go SDK Github Documentation.

Last Updated on 2024-01-09