Im confused. The Stripe Docs to integrate stripe elements in react said here:
const options = {
// passing the client secret obtained from the server
clientSecret: '{{CLIENT_SECRET}}',
};
return (
<Elements stripe={stripePromise} options={options}>
<CheckoutForm />
</Elements>
);
clientSecret in my Case -> 'seti_someId_secret_anotherId'
now im getting a warning: Unrecognized create() parameter: clientSecret is not a recognized parameter. This may cause issues with your integration in the future. Im not sure how to initialize the elements provider now.
Is this way, described in the docs deprecated? is there another new way? Im not able to bind the elements object to the current customer without this secret. Any Idea how to solve?
Thanks for your ideas, stay healthy.
Update: i tried to use another way. In my main App.js i deleted the options prop. Now i update the elements object in my component:
const CheckoutForm = () => {
const stripe = useStripe();
const elements = useElements();
const appearance = {
theme: 'dark'
};
useEffect(() => {
if(elements) {
//get secret key like seti_id_secret_id
axios.post(`${host}/stripe-api/payment-method`)
.then((res) => {
elements.update({clientSecret : res.data.setupIntent})
})
}
}, [elements])
const handleSubmit = async (event) => {
event.preventDefault();
if (elements == null) {
return;
}
const {error, paymentMethod} = await stripe.createPaymentMethod({
type: 'card',
card: elements.getElement(CardElement)
});
axios.post(`${host}/stripe-api/payment-method/attach`,paymentMethod)
.then((res) => console.log(res))
.catch((err) => console.log(err))
};
return (
<form onSubmit={handleSubmit}>
<CardElement />
<button type="submit" disabled={!stripe || !elements}>
Pay
</button>
</form>
);
};