#rizkieawan-react

1 messages · Page 1 of 1 (latest)

elfin hemlock
#

I can try to help, what's the question?

teal kelp
#

im new to stripe

#

and now i want to add validation to cardExp element

#

it will only accept card with exp date minimum +6 month from now

elfin hemlock
#

its not possible to do that unfortunately! There's no way to get notified of the exact value the customer is entering into the Element(there's an onChange event you can listen to for any validation errors like the date being in the past, but you can't really customise it to make it more restrictive like that

elfin hemlock
#

the only way to do this would be to check the details after the card is entered — i.e call createPaymentMethod when the customer is ready to pay, and then check the details of that PaymentMethod object (you can read the expiry from that) before proceeding

teal kelp
#

i tried to create custom input for the exp but how to put it when call createPaymentMethod?

#
      type: "card",
      card: elements.getElement("cardNumber")!,
      billing_details: {
        name: cardName,
      },
    });```
#

how to add exp value from input to that card params?

#

or it needs to pass an object instead of an element cardNumber

elfin hemlock
#

you can't(you can't supply the expiry yourself from your own inputs)

#

the only option is the one I said, you'd use our Elements, and check the details of the PaymentMethod after, you can't implement this validation on the input itself unfortunately, it's just not supported.

teal kelp
#

ohhh then it needs to be checked when createPaymentMethods deliver the response?

elfin hemlock
#

yes, paymentMethod.card.expiry_month I think can be accessed to check what the customer entered

teal kelp
#

yeah it can be accessed froom the response

#

is it the only way?

#

cause by that way it needs to fetch before i get the validation

boreal sail
#

Hey! Taking over from @elfin hemlock

#

Inspecting the resulting Payment Method object is the only way to check the expiry value I'm afraid