This library is the abstraction of Xendit API for access from applications written with Go.
For the API documentation, check Xendit API Reference.
For the details of this library, see the GoDoc.
Install xendit-go with:
go get -u github.com/ianeinser/xendit-go
Then, import it using:
import (
"github.com/ianeinser/xendit-go"
"github.com/ianeinser/xendit-go/$product$"
)
with $product$
is the product of Xendit such as invoice
and balance
.
This library supports Go modules by default. Simply require xendit-go in go.mod
with a version like so:
module github.com/my/package
go 1.13
require (
github.com/ianeinser/xendit-go v1.0.0
)
And use the same style of import paths as above:
import (
"github.com/ianeinser/xendit-go"
"github.com/ianeinser/xendit-go/$product$"
)
with $product$
is the product of Xendit such as invoice
and balance
.
If you are still using $GOPATH
and not planning to migrate to go mod,
installing xendit-go
would require installing its (only) dependency validator
via
go get -u github.com/go-playground/validator
Please note that this means you are using master
of validator
and effectively miss out on its versioning that's gomod-based.
After installing validator, xendit-go can be installed normally.
The following pattern is applied throughout the library for a given $product$
:
If you're only dealing with a single secret key
, you can simply import the packages required for the products you're interacting with without the need to create a client.
import (
"github.com/ianeinser/xendit-go"
"github.com/ianeinser/xendit-go/$product$"
)
// Setup
xendit.Opt.SecretKey = "examplesecretkey"
xendit.SetAPIRequester(apiRequester) // optional, useful for mocking
// Create
resp, err := $product$.Create($product$.CreateParams)
// Get
resp, err := $product$.Get($product$.GetParams)
// GetAll
resp, err := $product$.GetAll($product$.GetAllParams)
If you're dealing with multiple secret key
s, it is recommended you use client.API
. This allows you to create as many clients as needed, each with their own individual key.
import (
"github.com/ianeinser/xendit-go"
"github.com/ianeinser/xendit-go/client"
)
// Basic setup
xenCli := client.New("examplesecretkey")
// or with optional, useful-for-mocking `exampleAPIRequester`
xenCli := client.New("examplesecretkey").WithAPIRequester(exampleAPIRequester)
// Create
resp, err := xenCli.$product$.Create($product$.CreateParams)
// Get
resp, err := xenCli.$product$.Get($product$.GetParams)
// GetAll
resp, err := xenCli.$product$.GetAll($product$.GetAllParams)
The following is a list of pointers to documentations for sub-packages of xendit-go.
- Invoice
- E-Wallet
- Balance
- Virtual Account
- Retail Outlet
- Disbursement
- Card
- Payout
- Recurring Payment
- Cardless Credit
- Customer
For any requests, bugs, or comments, please open an issue or submit a pull request.
After modifying the code, please make sure that the code passes all test cases.
go test ./...
go test ./invoice
go test ./invoice -run TestCreateInvoice
SECRET_KEY=<your secret key> go run -race ./integration_test
Before making any commits, please install pre-commit. To install pre-commit, follow the installation steps.
After installing the pre-commit, please install the needed dependencies:
make init
After the code passes everything, please submit a pull request.