From 8b09c9242786c89c230648527d39fbdf0276fc5c Mon Sep 17 00:00:00 2001 From: Shulhan Date: Wed, 30 Nov 2022 11:38:02 +0700 Subject: all: do not check for response Code on transfer As long as the response body is valid, return it to caller and let them check the response code manually. This is to allow user to log the request and full response. --- client.go | 20 ++++++++++---------- response.go | 8 +++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client.go b/client.go index 938ac32..e23d939 100644 --- a/client.go +++ b/client.go @@ -83,7 +83,7 @@ func (cl *Client) CheckBalance() (bal *Balance, err error) { if err != nil { return nil, fmt.Errorf(`%s: %s`, logp, err) } - if bal.Code != resCodeSuccess { + if bal.Code != ResCodeSuccess { return nil, fmt.Errorf(`%s: %s: %s`, logp, bal.Code, bal.Desc) } @@ -121,7 +121,7 @@ func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryRes if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if res.Code != resCodeSuccess { + if res.Code != ResCodeSuccess { return nil, fmt.Errorf(`%s: %s: %s`, logp, res.Code, res.Desc) } @@ -133,6 +133,9 @@ func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryRes // // The following fields are set from response: AccountName, CustRefNumber, // DisburseID, and Type. +// +// Return without an error does not mean the transfer success, you need to +// check the response Code. func (cl *Client) ClearingTransfer(inquiryReq *ClearingInquiry, inquiryRes *ClearingInquiryResponse) ( transferRes *ClearingTransferResponse, err error, ) { @@ -165,9 +168,6 @@ func (cl *Client) ClearingTransfer(inquiryReq *ClearingInquiry, inquiryRes *Clea if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if transferRes.Code != resCodeSuccess { - return nil, fmt.Errorf(`%s: %s: %s`, logp, transferRes.Code, transferRes.Desc) - } return transferRes, nil } @@ -201,7 +201,7 @@ func (cl *Client) ListBank() (banks []Bank, err error) { if err != nil { return nil, fmt.Errorf(`%s: %s`, logp, err) } - if res.Code != resCodeSuccess { + if res.Code != ResCodeSuccess { return nil, fmt.Errorf(`%s: %s: %s`, logp, res.Code, res.Desc) } @@ -263,7 +263,7 @@ func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err e if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if res.Code != resCodeSuccess { + if res.Code != ResCodeSuccess { return nil, fmt.Errorf(`%s: %s: %s`, logp, res.Code, res.Desc) } @@ -276,6 +276,9 @@ func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err e // Transfer will be limited from 25 to 50 Million per transaction depending on // the beneficiary bank account. // +// Return without an error does not mean the transfer success, you need to +// check the response Code. +// // Ref: https://docs.duitku.com/disbursement/en/#online-transfer-transfer-request func (cl *Client) RtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryResponse) (res *RtolTransferResponse, err error) { var ( @@ -308,9 +311,6 @@ func (cl *Client) RtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryR 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 } diff --git a/response.go b/response.go index 1474ae2..6fb5049 100644 --- a/response.go +++ b/response.go @@ -3,8 +3,9 @@ package duitku +// List of known response code. const ( - resCodeSuccess = `00` // Approved or completed successfully. + ResCodeSuccess = `00` // Approved or completed successfully. resCodeError = `EE` // General Error. resCodeErrTimeout = `TO` // Response time out from ATM Bersama Network (Do not retry). resCodeErrLink = `LD` // Link problem between Duitku and ATM Bersama Network. @@ -36,3 +37,8 @@ type Response struct { Code string `json:"responseCode"` Desc string `json:"responseDesc"` } + +// IsSuccess return true if the response code equal to 00. +func (res *Response) IsSuccess() bool { + return res.Code == ResCodeSuccess +} -- cgit v1.3