aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-11-07 11:55:20 +0700
committerShulhan <ms@kilabit.info>2022-11-07 11:59:50 +0700
commiteb3c3fc6b20b77c26a571395f584efdce8cfb4f7 (patch)
tree0eb6fc3a9435a93f8bf6a33fa9c8cf4b7ed93b02 /client.go
parentab25f641e3343151839cf2624d19ef235a070c9d (diff)
downloadduitku-eb3c3fc6b20b77c26a571395f584efdce8cfb4f7.tar.xz
all: implement client API for Clearing Inquiry
The ClearingInquiry method is used to initiate the transfer for Clearing using LLG, RTGS, H2H, or BI-FAST.
Diffstat (limited to 'client.go')
-rw-r--r--client.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/client.go b/client.go
index 789f8fb..47cc88d 100644
--- a/client.go
+++ b/client.go
@@ -26,6 +26,13 @@ const (
PathDisbursementTransfer = `/disbursement/transfer`
PathDisbursementTransferSandbox = `/disbursement/transfersandbox` // Used for testing.
+
+ // Paths for Clearing.
+ PathDisbursementInquiryClearing = `/disbursement/inquiryclearing`
+ PathDisbursementInquiryClearingSandbox = `/disbursement/inquiryclearingsandbox` // Used for testing.
+
+ PathDisbursementTransferClearing = `/disbursement/transferclearing`
+ PathDisbursementTransferClearingSandbox = `/disbursement/transferclearingsandbox` // Used for testing.
)
type Client struct {
@@ -85,6 +92,46 @@ func (cl *Client) CheckBalance() (bal *Balance, err error) {
return bal, nil
}
+// ClearingInquiry initiate the transfer for Clearing using LLG, RTGS, H2H, or
+// BI-FAST.
+func (cl *Client) ClearingInquiry(req ClearingInquiry) (res *ClearingInquiryResponse, err error) {
+ var (
+ logp = `ClearingInquiry`
+ path = PathDisbursementInquiryClearing
+
+ httpRes *http.Response
+ resBody []byte
+ )
+
+ req.sign(cl.opts)
+
+ // Since the path is different in test environment, we check the host
+ // here to set it.
+ if cl.opts.host != hostLive {
+ path = PathDisbursementInquiryClearingSandbox
+ }
+
+ httpRes, resBody, err = cl.PostJSON(path, nil, req)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+ if httpRes.StatusCode >= 500 {
+ return nil, fmt.Errorf(`%s: %s`, logp, httpRes.Status)
+ }
+
+ fmt.Printf(`%s: resBody: %s\n`, logp, resBody)
+
+ err = json.Unmarshal(resBody, &res)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %w`, logp, err)
+ }
+ if res.Code != resCodeSuccess {
+ return nil, fmt.Errorf(`%s: %s: %s`, logp, res.Code, res.Desc)
+ }
+
+ return res, nil
+}
+
// tListBank fetch list of banks for disbursement.
func (cl *Client) ListBank() (banks []Bank, err error) {
var (