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

Support source sharing via Stripe Connect #500

Merged
merged 2 commits into from
Dec 13, 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
3 changes: 3 additions & 0 deletions bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type BankAccountParams struct {
// Token is a token referencing an external account like one returned from
// Stripe.js.
Token string `form:"-"`

// ID is used when tokenizing a bank account for shared customers
ID string `form:"*"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do know if the * is required here? If we just need it for AppendToAsSourceOrExternalAccount, it might be worth changing to - to indicate that it's never needed elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brahn-stripe with - the field seems ignored. Not sure if I'm making another mistake but it's not sent to stripe-mock in that case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that was for @brandur-stripe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, this was more of a question I guess. If you look at BankAccountParams, it's basically serialized in two separate ways:

  1. When it's used for bankaccount or token operations, the default form implementation is used.
  2. In certain cases (e.g. recipients), we call the special AppendToAsSourceOrExternalAccount function.

I just want to make sure that we're implementing the minimal logic that we need so that we don't make this anymore complicated. If we need the new ID field for just (1) above, then we should remove the changes in AppendToAsSourceOrExternalAccount. If we need it for just (2) (I don't think this is the case because you implemented a new test for token), then we should have just form:"-" to indicate that this field is never needed by form. If we need ID to be encoded for both (1) and (2), then we should leave this as is.

Can you just confirm that the latter is the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandur-stripe My understanding was that we call AppendToAsSourceOrExternalAccount even for Token but I see now that this is wrong and I did not need to add the if inside the custom append. I will fix

}

// AppendToAsSourceOrExternalAccount appends the given BankAccountParams as
Expand Down
3 changes: 3 additions & 0 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type CardParams struct {
Token string `form:"-"`
Year string `form:"exp_year"`
Zip string `form:"address_zip"`

// ID is used when tokenizing a card for shared customers
ID string `form:"*"`
}

// AppendToAsCardSourceOrExternalAccount appends the given CardParams as either a
Expand Down
1 change: 1 addition & 0 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type SourceObjectParams struct {
Currency Currency `form:"currency"`
Customer string `form:"customer"`
Flow SourceFlow `form:"flow"`
OriginalSource string `form:"original_source"`
Owner *SourceOwnerParams `form:"owner"`
Redirect *RedirectParams `form:"redirect"`
StatementDescriptor string `form:"statement_descriptor"`
Expand Down
13 changes: 13 additions & 0 deletions source/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ func TestSourceDetach(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, source)
}

func TestSourceSharing(t *testing.T) {
params := &stripe.SourceObjectParams{
Type: "card",
Customer: "cus_123",
OriginalSource: "src_123",
Usage: stripe.UsageReusable,
}
params.SetStripeAccount("acct_123")
source, err := New(params)
assert.Nil(t, err)
assert.NotNil(t, source)
}
26 changes: 26 additions & 0 deletions token/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,29 @@ func TestTokenNew_WithPII(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, token)
}

func TestTokenNew_SharedCustomerCard(t *testing.T) {
params := &stripe.TokenParams{
Card: &stripe.CardParams{
ID: "card_123",
},
Customer: "cus_123",
}
params.SetStripeAccount("acct_123")
token, err := New(params)
assert.Nil(t, err)
assert.NotNil(t, token)
}

func TestTokenNew_SharedCustomerBankAccount(t *testing.T) {
params := &stripe.TokenParams{
Bank: &stripe.BankAccountParams{
ID: "ba_123",
},
Customer: "cus_123",
}
params.SetStripeAccount("acct_123")
token, err := New(params)
assert.Nil(t, err)
assert.NotNil(t, token)
}