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

Nil api key causing exception with Stripe 1.20.4 #209

Closed
crberube opened this issue Mar 30, 2015 · 18 comments
Closed

Nil api key causing exception with Stripe 1.20.4 #209

crberube opened this issue Mar 30, 2015 · 18 comments

Comments

@crberube
Copy link

Wanted to point out this issue that I noticed even though stripe-ruby-mock is only supporting stripe 1.20.1 as of now.

As of the following PR stripe/stripe-ruby#221 stripe raises a TypeError when it receives an api_key in the options that is not a string. In the mock_request method of StripeMock::Instance, api_key is a required parameter that is nil by default, thus raising an exception unless an api key is explicitly passed.

As an example, the following code raises a TypeError:

stripe_customer.sources.create(card: stripe_token)

while this code works as expected:

stripe_customer.sources.create({card: stripe_token}, {api_key: Stripe.api_key})
@DanielePalombo
Copy link

same problem

@aliou
Copy link

aliou commented Apr 14, 2015

Having the same problem.

@jasonrhalpern
Copy link

I think I have a somewhat similar problem. In various methods in my code I use things like:

customer.subscriptions.retrieve({SUB_ID})
customer.sources.retrieve({CARD_ID})

I am using this gem to test the methods that then make these API calls to Stripe. The ones for create customer/subscription/plan are working fine without the api_key, but all of the calls to the retrieve methods (listed above) are failing with the following error and I don't want to have to add the api_key since this is only a problem for my tests:

TypeError: api_key must be a string.

@micahwedemeyer
Copy link

+1 same problem

@jb41
Copy link

jb41 commented May 4, 2015

Anyone found solution to that? I have the same problem as described above with retrieving from Stripe.

@jasonrhalpern
Copy link

I still haven't figured out a solution to that issue.

@samkpower
Copy link

+1

1 similar comment
@psiedlak
Copy link

+1

jbredeche pushed a commit to quantopian/stripe-ruby-mock that referenced this issue May 18, 2015
@moneytree-doug
Copy link

👍

@jasonrhalpern There's an alternative solution in the original post, if you need it quickly.

@justinbburris
Copy link

@jasonrhalpern

Similar to what @crberube mentioned, you can (for now) make your call with the api_key

stripe_customer.sources.retrieve(stripe_card_id, {api_key: Stripe.api_key})

alexmamonchik pushed a commit that referenced this issue May 21, 2015
@alexmamonchik
Copy link
Contributor

@jasonrhalpern
Copy link

Thanks for the help on this guys, I'll probably use the older branch for the time being. I don't really want to have to modify the stripe code that I am testing by adding the api_key since doing so would only be necessary for the tests to pass and not for the actual implementation.

@moneytree-doug
Copy link

@alexmamonchik Is this fix in the roadmap? I can go change all my tests to use the syntax suggested by @crberube , but that doesn't seem to be a long term solution.

@alexmamonchik
Copy link
Contributor

@moneytree-doug master use Stripe 1.20.1 because 1.21.0 includes changes that breaks a lot of tests. In this branch I'm trying to fix all breaks. If it'll have compatibility with 1.20.1 we are going to merge it with master. Will be fine if you start using this branch and add issues about bugs you found.

alexmamonchik pushed a commit that referenced this issue Jun 12, 2015
bbradbury pushed a commit to bbradbury/stripe-ruby-mock that referenced this issue Aug 6, 2015
alexmamonchik pushed a commit that referenced this issue Aug 13, 2015
kathyonu pushed a commit to kathyonu/stripe-ruby-mock that referenced this issue Aug 29, 2015
kathyonu pushed a commit to kathyonu/stripe-ruby-mock that referenced this issue Aug 29, 2015
alexmamonchik pushed a commit that referenced this issue Sep 12, 2015
alexmamonchik pushed a commit that referenced this issue Sep 23, 2015
@esbanarango
Copy link

+1 Same problem here with 'stripe', '~> 1.31.0' and 'stripe-ruby-mock', '~> 2.2.0'.
I was able to "fix" it by setting a random string to the api_key before starting StripeMock.

  let(:stripe_helper) { StripeMock.create_test_helper }
  before do 
    Stripe.api_key = 'blablabla'
    StripeMock.start
  end
  after { StripeMock.stop }

@ometa
Copy link

ometa commented Jan 11, 2016

+1
Same problem here with 'stripe', '~> 1.31.0' and 'stripe-ruby-mock', '~> 2.2.1'.
I successfully used the workaround mentioned by @esbanarango, thank you!

sophylee pushed a commit to hopskipdrive/stripe-ruby-mock that referenced this issue Feb 2, 2016
@HunterMeyer
Copy link

I was having the same issue but with the generate_card_token method.
To "solve", I redefined the mock's method by adding my api key as the second argument.
Any method that calls create on a Stripe object is expecting the api_key as the second argument.

So in my specs, I wrote the following:

def generate_card_token(card_params={})
  card_data = { number: '4242424242424242', exp_month: 9, exp_year: 2018, cvc: '999' }
  card = StripeMock::Util.card_merge(card_data, card_params)
  card[:fingerprint] = StripeMock::Util.fingerprint(card[:number])

  stripe_token = Stripe::Token.create({ card: card }, ENV['STRIPE_DEV_SK'])
  stripe_token.id
end

And used it like so:

before do
  StripeMock.start
  let(:token) = generate_card_token
end

Hope this helps.

@alexmamonchik
Copy link
Contributor

@HunterMeyer try to get code from repo instead of rubygems

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

No branches or pull requests