aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go15
-rw-r--r--client_test.go14
-rw-r--r--payment_status.go (renamed from transaction_status.go)12
-rw-r--r--payment_status_response.go (renamed from transaction_status_response.go)12
4 files changed, 27 insertions, 26 deletions
diff --git a/client.go b/client.go
index 68790b1..98ba946 100644
--- a/client.go
+++ b/client.go
@@ -322,24 +322,21 @@ func (cl *Client) MerchantPaymentMethod(req *PaymentMethod) (resp *PaymentMethod
return resp, nil
}
-// [MerchantTxStatus] get the status of payment from customer.
+// [MerchantPaymentStatus] get the status of payment from customer.
//
-// [MerchantTxStatus]: https://docs.duitku.com/api/en/#check-transaction
-func (cl *Client) MerchantTxStatus(orderID, paymentMethod string) (resp *TxStatusResponse, err error) {
+// [MerchantPaymentStatus]: https://docs.duitku.com/api/en/#check-transaction
+func (cl *Client) MerchantPaymentStatus(req *PaymentStatus) (resp *PaymentStatusResponse, err error) {
var (
- logp = `MerchantTxStatus`
- req = transactionStatus{
- OrderID: orderID,
- }
+ logp = `MerchantPaymentStatus`
params url.Values
httpRes *http.Response
resBody []byte
)
- req.sign(cl.opts, paymentMethod)
+ req.sign(cl.opts)
- params, err = libhttp.MarshalForm(req)
+ params, err = libhttp.MarshalForm(*req)
if err != nil {
return nil, fmt.Errorf(`%s: %w`, logp, err)
}
diff --git a/client_test.go b/client_test.go
index 109712d..e54a825 100644
--- a/client_test.go
+++ b/client_test.go
@@ -258,15 +258,19 @@ func TestClient_MerchantInquiry(t *testing.T) {
// Test checking the transaction status.
var (
- txResp *TxStatusResponse
+ paymentReq = &PaymentStatus{
+ MerchantCode: req.PaymentMethod,
+ OrderID: req.MerchantOrderId,
+ }
+ paymentResp *PaymentStatusResponse
)
- txResp, err = testClientMerchant.MerchantTxStatus(req.MerchantOrderId, req.PaymentMethod)
+ paymentResp, err = testClientMerchant.MerchantPaymentStatus(paymentReq)
if err != nil {
t.Fatal(err)
}
- got, err = json.MarshalIndent(txResp, ``, ` `)
+ got, err = json.MarshalIndent(paymentResp, ``, ` `)
if err != nil {
t.Fatal(err)
}
@@ -274,8 +278,8 @@ func TestClient_MerchantInquiry(t *testing.T) {
tag = `tx_status_response.json`
exp = tdata.Output[tag]
exp = bytes.ReplaceAll(exp, []byte(`$ref`), []byte(resp.Reference))
- t.Logf(`MerchantTxStatus: response: %s`, got)
- test.Assert(t, `MerchantTxStatus`, string(exp), string(got))
+ t.Logf(`MerchantPaymentStatus: response: %s`, got)
+ test.Assert(t, `MerchantPaymentStatus`, string(exp), string(got))
}
func TestClient_MerchantPaymentMethod(t *testing.T) {
diff --git a/transaction_status.go b/payment_status.go
index 7ddae30..4eccd0c 100644
--- a/transaction_status.go
+++ b/payment_status.go
@@ -9,7 +9,7 @@ import (
"fmt"
)
-type transactionStatus struct {
+type PaymentStatus struct {
MerchantCode string `form:"merchantCode"`
OrderID string `form:"merchantOrderId"`
@@ -18,15 +18,15 @@ type transactionStatus struct {
Signature string `form:"signature"`
}
-func (tx *transactionStatus) sign(opts ClientOptions, paymentMethod string) {
- var merchant = opts.Merchant(paymentMethod)
+func (req *PaymentStatus) sign(opts ClientOptions) {
+ var merchant = opts.Merchant(req.MerchantCode)
- tx.MerchantCode = merchant.Code
+ req.MerchantCode = merchant.Code
var (
- plain = fmt.Sprintf(`%s%s%s`, tx.MerchantCode, tx.OrderID, merchant.ApiKey)
+ plain = fmt.Sprintf(`%s%s%s`, req.MerchantCode, req.OrderID, merchant.ApiKey)
md5Plain = md5.Sum([]byte(plain))
)
- tx.Signature = hex.EncodeToString(md5Plain[:])
+ req.Signature = hex.EncodeToString(md5Plain[:])
}
diff --git a/transaction_status_response.go b/payment_status_response.go
index cba2fee..c78dd3c 100644
--- a/transaction_status_response.go
+++ b/payment_status_response.go
@@ -3,16 +3,16 @@
package duitku
-// List of valid Code in TxStatusResponse.
+// List of valid Code in PaymentStatusResponse.
const (
- MerchantTxStatusSuccess = `00`
- MerchantTxStatusProcess = `01`
- MerchantTxStatusFailed = `02`
+ PaymentStatusSuccess = `00`
+ PaymentStatusProcess = `01`
+ PaymentStatusFailed = `02`
)
-// TxStatusResponse contains response from checking merchant payment
+// PaymentStatusResponse contains response from checking merchant payment
// status.
-type TxStatusResponse struct {
+type PaymentStatusResponse struct {
OrderID string `json:"merchantOrderId"`
Reference string `json:"reference"`
Amount string `json:"amount"`