bca

package module
v0.0.0-...-8976aea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2018 License: MIT Imports: 12 Imported by: 0

README

🏦 BCA (Bank Central Asia) API's Go Library

Library Status Go Report Card MIT license Build Status

Go(lang) library to speed up your BCA (Bank Central Asia) API integration process. See this official documentation of BCA API

Usage

import (
	"context"

	"github.com/haritsfahreza/go-bca"
	"github.com/haritsfahreza/go-bca/business"
)

func main() {
    cfg := bca.Config{
		URL:          "https://sandbox.bca.co.id",
		ClientID:     "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
		ClientSecret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
		APIKey:       "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
		APISecret:    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
		CorporateID:  "BCAAPI2016", //Based on API document
		OriginHost:   "localhost",
	}
	businessClient := business.NewClient(cfg)
	authClient := auth.NewClient(cfg)

	ctx := context.Background()
	authToken, err := authClient.GetToken(ctx)
	if err != nil {
		panic(err)
	}

    businessClient.AccessToken = authToken.AccessToken

    ctx := context.Background()
    response, err := client.GetBalanceInfo(ctx, []string{"0201245680", "0063001004"})
}

Example

We have attached usage examples in this repository in folder example. Please proceed there for more detail on how to run the example.

License

See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountBalance

type AccountBalance struct {
	AccountNumber    string
	Currency         string  `json:",omitempty"`
	Balance          float64 `json:",string"`
	AvailableBalance float64 `json:",string"`
	FloatAmount      float64 `json:",string"`
	HoldAmount       float64 `json:",string"`
	Plafon           float64 `json:",string"`
	Indonesian       string  `json:",omitempty"`
	English          string  `json:",omitempty"`
}

AccountBalance represents account balance information

type AccountStatement

type AccountStatement struct {
	TransactionDate   string
	BranchCode        string
	TransactionType   string
	TransactionAmount float64 `json:",string"`
	TransactionName   string
	Trailer           string
}

AccountStatement represents account statement information

type AccountStatementResponse

type AccountStatementResponse struct {
	Error
	StartDate    string
	EndDate      string
	Currency     string
	StartBalance float64 `json:",string"`
	Data         []AccountStatement
}

AccountStatementResponse represents account statement response message

type AuthToken

type AuthToken struct {
	Error
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in"`
	Scope       string `json:"scope"`
}

AuthToken represents response of BCA OAuth 2.0 response message

type BalanceInfoResponse

type BalanceInfoResponse struct {
	Error
	AccountDetailDataSuccess []AccountBalance `json:",omitempty"`
	AccountDetailDataFailed  []AccountBalance `json:",omitempty"`
}

BalanceInfoResponse represents account balance information response message

type Client

type Client interface {
	Call(method, path string, body io.Reader, v interface{}) error
	CallRaw(method, path string, headers http.Header, body io.Reader, v interface{}) error
}

Client is an interface for making call to BCA API

type ClientImplementation

type ClientImplementation struct {
	APIKey     string
	APISecret  string
	OriginHost string
	URL        string
	HTTPClient *http.Client
	LogLevel   int
	Logger     *log.Logger
}

ClientImplementation represents config that used for HTTP client needs

func NewClient

func NewClient(cfg Config) ClientImplementation

NewClient is used to initialize new ClientImplementation

func (*ClientImplementation) Call

func (c *ClientImplementation) Call(method, path, accessToken string, body io.Reader, v interface{}) error

Call is the implementation for invoking BCA API with its authentication

func (*ClientImplementation) CallRaw

func (c *ClientImplementation) CallRaw(method, path, contentType string, headers http.Header, body io.Reader, v interface{}) error

CallRaw is the implementation for invoking API without any wrapper

func (*ClientImplementation) Do

func (c *ClientImplementation) Do(req *http.Request, v interface{}) error

Do is used by Call to execute BCA HTTP request and parse the response

func (*ClientImplementation) NewRequest

func (c *ClientImplementation) NewRequest(method, path, contentType string, headers http.Header, body io.Reader) (*http.Request, error)

NewRequest is used to create new HTTP request of BCA API

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	APIKey       string
	APISecret    string
	URL          string
	CorporateID  string
	OriginHost   string
	LogLevel     int
}

Config represents configuration that needed by BCA API

type Error

type Error struct {
	ErrorCode    string
	ErrorMessage ErrorLang
}

Error represent BCA error response messsage

type ErrorLang

type ErrorLang struct {
	Indonesian string
	English    string
}

ErrorLang represent BCA error response message language

type FundTransferRequest

type FundTransferRequest struct {
	CorporateID              string
	SourceAccountNumber      string
	TransactionID            string
	TransactionDate          string
	ReferenceID              string
	CurrencyCode             string
	Amount                   float64 `json:",string"`
	BeneficiaryAccountNumber string
	Remark1                  string
	Remark2                  string
}

FundTransferRequest represents fund transfer request message

type FundTransferResponse

type FundTransferResponse struct {
	Error
	TransactionID   string
	TransactionDate string
	ReferenceID     string
	Status          string
}

FundTransferResponse represents fund transfer response message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL