0

I'm trying to handle credit card payments using stripe and reactjs. I'm following the tutorial here https://github.com/stripe-archive/react-stripe-elements. See the get started section. The only problem I have is that I need to submit the credit card form on the component page where the code is (the first page that is created) and not the CheckoutForm page. How do I do that?

I tried doing the following

 var elements = useElements();
 const card = elements.getElement(CardElement);
 const result = await stripePromise.createToken(card);
 if (result.error) {
    console.dir(result.error.message);
 } else {
    console.dir(result.token);
 }

but I'm not able to use a hook function useElements in a class compomnent.

1 Answer 1

1

First, the library you've linked to is deprecated, the new version is this one. Since you're using the hooks you must be using the new library already, though.

If you're using Class components, the documentation provides an example of an alternate integration pattern using the <Elements> provider and <ElementsConsumer> explicitly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.