Skip to content

Commit

Permalink
Merge pull request #487 from stripe/brandur-account-holder-optional
Browse files Browse the repository at this point in the history
Make `account_holder_name`/`account_holder_type` truly optional
  • Loading branch information
brandur-stripe authored Oct 25, 2017
2 parents db83a94 + 63d6cfb commit d572f66
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,20 @@ func (a *BankAccountParams) AppendToAsSourceOrExternalAccount(body *form.Values)
} else {
body.Add(sourceType+"[object]", "bank_account")
body.Add(sourceType+"[country]", a.Country)
body.Add(sourceType+"[account_holder_name]", a.AccountHolderName)
body.Add(sourceType+"[account_holder_type]", a.AccountHolderType)
body.Add(sourceType+"[account_number]", a.Account)
body.Add(sourceType+"[currency]", a.Currency)

// These are optional and the API will fail if we try to send empty
// values in for them, so make sure to check that they're actually set
// before encoding them.
if len(a.AccountHolderName) > 0 {
body.Add(sourceType+"[account_holder_name]", a.AccountHolderName)
}

if len(a.AccountHolderType) > 0 {
body.Add(sourceType+"[account_holder_type]", a.AccountHolderType)
}

if len(a.Routing) > 0 {
body.Add(sourceType+"[routing_number]", a.Routing)
}
Expand Down
48 changes: 48 additions & 0 deletions bankaccount_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package stripe

import (
"testing"

assert "github.com/stretchr/testify/require"
"github.com/stripe/stripe-go/form"
)

func TestBankAccountParams_AppendToAsSourceOrExternalAccount(t *testing.T) {
// We should add more tests for all the various corner cases here ...

// Includes account_holder_name
{
params := &BankAccountParams{AccountHolderName: "Tyrion"}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"Tyrion"}, body.Get("external_account[account_holder_name]"))
}

// Does not include account_holder_name if empty
{
params := &BankAccountParams{}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string(nil), body.Get("external_account[account_holder_name]"))
}

// Includes account_holder_name
{
params := &BankAccountParams{AccountHolderType: "individual"}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string{"individual"}, body.Get("external_account[account_holder_type]"))
}

// Does not include account_holder_name if empty
{
params := &BankAccountParams{}
body := &form.Values{}
params.AppendToAsSourceOrExternalAccount(body)
t.Logf("body = %+v", body)
assert.Equal(t, []string(nil), body.Get("external_account[account_holder_type]"))
}
}

0 comments on commit d572f66

Please sign in to comment.