stripe icon indicating copy to clipboard operation
stripe copied to clipboard

Passing an email to Checkout using JS

Open bleepsandblops opened this issue 5 years ago • 7 comments

Description

Is there a way to pass an email to Checkout so that it's automatically pre-filled, using the front-end? If I dig in the files, it looks like the hidden input enupalStripe[stripeData] gets parsed then emptied; is there a way for me to send the customer_email through?

Additional info

  • Craft version: 3.5.14
  • PHP version: 7.4
  • Database driver & version: mysql 8
  • Plugin version: 3.1.5
  • Is SCA and Stripe Checkout enabled?: yes

bleepsandblops avatar Nov 22 '20 22:11 bleepsandblops

Hi @bleepsandblops Yes please follow the next example:

{% set options = {
    email: '[email protected]'
} %}

{{ craft.enupalstripe.paymentForm('handle', options) }}

Here you can see all the other options that you can pass to the paymentForm method: https://docs.enupal.com/stripe-payments/templating/paymentform.html

We'll add this to the docs soon

andrelopez avatar Nov 23 '20 07:11 andrelopez

@andrelopez thank you, but that's through twig though, not client-side; is there a way to do it client-side?

bleepsandblops avatar Nov 23 '20 08:11 bleepsandblops

@bleepsandblops I see, from JS you need to set the value to the hidden email input, in this example 1009 is the form Id

$("#enupal-stripe-1009 input[name='enupalStripe[email]']").val('[email protected]');

andrelopez avatar Nov 23 '20 08:11 andrelopez

@andrelopez ah great thanks!

bleepsandblops avatar Nov 23 '20 08:11 bleepsandblops

@andrelopez it's not working actually, and I think I can see why. https://github.com/enupal/stripe/blob/master/src/services/Checkout.php#L106 the $data object is taken from https://github.com/enupal/stripe/blob/master/src/services/Checkout.php#L59 $publicData['stripe'] which is actually enupalStripe[stripeData] JSON input, the one that gets emptied.

bleepsandblops avatar Nov 23 '20 09:11 bleepsandblops

@bleepsandblops I am trying to do the same thing - did you perhaps find a solution to this?

lucasdaniels avatar May 17 '21 10:05 lucasdaniels

@lucasdaniels I did not unfortunately, sorry!

bleepsandblops avatar May 17 '21 19:05 bleepsandblops