Skip to content

Commit 70ae162

Browse files
Merge pull request #396 from abyssparanoia/feature/impl-remittance-deposit-search
Feature/impl remittance deposit search
2 parents 4200f09 + 25527e8 commit 70ae162

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

remittance/const.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88
accountRegistrationPath = "api/AccountRegistration.json"
99
depositRegistrationPath = "api/DepositRegistration.json"
1010
realDepositRegistrationPath = "api/RealDepositRegistration.json"
11+
depositSearchPath = "api/DepositSearch.json"
1112
)
1213

1314
type MailDepositMethod string
@@ -45,3 +46,26 @@ const (
4546
DepositResultCompleted DepositResult = "1"
4647
DepositResultFailed DepositResult = "4"
4748
)
49+
50+
type DepositBankStatus string
51+
52+
const (
53+
DepositBankStatusRegistered DepositBankStatus = "0"
54+
DepositBankStatusCreated DepositBankStatus = "1"
55+
DepositBankStatusFailedCreating DepositBankStatus = "2"
56+
DepositBankStatusSent DepositBankStatus = "3"
57+
DepositBankStatusFailedSending DepositBankStatus = "4"
58+
DepositBankStatusCanceled DepositBankStatus = "9"
59+
)
60+
61+
type DepositBankResultDetail string
62+
63+
const (
64+
DepositBankResultDetailNoAccount DepositBankResultDetail = "01"
65+
DepositBankResultDetailNameMismatch DepositBankResultDetail = "02"
66+
DepositBankResultDetailAccountNumberMismatch DepositBankResultDetail = "03"
67+
DepositBankResultDetailSubjectMismatch DepositBankResultDetail = "04"
68+
DepositBankResultDetailAccountClosed DepositBankResultDetail = "05"
69+
DepositBankResultDetailAcceptTimeError DepositBankResultDetail = "06"
70+
DepositBankResultDetailOther DepositBankResultDetail = "09"
71+
)

remittance/deposit_search.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package remittance
2+
3+
import (
4+
"github.com/abyssparanoia/go-gmo/internal/pkg/converter"
5+
"github.com/abyssparanoia/go-gmo/internal/pkg/validate"
6+
)
7+
8+
type DepositSearchRequest struct {
9+
DepositID string `json:"Deposit_ID" validate:"required,max=27"`
10+
}
11+
12+
func (r *DepositSearchRequest) Validate() error {
13+
if err := validate.Struct(r); err != nil {
14+
return err
15+
}
16+
return nil
17+
}
18+
19+
type DepositSearchResponse struct {
20+
DepositID string `json:"Deposit_ID"`
21+
Amount string `json:"Amount"`
22+
Free string `json:"Free"`
23+
SelectKey string `json:"Select_Key"`
24+
Bank *DepositSearchBankResponse `json:"bank"`
25+
}
26+
27+
type DepositSearchBankResponse struct {
28+
BankID string `json:"Bank_ID"`
29+
BankName string `json:"Bank_Name"`
30+
BankCode string `json:"Bank_Code"`
31+
BranchName string `json:"Branch_Name"`
32+
BranchCode string `json:"Branch_Code"`
33+
AccountType string `json:"Account_Type"`
34+
AccountNumber string `json:"Account_Number"`
35+
AccountName string `json:"Account_Name"`
36+
BankFee string `json:"Bank_Fee"`
37+
Result DepositBankStatus `json:"Result"`
38+
BranchCodeJpbank string `json:"Branch_Code_Jpbank"`
39+
AccountNumberJpbank string `json:"Account_Number_Jpbank"`
40+
DepositDate string `json:"Deposit_Date"`
41+
ResultDetail DepositBankResultDetail `json:"Result_Detail"`
42+
ClientName string `json:"Client_Name"`
43+
}
44+
45+
func (cli *Client) DepositSearch(
46+
req *DepositSearchRequest,
47+
) (*DepositSearchResponse, error) {
48+
if err := req.Validate(); err != nil {
49+
return nil, err
50+
}
51+
reqMap, err := converter.StructToJsonTagMap(req)
52+
if err != nil {
53+
return nil, err
54+
}
55+
res := &DepositSearchResponse{}
56+
_, err = cli.do(depositSearchPath, reqMap, res)
57+
if err != nil {
58+
return nil, err
59+
}
60+
return res, nil
61+
}

remittance/deposit_search_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package remittance
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
"net/http/httptest"
7+
"net/url"
8+
"testing"
9+
10+
"gopkg.in/go-playground/assert.v1"
11+
)
12+
13+
func TestDepositSearch(t *testing.T) {
14+
15+
expected := &DepositSearchResponse{
16+
DepositID: "depositID",
17+
Bank: &DepositSearchBankResponse{
18+
BankID: "bankID",
19+
},
20+
}
21+
22+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
23+
respBody, _ := json.Marshal(expected)
24+
w.Header().Set("Content-Type", "application/json")
25+
w.Write(respBody)
26+
}))
27+
defer ts.Close()
28+
defaultProxy := http.DefaultTransport.(*http.Transport).Proxy
29+
http.DefaultTransport.(*http.Transport).Proxy = func(req *http.Request) (*url.URL, error) {
30+
return url.Parse(ts.URL)
31+
}
32+
defer func() { http.DefaultTransport.(*http.Transport).Proxy = defaultProxy }()
33+
34+
cli, _ := NewClient("shopID", "shopPass", false)
35+
cli.APIHost = apiHostTest
36+
cli.SetHTTPClient(http.DefaultClient)
37+
req := &DepositSearchRequest{
38+
DepositID: "depositID",
39+
}
40+
result, err := cli.DepositSearch(req)
41+
assert.Equal(t, nil, err)
42+
assert.Equal(t, expected, result)
43+
}

0 commit comments

Comments
 (0)