diff options
| author | Shulhan <ms@kilabit.info> | 2025-07-12 18:09:52 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-07-12 18:09:52 +0700 |
| commit | 172b04fdfdbb879993402d5f6f447e4258fa19f6 (patch) | |
| tree | fed0f1df3674ebc92a920877e67ac121421c489b | |
| parent | b278a9314e102ef6d2a47688318c56855f838e61 (diff) | |
| download | duitku-172b04fdfdbb879993402d5f6f447e4258fa19f6.tar.xz | |
all: replace module share with pakakeh.go
The share module has been migrated and renamed to
git.sr.ht/~shulhan/pakakeh.go.
| -rw-r--r-- | balance.go | 2 | ||||
| -rw-r--r-- | bank.go | 2 | ||||
| -rw-r--r-- | client.go | 178 | ||||
| -rw-r--r-- | client_options.go | 2 | ||||
| -rw-r--r-- | client_options_test.go | 4 | ||||
| -rw-r--r-- | client_test.go | 2 | ||||
| -rw-r--r-- | go.mod | 6 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rw-r--r-- | inquiry_status_response.go | 2 | ||||
| -rw-r--r-- | rtol_inquiry_response.go | 2 |
10 files changed, 115 insertions, 89 deletions
@@ -3,7 +3,7 @@ package duitku -import "github.com/shuLhan/share/lib/math/big" +import "git.sr.ht/~shulhan/pakakeh.go/lib/math/big" // Balance contains the current user balances. type Balance struct { @@ -4,7 +4,7 @@ package duitku import ( - "github.com/shuLhan/share/lib/math/big" + "git.sr.ht/~shulhan/pakakeh.go/lib/math/big" ) // Bank contains bank information from response of ListBank. @@ -6,12 +6,11 @@ package duitku import ( "encoding/json" "fmt" - "net/http" "net/url" "sort" "strings" - libhttp "github.com/shuLhan/share/lib/http" + libhttp "git.sr.ht/~shulhan/pakakeh.go/lib/http" ) // List of known and implemented HTTP API paths. @@ -54,7 +53,7 @@ func NewClient(opts ClientOptions) (cl *Client, err error) { var ( logp = `NewClient` httpcOpts = libhttp.ClientOptions{ - ServerUrl: opts.ServerUrl, + ServerURL: opts.ServerUrl, Timeout: opts.Timeout, } ) @@ -65,7 +64,7 @@ func NewClient(opts ClientOptions) (cl *Client, err error) { } cl = &Client{ - Client: libhttp.NewClient(&httpcOpts), + Client: libhttp.NewClient(httpcOpts), opts: opts, } @@ -77,20 +76,23 @@ func (cl *Client) CheckBalance() (bal *Balance, err error) { var ( logp = `CheckBalance` req = CreateDisburseRequest(cl.opts) - - httpRes *http.Response - resBody []byte ) - httpRes, resBody, err = cl.PostJSON(PathCheckBalance, nil, req) + var clreq = libhttp.ClientRequest{ + Path: PathCheckBalance, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, httpRes.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &bal) + err = json.Unmarshal(clresp.Body, &bal) if err != nil { return nil, fmt.Errorf(`%s: %s`, logp, err) } @@ -105,8 +107,7 @@ func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryRes logp = `ClearingInquiry` path = PathInquiryClearing - httpRes *http.Response - resBody []byte + clresp *libhttp.ClientResponse ) req.Sign(cl.opts) @@ -117,15 +118,19 @@ func (cl *Client) ClearingInquiry(req *ClearingInquiry) (res *ClearingInquiryRes path = PathInquiryClearingSandbox } - httpRes, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, httpRes.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -142,8 +147,7 @@ func (cl *Client) ClearingTransfer(req *ClearingTransfer) (res *ClearingTransfer logp = `ClearingTransfer` path = PathTransferClearing - httpRes *http.Response - resBody []byte + clresp *libhttp.ClientResponse ) req.Sign(cl.opts) @@ -154,15 +158,19 @@ func (cl *Client) ClearingTransfer(req *ClearingTransfer) (res *ClearingTransfer path = PathTransferClearingSandbox } - httpRes, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, httpRes.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -178,9 +186,6 @@ func (cl *Client) InquiryStatus(disburseID int64) (res *InquiryStatusResponse, e req = InquiryStatus{ DisburseID: disburseID, } - - resHttp *http.Response - resBody []byte ) // Since the path is different in test environment, we check the host @@ -191,15 +196,21 @@ func (cl *Client) InquiryStatus(disburseID int64) (res *InquiryStatusResponse, e req.Sign(cl.opts) - resHttp, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if resHttp.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, resHttp.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -218,22 +229,25 @@ func (cl *Client) ListBank() (banks []Bank, err error) { Code string `json:"responseCode"` Desc string `json:"responseDesc"` }{} - - httpRes *http.Response - resBody []byte ) - httpRes, resBody, err = cl.PostJSON(PathListBank, nil, req) + var clreq = libhttp.ClientRequest{ + Path: PathListBank, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, httpRes.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } res.Data = &banks - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %s`, logp, err) } @@ -262,24 +276,25 @@ func (cl *Client) ListBank() (banks []Bank, err error) { // // Ref: https://docs.duitku.com/api/en/#request-transaction func (cl *Client) MerchantInquiry(req *MerchantInquiry) (resp *MerchantInquiryResponse, err error) { - var ( - logp = `MerchantInquiry` - - httpRes *http.Response - resBody []byte - ) + var logp = `MerchantInquiry` req.sign(cl.opts) - httpRes, resBody, err = cl.PostJSON(PathMerchantInquiry, nil, req) + var clreq = libhttp.ClientRequest{ + Path: PathMerchantInquiry, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s: %s`, logp, httpRes.Status, resBody) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s: %s`, logp, clresp.HTTPResponse.Status, clresp.Body) } - err = json.Unmarshal(resBody, &resp) + err = json.Unmarshal(clresp.Body, &resp) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -295,22 +310,25 @@ func (cl *Client) MerchantPaymentMethod(req *PaymentMethod) (resp *PaymentMethod var ( logp = `MerchantPaymentMethod` path = PathMerchantPaymentMethod - - httpRes *http.Response - resBody []byte ) req.Sign(cl.opts) - httpRes, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 400 { - return nil, fmt.Errorf(`%s: %s: %s`, logp, httpRes.Status, resBody) + if clresp.HTTPResponse.StatusCode >= 400 { + return nil, fmt.Errorf(`%s: %s: %s`, logp, clresp.HTTPResponse.Status, clresp.Body) } - err = json.Unmarshal(resBody, &resp) + err = json.Unmarshal(clresp.Body, &resp) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -325,9 +343,7 @@ func (cl *Client) MerchantPaymentStatus(req *PaymentStatus) (resp *PaymentStatus var ( logp = `MerchantPaymentStatus` - params url.Values - httpRes *http.Response - resBody []byte + params url.Values ) req.sign(cl.opts) @@ -337,15 +353,21 @@ func (cl *Client) MerchantPaymentStatus(req *PaymentStatus) (resp *PaymentStatus return nil, fmt.Errorf(`%s: %w`, logp, err) } - httpRes, resBody, err = cl.PostForm(PathMerchantTransactionStatus, nil, params) + var clreq = libhttp.ClientRequest{ + Path: PathMerchantTransactionStatus, + Params: params, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostForm(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if httpRes.StatusCode >= 400 { - return nil, fmt.Errorf(`%s: %s: %s`, logp, httpRes.Status, resBody) + if clresp.HTTPResponse.StatusCode >= 400 { + return nil, fmt.Errorf(`%s: %s: %s`, logp, clresp.HTTPResponse.Status, clresp.Body) } - err = json.Unmarshal(resBody, &resp) + err = json.Unmarshal(clresp.Body, &resp) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -370,9 +392,6 @@ func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err e var ( logp = `RtolInquiry` path = PathInquiry - - resHttp *http.Response - resBody []byte ) // Since the path is different in test environment, we check the host @@ -383,15 +402,21 @@ func (cl *Client) RtolInquiry(req *RtolInquiry) (res *RtolInquiryResponse, err e req.Sign(cl.opts) - resHttp, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if resHttp.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, resHttp.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } @@ -412,9 +437,6 @@ func (cl *Client) RtolTransfer(req *RtolTransfer) (res *RtolTransferResponse, er var ( logp = `RtolTransfer` path = PathTransfer - - resHttp *http.Response - resBody []byte ) // Since the path is different in test environment, we check the host @@ -425,15 +447,21 @@ func (cl *Client) RtolTransfer(req *RtolTransfer) (res *RtolTransferResponse, er req.Sign(cl.opts) - resHttp, resBody, err = cl.PostJSON(path, nil, req) + var clreq = libhttp.ClientRequest{ + Path: path, + Params: req, + } + var clresp *libhttp.ClientResponse + + clresp, err = cl.PostJSON(clreq) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } - if resHttp.StatusCode >= 500 { - return nil, fmt.Errorf(`%s: %s`, logp, resHttp.Status) + if clresp.HTTPResponse.StatusCode >= 500 { + return nil, fmt.Errorf(`%s: %s`, logp, clresp.HTTPResponse.Status) } - err = json.Unmarshal(resBody, &res) + err = json.Unmarshal(clresp.Body, &res) if err != nil { return nil, fmt.Errorf(`%s: %w`, logp, err) } diff --git a/client_options.go b/client_options.go index 2bdbffe..f2d2f45 100644 --- a/client_options.go +++ b/client_options.go @@ -9,7 +9,7 @@ import ( "os" "time" - "github.com/shuLhan/share/lib/ini" + "git.sr.ht/~shulhan/pakakeh.go/lib/ini" ) // ClientOptions configuration for HTTP client. diff --git a/client_options_test.go b/client_options_test.go index 0d865f3..2e2889c 100644 --- a/client_options_test.go +++ b/client_options_test.go @@ -7,8 +7,8 @@ import ( "encoding/json" "testing" - "github.com/shuLhan/share/lib/ini" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/ini" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestLoadClientOptions(t *testing.T) { diff --git a/client_test.go b/client_test.go index ea67d89..6fed817 100644 --- a/client_test.go +++ b/client_test.go @@ -8,7 +8,7 @@ import ( "encoding/json" "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestClient_CheckBalance(t *testing.T) { @@ -5,12 +5,10 @@ module git.sr.ht/~shulhan/duitku go 1.23.4 -require ( - git.sr.ht/~shulhan/pakakeh.go v0.60.1 - github.com/shuLhan/share v0.49.0 -) +require git.sr.ht/~shulhan/pakakeh.go v0.60.1 require ( + golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect golang.org/x/mod v0.24.0 // indirect golang.org/x/net v0.39.0 // indirect golang.org/x/sync v0.13.0 // indirect @@ -2,8 +2,8 @@ git.sr.ht/~shulhan/pakakeh.go v0.60.1 h1:JGke3BIh40tK+d9eHg0jYi/W+GVixWcGwFkAcyn git.sr.ht/~shulhan/pakakeh.go v0.60.1/go.mod h1:8t/pEqWDrEcyr26qR5sXJkF1M5tFhrs3Jzr5aYoZdIo= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/shuLhan/share v0.49.0 h1:9RtvejG4wV+0juKf8lB9lkF/pquC0rDPwm5lh/5mcG8= -github.com/shuLhan/share v0.49.0/go.mod h1:lnY5x7bhCg3fUy5bF1Cs6S23MKhMYwmVuzi4YRt84NM= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= diff --git a/inquiry_status_response.go b/inquiry_status_response.go index c1ed166..0d692be 100644 --- a/inquiry_status_response.go +++ b/inquiry_status_response.go @@ -3,7 +3,7 @@ package duitku -import "github.com/shuLhan/share/lib/math/big" +import "git.sr.ht/~shulhan/pakakeh.go/lib/math/big" // InquiryStatusResponse define response valeus from InquiryStatus. type InquiryStatusResponse struct { diff --git a/rtol_inquiry_response.go b/rtol_inquiry_response.go index 62529e9..ac5b1b6 100644 --- a/rtol_inquiry_response.go +++ b/rtol_inquiry_response.go @@ -3,7 +3,7 @@ package duitku -import "github.com/shuLhan/share/lib/math/big" +import "git.sr.ht/~shulhan/pakakeh.go/lib/math/big" // RtolInquiryResponse contains response from inquiry for Online Transfer. type RtolInquiryResponse struct { |
