diff options
| author | Shulhan <ms@kilabit.info> | 2022-11-18 18:05:19 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-11-18 18:05:19 +0700 |
| commit | 80af1ff2a264a875fbd8dbf0a0ae8926c1ef396e (patch) | |
| tree | 364f2b3ca4cfe8b43bfe13ad0614c660b090787e | |
| parent | f98eb44cd053677b921753912e1b908f4510b28d (diff) | |
| download | duitku-80af1ff2a264a875fbd8dbf0a0ae8926c1ef396e.tar.xz | |
all: export types RtolTransfer, ClearingTransfer and method Sign
The idea is to allow testing the client from other module without
using the provided APIs.
| -rw-r--r-- | clearing_inquiry.go | 4 | ||||
| -rw-r--r-- | clearing_transfer.go | 16 | ||||
| -rw-r--r-- | client.go | 14 | ||||
| -rw-r--r-- | rtol_inquiry.go | 4 | ||||
| -rw-r--r-- | rtol_transfer.go | 14 |
5 files changed, 30 insertions, 22 deletions
diff --git a/clearing_inquiry.go b/clearing_inquiry.go index f840f5e..6de3a2c 100644 --- a/clearing_inquiry.go +++ b/clearing_inquiry.go @@ -29,7 +29,9 @@ type ClearingInquiry struct { RtolInquiry } -func (inq *ClearingInquiry) sign(opts ClientOptions) { +// Sign the request, fill the UserID, Email, Timestamp, and generate the +// Signature. +func (inq *ClearingInquiry) Sign(opts ClientOptions) { inq.UserID = opts.UserID inq.Email = opts.Email inq.Timestamp = time.Now().UnixMilli() diff --git a/clearing_transfer.go b/clearing_transfer.go index 9124eac..52f23bc 100644 --- a/clearing_transfer.go +++ b/clearing_transfer.go @@ -11,7 +11,7 @@ import ( "time" ) -// clearingTransfer contains request parameter for Clearing Transfer. +// ClearingTransfer contains request parameter for Clearing Transfer. // // Formula to generate signature: // @@ -20,19 +20,19 @@ import ( // disburseId + apiKey) // // Ref: https://docs.duitku.com/disbursement/en/#clearing-transfer-request -type clearingTransfer struct { +type ClearingTransfer struct { Type string `json:"type"` - rtolTransfer + RtolTransfer } -// newClearingTransfer create clearingTransfer from Clearing Inquiry +// NewClearingTransfer create ClearingTransfer from Clearing Inquiry // request and response. // // The following fields are set from response: AccountName, CustRefNumber, // DisburseID, and Type. -func newClearingTransfer(inqReq *ClearingInquiry, inqRes *ClearingInquiryResponse) (trf *clearingTransfer) { - trf = &clearingTransfer{} +func NewClearingTransfer(inqReq *ClearingInquiry, inqRes *ClearingInquiryResponse) (trf *ClearingTransfer) { + trf = &ClearingTransfer{} trf.Amount = inqReq.Amount trf.BankAccount = inqReq.BankAccount @@ -47,7 +47,9 @@ func newClearingTransfer(inqReq *ClearingInquiry, inqRes *ClearingInquiryRespons return trf } -func (trf *clearingTransfer) sign(opts ClientOptions) { +// Sign the request, fill the UserID, Email, Timestamp, and generate the +// Signature. +func (trf *ClearingTransfer) Sign(opts ClientOptions) { var ( now = time.Now() @@ -101,7 +101,7 @@ func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryRes resBody []byte ) - req.sign(cl.opts) + req.Sign(cl.opts) // Since the path is different in test environment, we check the host // here to set it. @@ -139,13 +139,13 @@ func (cl *Client) ClearingTransfer(inquiryReq *ClearingInquiry, inquiryRes *Clea var ( logp = `ClearingTransfer` path = PathTransferClearing - transferReq = newClearingTransfer(inquiryReq, inquiryRes) + transferReq = NewClearingTransfer(inquiryReq, inquiryRes) httpRes *http.Response resBody []byte ) - transferReq.sign(cl.opts) + transferReq.Sign(cl.opts) // Since the path is different in test environment, we check the host // here to set it. @@ -244,7 +244,7 @@ func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err e path = PathInquirySandbox } - req.sign(cl.opts) + req.Sign(cl.opts) resHttp, resBody, err = cl.PostJSON(path, nil, req) if err != nil { @@ -277,7 +277,7 @@ func (cl *Client) RtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryR logp = `RtolTransfer` path = PathTransfer - req *rtolTransfer + req *RtolTransfer resHttp *http.Response resBody []byte ) @@ -288,8 +288,8 @@ func (cl *Client) RtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryR path = PathTransferSandbox } - req = newRtolTransfer(inquiryReq, inquiryRes) - req.sign(cl.opts) + req = NewRtolTransfer(inquiryReq, inquiryRes) + req.Sign(cl.opts) resHttp, resBody, err = cl.PostJSON(path, nil, req) if err != nil { diff --git a/rtol_inquiry.go b/rtol_inquiry.go index 5168cf8..a3b4ea9 100644 --- a/rtol_inquiry.go +++ b/rtol_inquiry.go @@ -41,7 +41,9 @@ type RtolInquiry struct { Amount int64 `json:"amountTransfer"` } -func (inq *RtolInquiry) sign(opts ClientOptions) { +// Sign the request, fill the UserID, Email, Timestamp, and generate the +// Signature. +func (inq *RtolInquiry) Sign(opts ClientOptions) { inq.UserID = opts.UserID inq.Email = opts.Email inq.Timestamp = time.Now().UnixMilli() diff --git a/rtol_transfer.go b/rtol_transfer.go index 9766092..4ba8718 100644 --- a/rtol_transfer.go +++ b/rtol_transfer.go @@ -11,7 +11,7 @@ import ( "time" ) -// rtolTransfer containts request to transfer amount from merchant to +// RtolTransfer containts request to transfer amount from merchant to // customer's bank account, using the previous data obtained from the inquiry // process. // @@ -20,7 +20,7 @@ import ( // disburseId + secretKey). // // Ref: https://docs.duitku.com/disbursement/en/#online-transfer-transfer-request -type rtolTransfer struct { +type RtolTransfer struct { // Bank Account owner, obtained after getting a response from the // inquiry process. AccountName string `json:"accountName"` @@ -48,10 +48,10 @@ type rtolTransfer struct { DisburseID int64 `json:"disburseId"` } -// newRtolTransfer create new rtolTransfer request from request and response +// NewRtolTransfer create new RtolTransfer request from request and response // of RtolInquiry. -func newRtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryResponse) (req *rtolTransfer) { - req = &rtolTransfer{ +func NewRtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryResponse) (req *RtolTransfer) { + req = &RtolTransfer{ Amount: inquiryReq.Amount, Purpose: inquiryReq.Purpose, @@ -64,7 +64,9 @@ func newRtolTransfer(inquiryReq *RtolInquiry, inquiryRes *RtolInquiryResponse) ( return req } -func (req *rtolTransfer) sign(opts ClientOptions) { +// Sign the request, fill the UserID, Email, Timestamp, and generate the +// Signature. +func (req *RtolTransfer) Sign(opts ClientOptions) { var ( now = time.Now() |
