#piLLy
1 messages · Page 1 of 1 (latest)
Hi! Let me help you with this.
What would you validate in the Payment Element if you've selected Google Pay?
I'm trying to validate billing information and the payment element validity at the same time, then if they're both valid, continue on to create the intent and order on the server.
So for Google pay, nothing, but I just need a way to check if there are any errors on the payment element.
I don't think it's possible: https://stripe.com/docs/js/elements/submit
But why you don't want to open the PR if Google Pay was selected?
Do you just want to check if the form is valid?
You can then listen to 'change' event, and inspect the complete property: https://stripe.com/docs/js/element/events/on_change?type=paymentElement
I have my own billing fields that I want to validate at the same time as the payment element.
I was going to pass these in to the confirmPayment method
So when the user submits, I validate their billing information, validate the payment element has no errors, and then send the data to the server, create the intent and call confirmPayment using the billing information from the form
If there's a billing validation issue, the PR will still open
Is there a way to get the selected payment method from the payment element? Then I can check if there's actually anything to validate on the element
Can you validate your form before calling .submit()?
Sure, but then I'm validating the form before the payment element which just seems pretty bad UX
I'd like to show the form errors and the element errors at the same time
As I said, you can validate it in real-time with 'change' event: https://stripe.com/docs/js/element/input_validation
That's a different change event to the one you linked before, and it's for a different element I think?
It's the same
But you're using Payment Element right?
Yes
What did you mean when you said validate in real time? Like check the event.value if it's googlepay and not call .submit() ?
Sorry I got misunderstood because you linked two different change events which appear to have slightly different results
I meant you listen to events when the form input changes and check if the form is valid or not.
I can see the event.complete property now
Sorry for confusion.
Is there anyway to pull that at will instead of listening to the change event
paymentElement.complete or something
Why you don't want to use Billing address conllection from the payment element? Or Address Element? https://stripe.com/docs/elements/address-element/collect-addresses?platform=web
No unfortunately, but you can save the current state into a variable.
I think I avoided it because we needed to support PayPal too, but we just got that added so maybe I should re-visit
added via stripe