7

I am attempting to add parameters to Stripe Checkout.

new.html.erb

<%= form_for @user do |f| %>

    <%= f.label :first_name %>
    <%= f.text_field :first_name %>

    <%= f.label :last_name %>
    <%= f.text_field :last_name %>

<% end %>
<%= form_tag charges_path, class: 'stripeform' do %>

    <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
            data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
            data-description="Beautiful"
            data-amount="<%= @price*100 %>"
            data-image="<%= image_tag "logo.png" %>"></script>

<% end %>

Considering Stripe has its own "submit" button, how would one pass additional parameters?

2
  • Just put your fields inside Checkout's form and they'll get submitted along with the form? Commented Feb 1, 2015 at 1:01
  • Composing compound words such as data-name doesn't work. There are restrictions. stripe.com/docs/checkout#integration-custom Commented Feb 1, 2015 at 5:46

1 Answer 1

14

You can just add extra <input> fields inside the form you use for Checkout. They will get posted along with the Stripe token

<form action="/charge" method="POST">
  <input type="text" name="extraParam">
  <input type="text" name="extraParam2">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_XXX"
    data-image="/square-image.png"
    data-name="Demo Site"
    data-description="2 widgets ($20.00)"
    data-amount="2000">
  </script>
</form>

The other solution would be to use Custom Checkout to retrieve the token in the token() callback and then add it as a hidden input in your own form and submit that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.