Skip to content
Advertisement

Stripe checkout button is not passing the email address

I am setting up a stripe button to charge a one time fee for a product. I the button works and it charges the customer but when i want to send an email to the customer, i can not fetch the customer email and also the customer email is not showing up in stripe dashboard. I have the following code;

<form action="/purchase" method="post" id="stripe" class="nobottommargin margin-top10">
<noscript>You must <a href="http://www.enable-javascript.com" target="_blank">enable JavaScript</a> in your web browser in order to pay via Stripe.</noscript>

<input type="hidden" name="purchase" >
<input type="hidden" name="software" value="product">
<input type="hidden" name="amount" value="399">

<input 
    type="submit" 
    value="Pay Now"
    class="button button-3d button-large button-rounded btn-block button-green"
    data-image="https://www.domainname.co.uk/images/favicon/favicon-196x196.png"
    data-key="<?php echo $stripe_publishable_key; ?>"
    data-amount="39900"
    data-currency="gbp"
    data-zip-code="true"
    data-billingAddress="true"
    data-name="domainname.co.uk"
    data-description="Product"
    data-label="Pay Now"
    onClick="this.disabled=true; this.value='Processing...';"
/>
<script src="https://checkout.stripe.com/v2/checkout.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
$(document).ready(function() {
    $(":submit").on("click", function(event) {
        event.preventDefault();
        var $button = $(this),
            $form = $button.parents("form");
        var opts = $.extend({}, $button.data(), {
            token: function(result) {
                $form.append($("<input>").attr({ type: "hidden", name: "stripeToken", value: result.id })).submit();
                
            }
        });
        StripeCheckout.open(opts);
    });
});
</script>

When submit the payment I get the following error;

Notice: Undefined index: stripeEmail in ........

Does anyone know why?

Advertisement

Answer

You are using a deprecated version of Checkout which no longer sees any major updates. Instead you should use Stripe’s new Checkout: https://stripe.com/docs/payments/checkout

To answer your question, you aren’t getting the email value because you aren’t explicitly adding it to the form data to be POSTed to your backend. This should fix it:

$form
  .append($("<input>").attr({ type: "hidden", name: "stripeToken", value: result.id }))
  .append($("<input>").attr({ type: "hidden", name: "stripeEmail", value: result.email }))
  .submit();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement