diff options
| author | Shulhan <ms@kilabit.info> | 2023-03-09 18:47:08 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-03-09 18:47:08 +0700 |
| commit | 3d29a1cf144c785c8a210c1e85061968446b2433 (patch) | |
| tree | 24b22f35d2fb5d91b1de544c84f8a172a1926b63 | |
| parent | 9318bcba3b36b1778aebba5f4a87f2a5c22d1432 (diff) | |
| download | duitku-3d29a1cf144c785c8a210c1e85061968446b2433.tar.xz | |
all: export the CallbackUrl, ReturnUrl, and Signature in MerchantInquiry
This is to allow the MerchantInquiry API to be more customize able
instead of fixed, using specific merchant configuration.
While at it change the MerchantInquiry method parameter to pointer,
because to allow the caller receive filled Signature for audit.
| -rw-r--r-- | client.go | 11 | ||||
| -rw-r--r-- | client_test.go | 2 | ||||
| -rw-r--r-- | merchant_inquiry.go | 64 |
3 files changed, 37 insertions, 40 deletions
@@ -265,20 +265,17 @@ func (cl *Client) ListBank() (banks []Bank, err error) { // numbers, QRIS, e-wallet, and so on). // // Ref: https://docs.duitku.com/api/en/#request-transaction -func (cl *Client) MerchantInquiry(req MerchantInquiry) (resp *MerchantInquiryResponse, err error) { +func (cl *Client) MerchantInquiry(req *MerchantInquiry) (resp *MerchantInquiryResponse, err error) { var ( - logp = `MerchantInquiry` - inreq = merchantInquiry{ - MerchantInquiry: req, - } + logp = `MerchantInquiry` httpRes *http.Response resBody []byte ) - inreq.sign(cl.opts) + req.sign(cl.opts) - httpRes, resBody, err = cl.PostJSON(PathMerchantInquiry, nil, inreq) + httpRes, resBody, err = cl.PostJSON(PathMerchantInquiry, nil, req) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } diff --git a/client_test.go b/client_test.go index 2c58db5..109712d 100644 --- a/client_test.go +++ b/client_test.go @@ -228,7 +228,7 @@ func TestClient_MerchantInquiry(t *testing.T) { t.Fatal(err) } - resp, err = testClientMerchant.MerchantInquiry(*req) + resp, err = testClientMerchant.MerchantInquiry(req) if err != nil { t.Fatal(err) } diff --git a/merchant_inquiry.go b/merchant_inquiry.go index 9c8495a..622c764 100644 --- a/merchant_inquiry.go +++ b/merchant_inquiry.go @@ -11,6 +11,15 @@ import ( // MerchantInquiry define request data for payment using merchant. type MerchantInquiry struct { + // [REQ] MerchantCode is a project that use Duitku. + // + // You can get this code on every project you register on the + // [merchant portal]. + // Default to ClientOptions.MerchantCode. + // + // [merchant portal]: https://passport.duitku.com/merchant/Project + MerchantCode string `json:"merchantCode"` + // [REQ] Transaction number from merchant. // Every request for a new transaction must use a new ID. MerchantOrderId string `json:"merchantOrderId"` @@ -36,6 +45,19 @@ type MerchantInquiry struct { // [REQ] The name that would be shown at bank payment system. CustomerVaName string `json:"customerVaName"` + // [REQ] A link that is used for redirect after exit payment page, + // being paid or not. + // Default to ClientOptions.MerchantReturnUrl. + ReturnUrl string `json:"returnUrl"` + + // [REQ] A link for callback transaction. + // Default to ClientOptions.MerchantCallbackUrl. + CallbackUrl string `json:"callbackUrl"` + + // [REQ] Transaction security identification code. + // Formula: MD5(merchantCode + merchantOrderId + paymentAmount + apiKey). + Signature string `json:"signature"` + // [OPT] Additional parameter to be used by merchant. // If its set, the value must be URL encoded. AdditionalParam string `json:"additionalParam,omitempty"` @@ -73,40 +95,18 @@ type MerchantInquiry struct { ExpiryPeriod int `json:"expiryPeriod,omitempty"` } -// merchantInquiry contains internal fields that will be set by client -// during Sign. -type merchantInquiry struct { - // [REQ] A link for callback transaction. - // Default to ClientOptions.MerchantCallbackUrl. - CallbackUrl string `json:"callbackUrl"` - - // [REQ] MerchantCode is a project that use Duitku. - // - // You can get this code on every project you register on the - // [merchant portal]. - // Default to ClientOptions.MerchantCode. - // - // [merchant portal]: https://passport.duitku.com/merchant/Project - MerchantCode string `json:"merchantCode"` - - // [REQ] A link that is used for redirect after exit payment page, - // being paid or not. - // Default to ClientOptions.MerchantReturnUrl. - ReturnUrl string `json:"returnUrl"` - - // [REQ] Transaction security identification code. - // Formula: MD5(merchantCode + merchantOrderId + paymentAmount + apiKey). - Signature string `json:"signature"` - - MerchantInquiry -} - -func (inq *merchantInquiry) sign(opts ClientOptions) { +func (inq *MerchantInquiry) sign(opts ClientOptions) { var merchant = opts.Merchant(inq.PaymentMethod) - inq.CallbackUrl = merchant.CallbackUrl - inq.MerchantCode = merchant.Code - inq.ReturnUrl = merchant.ReturnUrl + if len(inq.MerchantCode) == 0 { + inq.MerchantCode = merchant.Code + } + if len(inq.CallbackUrl) == 0 { + inq.CallbackUrl = merchant.CallbackUrl + } + if len(inq.ReturnUrl) == 0 { + inq.ReturnUrl = merchant.ReturnUrl + } var ( plain = fmt.Sprintf(`%s%s%d%s`, inq.MerchantCode, inq.MerchantOrderId, inq.PaymentAmount, merchant.ApiKey) |
