Skip to content

Commit

Permalink
Merge pull request #396 from abyssparanoia/feature/impl-remittance-de…
Browse files Browse the repository at this point in the history
…posit-search

Feature/impl remittance deposit search
  • Loading branch information
abyssparanoia authored Jun 22, 2024
2 parents 4200f09 + 25527e8 commit 70ae162
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
24 changes: 24 additions & 0 deletions remittance/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
accountRegistrationPath = "api/AccountRegistration.json"
depositRegistrationPath = "api/DepositRegistration.json"
realDepositRegistrationPath = "api/RealDepositRegistration.json"
depositSearchPath = "api/DepositSearch.json"
)

type MailDepositMethod string
Expand Down Expand Up @@ -45,3 +46,26 @@ const (
DepositResultCompleted DepositResult = "1"
DepositResultFailed DepositResult = "4"
)

type DepositBankStatus string

const (
DepositBankStatusRegistered DepositBankStatus = "0"
DepositBankStatusCreated DepositBankStatus = "1"
DepositBankStatusFailedCreating DepositBankStatus = "2"
DepositBankStatusSent DepositBankStatus = "3"
DepositBankStatusFailedSending DepositBankStatus = "4"
DepositBankStatusCanceled DepositBankStatus = "9"
)

type DepositBankResultDetail string

const (
DepositBankResultDetailNoAccount DepositBankResultDetail = "01"
DepositBankResultDetailNameMismatch DepositBankResultDetail = "02"
DepositBankResultDetailAccountNumberMismatch DepositBankResultDetail = "03"
DepositBankResultDetailSubjectMismatch DepositBankResultDetail = "04"
DepositBankResultDetailAccountClosed DepositBankResultDetail = "05"
DepositBankResultDetailAcceptTimeError DepositBankResultDetail = "06"
DepositBankResultDetailOther DepositBankResultDetail = "09"
)
61 changes: 61 additions & 0 deletions remittance/deposit_search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package remittance

import (
"github.com/abyssparanoia/go-gmo/internal/pkg/converter"
"github.com/abyssparanoia/go-gmo/internal/pkg/validate"
)

type DepositSearchRequest struct {
DepositID string `json:"Deposit_ID" validate:"required,max=27"`
}

func (r *DepositSearchRequest) Validate() error {
if err := validate.Struct(r); err != nil {
return err
}
return nil
}

type DepositSearchResponse struct {
DepositID string `json:"Deposit_ID"`
Amount string `json:"Amount"`
Free string `json:"Free"`
SelectKey string `json:"Select_Key"`
Bank *DepositSearchBankResponse `json:"bank"`
}

type DepositSearchBankResponse struct {
BankID string `json:"Bank_ID"`
BankName string `json:"Bank_Name"`
BankCode string `json:"Bank_Code"`
BranchName string `json:"Branch_Name"`
BranchCode string `json:"Branch_Code"`
AccountType string `json:"Account_Type"`
AccountNumber string `json:"Account_Number"`
AccountName string `json:"Account_Name"`
BankFee string `json:"Bank_Fee"`
Result DepositBankStatus `json:"Result"`
BranchCodeJpbank string `json:"Branch_Code_Jpbank"`
AccountNumberJpbank string `json:"Account_Number_Jpbank"`
DepositDate string `json:"Deposit_Date"`
ResultDetail DepositBankResultDetail `json:"Result_Detail"`
ClientName string `json:"Client_Name"`
}

func (cli *Client) DepositSearch(
req *DepositSearchRequest,
) (*DepositSearchResponse, error) {
if err := req.Validate(); err != nil {
return nil, err
}
reqMap, err := converter.StructToJsonTagMap(req)
if err != nil {
return nil, err
}
res := &DepositSearchResponse{}
_, err = cli.do(depositSearchPath, reqMap, res)
if err != nil {
return nil, err
}
return res, nil
}
43 changes: 43 additions & 0 deletions remittance/deposit_search_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package remittance

import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"gopkg.in/go-playground/assert.v1"
)

func TestDepositSearch(t *testing.T) {

expected := &DepositSearchResponse{
DepositID: "depositID",
Bank: &DepositSearchBankResponse{
BankID: "bankID",
},
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
respBody, _ := json.Marshal(expected)
w.Header().Set("Content-Type", "application/json")
w.Write(respBody)
}))
defer ts.Close()
defaultProxy := http.DefaultTransport.(*http.Transport).Proxy
http.DefaultTransport.(*http.Transport).Proxy = func(req *http.Request) (*url.URL, error) {
return url.Parse(ts.URL)
}
defer func() { http.DefaultTransport.(*http.Transport).Proxy = defaultProxy }()

cli, _ := NewClient("shopID", "shopPass", false)
cli.APIHost = apiHostTest
cli.SetHTTPClient(http.DefaultClient)
req := &DepositSearchRequest{
DepositID: "depositID",
}
result, err := cli.DepositSearch(req)
assert.Equal(t, nil, err)
assert.Equal(t, expected, result)
}

0 comments on commit 70ae162

Please sign in to comment.