Skip to content

Xendit REST API Client for Go - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services, QR Codes

License

Notifications You must be signed in to change notification settings

ianeinser/xendit-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xendit API Go Client

go.dev reference Coverage Status Go Report Card

This library is the abstraction of Xendit API for access from applications written with Go.

Documentation

For the API documentation, check Xendit API Reference.

For the details of this library, see the GoDoc.

Installation

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.

Go Module Support

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.

Using xendit-go with $GOPATH

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.

Usage

The following pattern is applied throughout the library for a given $product$:

Without Client

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)

With Client

If you're dealing with multiple secret keys, 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)

Sub-Packages Documentations

The following is a list of pointers to documentations for sub-packages of xendit-go.

Contribute

For any requests, bugs, or comments, please open an issue or submit a pull request.

Test

After modifying the code, please make sure that the code passes all test cases.

Run all tests

go test ./...

Run tests for a package

go test ./invoice

Run a single test

go test ./invoice -run TestCreateInvoice

Run integration tests

SECRET_KEY=<your secret key> go run -race ./integration_test

Pre-commit

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.

About

Xendit REST API Client for Go - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets Services, QR Codes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.9%
  • Makefile 0.1%