Skip to content

Instantly share code, notes, and snippets.

@mattvv
Created March 17, 2014 19:15
Show Gist options
  • Select an option

  • Save mattvv/9606278 to your computer and use it in GitHub Desktop.

Select an option

Save mattvv/9606278 to your computer and use it in GitHub Desktop.

Revisions

  1. Matt Van created this gist Mar 17, 2014.
    25 changes: 25 additions & 0 deletions credit_card_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #this is a very simple, work in progress helper method for stubbing the stripe checkout.js

    #this creates a fake server that will generate stripe token as if it's coming from stripe. So we can test credit card input
    class FakeStripe < Sinatra::Base
    def self.boot
    instance = new
    Capybara::Server.new(instance).tap { |server| server.boot }
    end

    get '/checkout.js' do
    #generate a fake token from stripe as if the user entered a card
    StripeMock.start
    token = StripeMock.generate_card_token(last4: '4242', exp_year: 2020)
    "$(document).ready(function() {
    $('.stripe-button').replaceWith(function() {
    return \"<div id='stripeForm'></div>\";
    });
    $(\"<input type='hidden' id='stripeToken' name='stripeToken' value='#{token}'>\").appendTo('#stripeForm');
    $(\"<input name='commit' type='submit' value='Submit'/>\").appendTo('#stripeForm');
    });"
    end
    end

    server = FakeStripe.boot
    Stripe.api_base = "http://#{server.host}:#{server.port}"