Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Parameters with Stripe Checkout

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?

like image 617
softcode Avatar asked Jan 31 '15 03:01

softcode


1 Answers

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.

like image 75
koopajah Avatar answered Nov 09 '22 07:11

koopajah