Adding Parameters Using Stripe Checkout

I am trying 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 %> 

Given that Stripe has its own submit button, how would I pass in additional parameters?

+5
source share
1 answer

You can simply add additional <input> fields inside the form that you use for Checkout. They will be sent along with the Stripe marker.

 <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> 

Another solution would be to use Custom Checkout to extract the token in the token() callback, and then add it as hidden input in your own form and send that.

+10
source

Source: https://habr.com/ru/post/1212315/


All Articles