enupal / stripe

Allows customers sign up for recurring and one-time payments with Stripe, perfect for orders, donations, subscriptions, and events. Create simple payment forms in seconds easily without coding. For Craft CMS
https://enupal.com/craft-plugins/stripe-payments/
Other
33 stars 19 forks source link

Passing an email to Checkout using JS #152

Open bleepsandblops opened 3 years ago

bleepsandblops commented 3 years ago

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

andrelopez commented 3 years ago

Hi @bleepsandblops Yes please follow the next example:

{% set options = {
    email: 'customer-email@test.com'
} %}

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

bleepsandblops commented 3 years ago

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

andrelopez commented 3 years ago

@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('test@test.com');
bleepsandblops commented 3 years ago

@andrelopez ah great thanks!

bleepsandblops commented 3 years ago

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

lucasdaniels commented 3 years ago

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

bleepsandblops commented 3 years ago

@lucasdaniels I did not unfortunately, sorry!