Skip to content

Commit

Permalink
Merge pull request #48 from payjp/nyamanaka/fix_due_date_type
Browse files Browse the repository at this point in the history
fix due_date type
  • Loading branch information
natsuki-yamanaka authored Jun 19, 2024
2 parents 696b1f5 + ef9cacb commit e935cbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion v1/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ type BalanceResponse struct {
Closed bool `json:"closed"`
Statements []*StatementResponse
RawStatements listResponseParser `json:"statements"`
DueDate string `json:"due_date"`
RawDueDate *int `json:"due_date"`
DueDate time.Time
BankInfo *BankInfo `json:"bank_info"`
Object string `json:"object"`

Expand All @@ -112,6 +113,7 @@ func (t *BalanceResponse) UnmarshalJSON(b []byte) error {
err := json.Unmarshal(b, &raw)
if err == nil && raw.Object == "balance" {
raw.CreatedAt = time.Unix(IntValue(raw.Created), 0)
raw.DueDate = time.Unix(IntValue(raw.RawDueDate), 0)
raw.Statements = make([]*StatementResponse, len(raw.RawStatements.Data))
for i, r := range raw.RawStatements.Data {
json.Unmarshal(r, &(raw.Statements[i]))
Expand Down
8 changes: 5 additions & 3 deletions v1/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func TestParseBalance(t *testing.T) {
assert.EqualValues(t, 1000, s.Net)
assert.True(t, s.RawStatements.HasMore)
assert.Equal(t, "st_xxx", s.Statements[0].ID)
assert.Equal(t, "", s.DueDate)
assert.Equal(t, (*int)(nil), s.RawDueDate)
assert.Equal(t, time.Unix(0, 0), s.DueDate)
assert.Equal(t, "collecting", s.Type)
assert.False(t, s.Closed)
assert.Nil(t, s.BankInfo)
Expand All @@ -66,10 +67,11 @@ func TestParseBalance(t *testing.T) {
"bank_account_number": "1234567",
"bank_account_holder_name": "ペイ タロウ",
"bank_account_status": "pending"
}`, `"2015-09-16"`)
}`, `1711897200`)
err = json.Unmarshal([]byte(balanceJSONStr2), s)
assert.NoError(t, err)
assert.Equal(t, "2015-09-16", s.DueDate)
assert.Equal(t, 1711897200, *s.RawDueDate)
assert.Equal(t, 1711897200, (int)(s.DueDate.Unix()))
assert.Equal(t, "0001", s.BankInfo.BankCode)
assert.Equal(t, "123", s.BankInfo.BankBranchCode)
assert.Equal(t, "普通", s.BankInfo.BankAccountType)
Expand Down
2 changes: 1 addition & 1 deletion v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"
)

const Version = "v0.2.2"
const Version = "v0.2.3"
const tagName = "form"
const rateLimitStatusCode = 429

Expand Down

0 comments on commit e935cbe

Please sign in to comment.