Question

I am using Stripe's custom checkout button and I can create charges successfully. What I want to do now is pass the e-mail address on the form and create a new customer. However, the email address doesn't get passed to my server rather it goes directly to Stripe.

I was hoping I could do something like this:

//pass value from input field on previous page
$email = $_POST['email'];

// Create a Customer
$customer = Stripe_Customer::create(array(
  "card" => $token,
  "description" => "$email")
);

But I don't want to ask the user for his email address twice, since Stripe's form already asks for it.

How can I capture the email address to create a new customer?

Was it helpful?

Solution 2

Ok then...while I didn't know the rules here, here's the answer:

Using the Stripe checkout.js

In your token callback, you can access res.email the same way you access res.id which will give you the email that the user submitted. Here's the code:

  var token = function(res){
      var $theToken = $('<input type=hidden name=stripeToken />').val(res.id);
      var $theEmail = $('<input type=hidden name=stripeEmail />').val(res.email);
      $('form').append($theToken);
      $('form').append($theEmail).submit();
  };

You could also put them in an array and then use a

$.each(

But that would be as an exercise for you to use. Cheers, -Colin

OTHER TIPS

The email is posted along with the token.

It's passed into a post variable: $_POST['stripeEmail'].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top