diff options
| author | Shulhan <ms@kilabit.info> | 2023-01-31 17:33:53 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-01-31 17:33:53 +0700 |
| commit | e59291fc07605b35e07174803a12b45365cd8fe8 (patch) | |
| tree | 9a3ec25df299313d3898bcafd20ef580223c0079 | |
| parent | 3153c1d5c2d43212a3c26c11f5a9567e68d95db2 (diff) | |
| download | duitku-e59291fc07605b35e07174803a12b45365cd8fe8.tar.xz | |
all: add prefix Disburse to UserID, Email, and ApiKey in ClientOptions
This is to differentiate options between Merchant and Disbursement.
| -rw-r--r-- | clearing_callback.go | 2 | ||||
| -rw-r--r-- | clearing_inquiry.go | 6 | ||||
| -rw-r--r-- | clearing_transfer.go | 6 | ||||
| -rw-r--r-- | client.go | 4 | ||||
| -rw-r--r-- | client_options.go | 27 | ||||
| -rw-r--r-- | duitku_test.go | 8 | ||||
| -rw-r--r-- | inquiry_status.go | 6 | ||||
| -rw-r--r-- | request.go | 8 | ||||
| -rw-r--r-- | rtol_inquiry.go | 6 | ||||
| -rw-r--r-- | rtol_transfer.go | 6 |
10 files changed, 42 insertions, 37 deletions
diff --git a/clearing_callback.go b/clearing_callback.go index 8a9fad0..27a94b0 100644 --- a/clearing_callback.go +++ b/clearing_callback.go @@ -73,7 +73,7 @@ func (cbres *ClearingCallbackResponse) Sign(opts ClientOptions) { bb.WriteString(cbres.AccountName) bb.WriteString(cbres.CustRefNumber) fmt.Fprintf(&bb, `%d%d`, cbres.Amount, cbres.DisburseID) - bb.WriteString(opts.ApiKey) + bb.WriteString(opts.DisburseApiKey) plainHash = sha256.Sum256(bb.Bytes()) diff --git a/clearing_inquiry.go b/clearing_inquiry.go index 6de3a2c..88830b1 100644 --- a/clearing_inquiry.go +++ b/clearing_inquiry.go @@ -32,14 +32,14 @@ type ClearingInquiry struct { // 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.UserID = opts.DisburseUserID + inq.Email = opts.DisburseEmail inq.Timestamp = time.Now().UnixMilli() var ( plain = fmt.Sprintf(`%s%d%s%s%s%d%s%s`, inq.Email, inq.Timestamp, inq.BankCode, inq.Type, - inq.BankAccount, inq.Amount, inq.Purpose, opts.ApiKey) + inq.BankAccount, inq.Amount, inq.Purpose, opts.DisburseApiKey) plainHash [sha256.Size]byte = sha256.Sum256([]byte(plain)) ) inq.Signature = hex.EncodeToString(plainHash[:]) diff --git a/clearing_transfer.go b/clearing_transfer.go index 52f23bc..199c408 100644 --- a/clearing_transfer.go +++ b/clearing_transfer.go @@ -57,8 +57,8 @@ func (trf *ClearingTransfer) Sign(opts ClientOptions) { plainHash [sha256.Size]byte ) - trf.UserID = opts.UserID - trf.Email = opts.Email + trf.UserID = opts.DisburseUserID + trf.Email = opts.DisburseEmail trf.Timestamp = now.UnixMilli() bb.WriteString(trf.Email) @@ -71,7 +71,7 @@ func (trf *ClearingTransfer) Sign(opts ClientOptions) { fmt.Fprintf(&bb, `%d`, trf.Amount) bb.WriteString(trf.Purpose) fmt.Fprintf(&bb, `%d`, trf.DisburseID) - bb.WriteString(opts.ApiKey) + bb.WriteString(opts.DisburseApiKey) plainHash = sha256.Sum256(bb.Bytes()) @@ -69,7 +69,7 @@ func NewClient(opts ClientOptions) (cl *Client, err error) { func (cl *Client) CheckBalance() (bal *Balance, err error) { var ( logp = `CheckBalance` - req = CreateRequest(cl.opts) + req = CreateDisburseRequest(cl.opts) httpRes *http.Response resBody []byte @@ -211,7 +211,7 @@ func (cl *Client) InquiryStatus(disburseID int64) (res *InquiryStatusResponse, e func (cl *Client) ListBank() (banks []Bank, err error) { var ( logp = `ListBank` - req = CreateRequest(cl.opts) + req = CreateDisburseRequest(cl.opts) res = struct { Data interface{} `json:"Banks"` Code string `json:"responseCode"` diff --git a/client_options.go b/client_options.go index e5d7932..293b7c3 100644 --- a/client_options.go +++ b/client_options.go @@ -11,8 +11,9 @@ import ( // ClientOptions configuration for HTTP client. type ClientOptions struct { ServerUrl string - Email string - ApiKey string + + // The hostname extracted from ServerUrl. + host string // The merchant code is the project code obtained from the Duitku // merchant page. @@ -31,10 +32,14 @@ type ClientOptions struct { IndomaretMerchantCode string IndomaretApiKey string - // The hostname extracted from ServerUrl. - host string + // DisburseApiKey API key for signing disbursement request. + DisburseApiKey string + + // DisburseEmail The email registered for disbursement in Duitku. + DisburseEmail string - UserID int64 + // DisburseUserID user ID for disbursement request. + DisburseUserID int64 } // validate each field values. @@ -49,14 +54,14 @@ func (opts *ClientOptions) validate() (err error) { } opts.host = urlServer.Host - if opts.UserID <= 0 { - return fmt.Errorf(`invalid or empty UserID: %d`, opts.UserID) + if opts.DisburseUserID <= 0 { + return fmt.Errorf(`invalid or empty DisburseUserID: %d`, opts.DisburseUserID) } - if len(opts.Email) == 0 { - return fmt.Errorf(`invalid or empty Email: %s`, opts.Email) + if len(opts.DisburseEmail) == 0 { + return fmt.Errorf(`invalid or empty DisburseEmail: %s`, opts.DisburseEmail) } - if len(opts.ApiKey) == 0 { - return fmt.Errorf(`invalid or empty ApiKey: %s`, opts.ApiKey) + if len(opts.DisburseApiKey) == 0 { + return fmt.Errorf(`invalid or empty DisburseApiKey: %s`, opts.DisburseApiKey) } return nil diff --git a/duitku_test.go b/duitku_test.go index 129e97f..37d1ba6 100644 --- a/duitku_test.go +++ b/duitku_test.go @@ -16,10 +16,10 @@ var ( func TestMain(m *testing.M) { var ( clOpts = ClientOptions{ - ServerUrl: ServerUrlSandbox, - Email: `test@chakratechnology.com`, - UserID: 3551, - ApiKey: `de56f832487bc1ce1de5ff2cfacf8d9486c61da69df6fd61d5537b6b7d6d354d`, + ServerUrl: ServerUrlSandbox, + DisburseUserID: 3551, + DisburseEmail: `test@chakratechnology.com`, + DisburseApiKey: `de56f832487bc1ce1de5ff2cfacf8d9486c61da69df6fd61d5537b6b7d6d354d`, } err error diff --git a/inquiry_status.go b/inquiry_status.go index 66797bf..28b5cf0 100644 --- a/inquiry_status.go +++ b/inquiry_status.go @@ -20,11 +20,11 @@ type InquiryStatus struct { // Sign the request, fill the UserID, Email, Timestamp, and generate the // Signature. func (inq *InquiryStatus) Sign(opts ClientOptions) { - inq.UserID = opts.UserID - inq.Email = opts.Email + inq.UserID = opts.DisburseUserID + inq.Email = opts.DisburseEmail inq.Timestamp = time.Now().UnixMilli() - var plain string = fmt.Sprintf(`%s%d%d%s`, inq.Email, inq.Timestamp, inq.DisburseID, opts.ApiKey) + var plain string = fmt.Sprintf(`%s%d%d%s`, inq.Email, inq.Timestamp, inq.DisburseID, opts.DisburseApiKey) var plainHash [sha256.Size]byte = sha256.Sum256([]byte(plain)) inq.Signature = hex.EncodeToString(plainHash[:]) @@ -25,13 +25,13 @@ type Request struct { Timestamp int64 `json:"timestamp"` } -func CreateRequest(opts ClientOptions) (req Request) { - req.UserID = opts.UserID - req.Email = opts.Email +func CreateDisburseRequest(opts ClientOptions) (req Request) { + req.UserID = opts.DisburseUserID + req.Email = opts.DisburseEmail req.Timestamp = time.Now().UnixMilli() var ( - plain = fmt.Sprintf(`%s%d%s`, req.Email, req.Timestamp, opts.ApiKey) + plain = fmt.Sprintf(`%s%d%s`, req.Email, req.Timestamp, opts.DisburseApiKey) hashRaw = sha256.Sum256([]byte(plain)) ) diff --git a/rtol_inquiry.go b/rtol_inquiry.go index a3b4ea9..14b9bba 100644 --- a/rtol_inquiry.go +++ b/rtol_inquiry.go @@ -44,14 +44,14 @@ type RtolInquiry struct { // 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.UserID = opts.DisburseUserID + inq.Email = opts.DisburseEmail inq.Timestamp = time.Now().UnixMilli() var ( plain = fmt.Sprintf(`%s%d%s%s%d%s%s`, inq.Email, inq.Timestamp, inq.BankCode, inq.BankAccount, - inq.Amount, inq.Purpose, opts.ApiKey) + inq.Amount, inq.Purpose, opts.DisburseApiKey) plainHash [sha256.Size]byte = sha256.Sum256([]byte(plain)) ) inq.Signature = hex.EncodeToString(plainHash[:]) diff --git a/rtol_transfer.go b/rtol_transfer.go index 4ba8718..6d6c1fb 100644 --- a/rtol_transfer.go +++ b/rtol_transfer.go @@ -74,14 +74,14 @@ func (req *RtolTransfer) Sign(opts ClientOptions) { plainHash [sha256.Size]byte ) - req.UserID = opts.UserID - req.Email = opts.Email + req.UserID = opts.DisburseUserID + req.Email = opts.DisburseEmail req.Timestamp = now.UnixMilli() fmt.Fprintf(&bb, `%s%d%s%s%s%s%d%s%d%s`, req.Email, req.Timestamp, req.BankCode, req.BankAccount, req.AccountName, req.CustRefNumber, req.Amount, req.Purpose, - req.DisburseID, opts.ApiKey) + req.DisburseID, opts.DisburseApiKey) plainHash = sha256.Sum256(bb.Bytes()) |
