#rc999 - js question
1 messages · Page 1 of 1 (latest)
Hello. Catching up on threads
Will check in a second
Is your question why aren't the console logs working?
My goal: get the status of the paymentIntent so I know whether or not to post a form to the back-end.
Whether the payment succeeds or fails, it still doesn't do anything, 1. doesn't send the data or 2. log an error
Pasting your code for my reference:
const stripe = useStripe();
const elements = useElements();
const [message, setMessage] = useState(null);
const [isLoading, setIsLoading] = useState(false);
const [success, setSuccess] = useState(false);
useEffect(() => {
if (!stripe) {
return;
}
const clientSecret = new URLSearchParams(window.location.search).get(
"payment_intent_client_secret"
);
if (!clientSecret) {
return;
}
console.log(body);
stripe.retrievePaymentIntent(clientSecret).then(
async function (response) {
if (
response.paymentIntent &&
response.paymentIntent.status === "succeeded"
) {
setSuccess(true);
const response = await fetch("/api/publish-newsletter", {
method: "POST",
body: body,
headers: {
"Content-Type": "application/json",
},
});
console.log(response);
const data = await response.json();
console.log(data);
} else {
console.log("Error");
}
},
[stripe, clientSecret]
);
});
What are you seeing being logged?