#hannahouazzane
1 messages ยท Page 1 of 1 (latest)
Hello ๐ can you share a screenshot of the UI you're looking at?
Want to make sure if its checkout prefilling the payment method details or link
also, we don't own the firebase extension anymore. The project was transferred to invertase
https://github.com/invertase/stripe-firebase-extensions#readme
sure thing one second
the first screenshot is where the user first subscribes and the second one is where the user tries to subscribe again
are you setting customer ID when creating checkout sessions?
not sure if I am, would I set it in here?
hmm, in the first screenshot the email address seems to be prefilled which almost confirms that this session has a customer ID associated OR an email is being passed in..
is addDoc your own function?
No, addDoc is a firebase/firestore function
what's checkoutSessionCollection ?
ah that might be the collection you're storing the checkout session to i presume ?
here's the code for the page: import { app } from "../firebase/firebase";
import { loadStripe } from "@stripe/stripe-js";
import {
collection,
addDoc,
onSnapshot,
getFirestore,
} from "firebase/firestore";
export async function createCheckoutSession(uid) {
const firestore = getFirestore(app);
const expirationTime = Math.floor(Date.now() / 1000) + 30 * 60;
try {
const checkoutSessionsCollection = collection(
firestore,
"customers",
uid,
"checkout_sessions"
);
const newCheckoutSessionRef = await addDoc(checkoutSessionsCollection, {
price: "price_1NYpJSGKhIdX4asTMNftfoDj",
success_url: window.location.origin + "?payment_success=true",
cancel_url: window.location.origin + "/?payment_success=false",
expires_at: expirationTime,
});
onSnapshot(newCheckoutSessionRef, async (snap) => {
const data = snap.data();
if (data) {
const { sessionId } = data;
// Initiate Stripe
const stripe = await loadStripe(
process.env.NEXT_PUBLIC_STRIPE_TEST_API
);
if (stripe) {
stripe
.redirectToCheckout({sessionId} )
.then((result) => {
if (result.error) {
console.error("Stripe redirect error:", result.error);
}
})
.catch((error) => {
console.error("Stripe redirect error:", error);
});
} else {
console.error("Stripe is null.");
}
}
});
} catch (error) {
console.error("Error creating checkout session:", error);
}
}
yes it is !
so if you look at the creation request for the session you shared above
https://dashboard.stripe.com/logs/req_w2Id5goFS7dJN5
there's a customer: cus_P2RriDjl8lOqE8 passed in as a parameter
so I would still like to pre-fill the email when a user first subscribes, so I assumed I would need that customer ID?
yes, or you could pass it in via customer_email parameter
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer_email
The reason the payment method is being prefilled is because this customer has a successful payment with an attached payment method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.