{"action":"created","issue":{"url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/360","repository_url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock","labels_url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/360/labels{/name}","comments_url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/360/comments","events_url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/360/events","html_url":"https://github.com/rebelidealist/stripe-ruby-mock/issues/360","id":167171077,"number":360,"title":"Integration testing with Stripe checkout.js and stripe-ruby-mock","user":{"login":"nfm","id":127960,"avatar_url":"https://avatars.githubusercontent.com/u/127960?v=3","gravatar_id":"","url":"https://api.github.com/users/nfm","html_url":"https://github.com/nfm","followers_url":"https://api.github.com/users/nfm/followers","following_url":"https://api.github.com/users/nfm/following{/other_user}","gists_url":"https://api.github.com/users/nfm/gists{/gist_id}","starred_url":"https://api.github.com/users/nfm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nfm/subscriptions","organizations_url":"https://api.github.com/users/nfm/orgs","repos_url":"https://api.github.com/users/nfm/repos","events_url":"https://api.github.com/users/nfm/events{/privacy}","received_events_url":"https://api.github.com/users/nfm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-23T06:37:32Z","updated_at":"2016-11-23T12:37:36Z","closed_at":null,"body":"Hey there,\n\nI'm trying to figure out the best way to write integration tests using Capybara that work with Stripe's checkout.js. My tests are working correctly as is - I can fill out the Stripe Checkout modal with a test card, submit it to Stripe, receive a card token back in my app, and create a customer using that card token. However, these all hit Stripe's test API.\n\nI'm trying to set up stripe-ruby-mock, and it looks like it expects to generate card tokens for you. I've had a look at the source, and can't see a way to tell it to accept card tokens that have actually been returned from Stripe via the checkout.js process. When I call `StripeMock.start` before my tests, and continue to pass a real token from Stripe into my `Stripe:::Customer.create` call, I receive a `Stripe::InvalidRequestError: Invalid token` from stripe-ruby-mock.\n\nIs there an existing way to do this? If not, would you be open to a PR that added this? Or am I going about this the wrong way?\n\nIdeally it would be nice to not have to go through Stripe's checkout.js at all, but that involves resolving `checkout.stripe.com` to `localhost` and spoofing SSL certificates, or conditionally sourcing `checkout.js` from `localhost` based on `Rails.env`, which seems brittle. But I'm definitely open to other options if anyone has a good way to test this stuff!\n"},"comment":{"url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/comments/262502302","html_url":"https://github.com/rebelidealist/stripe-ruby-mock/issues/360#issuecomment-262502302","issue_url":"https://api.github.com/repos/rebelidealist/stripe-ruby-mock/issues/360","id":262502302,"user":{"login":"patrick-gleeson","id":12064716,"avatar_url":"https://avatars.githubusercontent.com/u/12064716?v=3","gravatar_id":"","url":"https://api.github.com/users/patrick-gleeson","html_url":"https://github.com/patrick-gleeson","followers_url":"https://api.github.com/users/patrick-gleeson/followers","following_url":"https://api.github.com/users/patrick-gleeson/following{/other_user}","gists_url":"https://api.github.com/users/patrick-gleeson/gists{/gist_id}","starred_url":"https://api.github.com/users/patrick-gleeson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrick-gleeson/subscriptions","organizations_url":"https://api.github.com/users/patrick-gleeson/orgs","repos_url":"https://api.github.com/users/patrick-gleeson/repos","events_url":"https://api.github.com/users/patrick-gleeson/events{/privacy}","received_events_url":"https://api.github.com/users/patrick-gleeson/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T12:37:36Z","updated_at":"2016-11-23T12:37:36Z","body":"One option (not necessarily a good one!) would be to inject some JS directly into your page when running tests to mock Stripe interactions. I'm using `stripe.js` rather than `checkout.js` (i.e. my own custom form rather than Stripe's modal. All I need is for `Stripe.card.createToken(form, callback)` in my JS to return a stripe-mock token rather than going to the Stripe API. So in one of my RSpec feature specs I'm experimenting with doing:\r\n\r\n```ruby\r\n  visit '/payment_page'\r\n  stripe_helper = StripeMock.create_test_helper\r\n  token = stripe_helper.generate_card_token(last4: '1234')\r\n  script = \"Stripe.card = { createToken: function(_ ,callback) { callback(null, {id: \\\"#{token}\\\"}); } }\"\r\n  page.evaluate_script(script)\r\n```\r\n\r\nIt's not beautiful, but it's simpler than trying to catch the network requests. I wonder if this sort of approach could be refined to work in your case."}}
{"actor":{"display_login":"patrick-gleeson"}}