#Liam Wilkinson - programmatic validation

1 messages · Page 1 of 1 (latest)

keen creek
chilly lodge
#

Hi 👋 the submission/confirmation is handled by calling stripe.confirmPayment, and as far as I know that can be called from anywhere within your JS code.

tropic apex
#

Hi Toby, yup I'm using stripe confirm payment right now but I don't want to run confirm payment until the user fills out the custom name field on the page. I know that confirm payment triggers validation, is there a publicly exposed function I can use to trigger that same validation logic without submitting the information?

chilly lodge
#

Are you referring to the validations that, for example, return an error if the card was declined?

tropic apex
#

So those sorts of errors I assume can only be received if I actually call confirmPayment. I just want to display front end validation errors for if the customer hasn't filled out say the credit card field or CCV field.

chilly lodge
#

Oh gotcha

tropic apex
#

Essentially the errors that are triggered by .on('change', but without the user having actually modified the form.

chilly lodge
#

Listening to those change events is going to be best way to handle that. You'll essentially want to track the state of the element(s) yourself, and then throw your own error if the user attempts to submit before everything is ready.

tropic apex
#

Is there any way for me to then highlight the field if the user hasn't filled the form out then or is that not a publicly accessible method?

chilly lodge
#

I don't think so, but am looking.

#

I'm not entirely sure if it's possible, but if it is then it's likely done by leveraging either:

The appearance API if you're using the Payment Element: I haven't played with this much, but the options related to warnings would be my guess on what might be applicable.
https://stripe.com/docs/stripe-js/appearance-api#additional-variables

Or the Style object if you're using Card Element(s): I think invalid would be the state to make changes to with this approach
https://stripe.com/docs/js/appendix/style

Customize the look and feel of Elements to match the design of your site.

tropic apex
#

Ok, thanks I'll look into this.