0
votes

I have a signup form with First Name, Last Name, Email and Phone, and then a Pay with Card Stripe Checkout button. Once the user fills out the form, Stripe Checkout asks for Email Address. How can I get the user entered email address in the form to auto fill the email address field in Stripe Checkout.

Here's my current code:

        .field
          = f.label :"Email:"
          = f.text_field :email
        %br  
        .actions
          %script.stripe-button{ src: "https://checkout.stripe.com/checkout.js",
                data: {email: "thisemail@carriesover.com", amount: @level.price*100, description: @level.name, key: Rails.application.secrets.stripe_publishable_key}}

If I hardcode the email address in the Stripe Checkout script, it works. Can I use jQuery to pass it over? If so, how?

1
If you get it in JS on the same page then you can't this way. You need to use Custom Checkout (stripe.com/docs/checkout#integration-custom) and pass the email in the email parameter of handler.open() - koopajah
@koopajah thanks! it looks like it broke this line though: @registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"]) Not sure where stripe_params[] comes from. - Trey Copeland
If you use custom checkout you get the token in the token() callback and at that point you have to post the token id and the user email yourself to your server - koopajah

1 Answers

0
votes

I did so like this:

    = javascript_include_tag "https://checkout.stripe.com/v2/checkout.js",
      :class => "stripe-button",
      :"data-key" => "#{Rails.configuration.stripe[:publishable_key]}",
      :"data-description" => "charged upon appointment confirmation",
      :"data-amount" => total.to_s,
      :"data-image" => 'https://s3-us-west-2.amazonaws.com/xx
      :"data-label" => "Request Appointment",
      :"data-panel-label" => "Pre-Authorize",
      :"data-name" => "Pre-Authorize Payment",
      :"data-email" => @current_user.email

Hope it helps you.