Это код, который я использую: < /p>
Код: Выделить всё
const [clientSecret, setClientSecret] = useState('');
const handleSubmit = async (event) => {
event.preventDefault();
await createPaymentIntent();
if (stripe && elements) {
const { error: stripeError } = await stripe.confirmCardPayment(clientSecret, {
payment_method: {
card: elements.getElement(CardElement)
}
});
if (stripeError) {
console.error('Payment failed', stripeError);
} else {
console.log('Payment successful');
}
}
}
const createPaymentIntent = async () => {
var imageLength = localStorage.getItem("imageBytes").split(',').length;
await fetch(`${HostName}api/Sell/xxxxx`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ "numberOfImages": imageLength })
})
.then((response) => response.json())
.then((response) => {
setClientSecret(response.clientSecret);
})
.catch(error => console.warn(error));
};
< /code>
Код ниже: < /p>
stripe.confirmCardPayment(clientSecret.....
Подробнее здесь: https://stackoverflow.com/questions/797 ... tripe-conf
Мобильная версия