Skip to content

Commit

Permalink
Merge pull request #486 from stripe/brandur-send-object
Browse files Browse the repository at this point in the history
Send `object=bank_account` when using `AccountExternalAccountParams`
  • Loading branch information
brandur-stripe authored Oct 25, 2017
2 parents d572f66 + f7de6b1 commit 76e48b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ type AccountExternalAccountParams struct {
Token string `form:"token"`
}

// AppendTo implements custom encoding logic for AccountExternalAccountParams
// so that we can send the special required `object` field up along with the
// other specified parameters or the token value
func (p *AccountExternalAccountParams) AppendTo(body *form.Values, keyParts []string) {
if len(p.Token) > 0 {
body.Add(form.FormatKey(keyParts), p.Token)
} else {
body.Add(form.FormatKey(append(keyParts, "object")), "bank_account")
}
}

// PayoutScheduleParams are the parameters allowed for payout schedules.
type PayoutScheduleParams struct {
Delay uint64 `form:"delay_days"`
Expand Down
22 changes: 22 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ import (
"github.com/stripe/stripe-go/form"
)

func TestAccountExternalAccountParams_AppendTo(t *testing.T) {
{
params := &AccountExternalAccountParams{}
body := &form.Values{}
form.AppendTo(body, params)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"bank_account"}, body.Get("object"))
}

{
params := &AccountExternalAccountParams{Token: "tok_123"}
body := &form.Values{}

// 0-length keyParts are not allowed, so call AppendTo directly (as
// opposed to through the form package) and inject a realistic set
params.AppendTo(body, []string{"external_account"})

t.Logf("body = %+v", body)
assert.Equal(t, []string{"tok_123"}, body.Get("external_account"))
}
}

func TestAccountUnmarshal(t *testing.T) {
accountData := map[string]interface{}{
"id": "acct_123",
Expand Down

0 comments on commit 76e48b3

Please sign in to comment.