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

Allow stripe_account to be set globally: #412

Merged
merged 1 commit into from Apr 13, 2016

Conversation

Edouard-chin
Copy link
Contributor

  • When performing requests on the behalf of a managed account, stripe_account option must be passed everytime, this can become redundant
  • Allowing to set the stripe_account globally makes thing easier for wrapping every request in a single method, the same way as it is when defining the api_key globally

@matthelm

@brandur
Copy link
Contributor

brandur commented Apr 12, 2016

Thanks!

So my only fear here is that other global fields like api_key and api_version are the types of information that you're going to set once and will almost certainly last throughout the entire lifecycle of your program. I would say that this isn't necessarily the case of stripe_account; although you may want to work under the context of a single account for some time, it's possible (and maybe even likely) that you might want to move to another context later on, which introduces questions around thread safety across the boundaries of mutations in this global state.

Can I ask you what your use case is for you is here?

@Edouard-chin
Copy link
Contributor Author

Thanks for quick answer
We are switching from standalone account to managed account, we have many different places in our codebase where we retrieve Stripe object using API authentication via account specific api key.
Every call to Stripe are wrapped around a single method process_with_api_key that takes care of setting the desired api_key/version before yielding.

Moving to managed account would mean that we need to pass the stripe_account option in every method call to Stripe API and any future call would require so as well.

Instead we would like to set the stripe_account option (like we do for the version) inside our method wrapper so that we don't need to maintain multiple code paths as well as not have to remember in the future to pass the stripe_account option in the call.

has_entry(:headers, has_entry(:stripe_account, 'acct_1234')),
any_parameters,
any_parameters
).returns(make_response(response))
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Edouard-chin, so execute_request_with_rescues is at least to some degree what I'd consider a private-level method, and it would be nice to avoid referencing it in tests if possible.

test_helper defines a standardized way of mocking out HTTP requests; would you mind changing this check over to use that? Here is an example of a mock that would be very close to the one that you want to build.

@brandur
Copy link
Contributor

brandur commented Apr 13, 2016

@Edouard-chin Cool! I'm okay with bringing this in given that we currently don't give you a better way of doing this (we'll continue to work on that part of it).

I left one piece of feedback above. Would you mind taking a look at it, and then we can get this shipped. Thanks!

@Edouard-chin
Copy link
Contributor Author

Hey @brandur , awesome this is going to simplify our life greatly! I modified the test as you advised to mock the response with the standardized way. However and maybe I was doing this wrong but the test was focusing on checking what headers were passed to the request.

This is no more the case as the post method arguments from the mock doesn't include the headers.

I'm fine if this is ok to you, I will have to rename the test and squash 😄

@@ -33,4 +33,20 @@ class StripeTest < Test::Unit::TestCase
Stripe.max_network_retries = old
end
end

should "pass the stripe-account in the header" do
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also rename this one to "makes requests with the Stripe-Account header"?

@brandur
Copy link
Contributor

brandur commented Apr 13, 2016

This is no more the case as the post method arguments from the mock doesn't include the headers.

@Edouard-chin Doh! Okay, sorry that was my mistake.

We definitely want to test for the header though. Could you revert the last change and keep it the same except see if you can stub on the execute_request method instead? I think that this approach is slightly better because as you've seen, we already stub that elsewhere in the tests anyway.

Thanks! And sorry about the churn.

(And yes, please squash this all up if you can.)

- When performing requests on the behalf of a managed account, `stripe_account` option must be passed everytime, this can become redundant
- Allowing to set the `stripe_account` globally makes thing easier for wrapping every request in a single method, the same way as it is for defining the `api_key` globally
@Edouard-chin
Copy link
Contributor Author

@brandur No need to apologize thanks for your precious help !

All your comments should now be addressed, squashed commits and 💚 travis.

@brandur brandur merged commit 679b2b9 into stripe:master Apr 13, 2016
@brandur
Copy link
Contributor

brandur commented Apr 13, 2016

Thank-you :)

Released as 1.41.0.

@Edouard-chin Edouard-chin deleted the global-stripe-account-head branch April 13, 2016 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants