Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make account_holder_name/account_holder_type truly optional #487

Merged
merged 1 commit into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]"))
}
}