I'm building a React App where you users can make one-time purchases of in-game tokens using Stripe. I'm having trouble getting onCurrentUserPayment()
to work from the @stripe/firestore-stripe-payments
sdk.
CODE
I have an onClick button
event with the following code.
const buyTokens1 = async () => {
const session = await createCheckoutSession(payments, {
mode: "payment",
price: [PRICE_ID],
success_url: window.location.origin,
cancel_url: window.location.origin,
});
window.location.assign(session.url);
onCurrentUserPaymentUpdate(payments, async (snapshot) => {
for (const change in snapshot.changes) {
if (change.type === "added") {
const docRef = doc(db, "users", user.uid);
await updateDoc(docRef, {
tokens: authUser.tokens + 100,
});
}
}
});
};
PROBLEM
When I click the button, the stripe checkout works perfectly fine, but the onCurrentUserPaymentUpdate()
does not work.
It's supposed to execute the firebase updateDoc
function when the Stripe purchase finishes, but it is not doing it.
The documentation isn't super clear. I've tried changing the "change-type" if statement and switching up API keys. None of this has worked.
Help! Thank you in advance.