#hannahouazzane

1 messages ยท Page 1 of 1 (latest)

icy turretBOT
short kindle
#

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

sharp horizon
#

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

short kindle
#

are you setting customer ID when creating checkout sessions?

sharp horizon
#

not sure if I am, would I set it in here?

short kindle
#

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?

sharp horizon
#

No, addDoc is a firebase/firestore function

short kindle
#

what's checkoutSessionCollection ?

#

ah that might be the collection you're storing the checkout session to i presume ?

sharp horizon
#

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 !

short kindle
#

there's a customer: cus_P2RriDjl8lOqE8 passed in as a parameter

sharp horizon
#

so I would still like to pre-fill the email when a user first subscribes, so I assumed I would need that customer ID?

short kindle
#

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

sharp horizon
#

I think the customer ID is being generated automatically, so I am not sure how I'd remove it

#

is there a way to stop it pre-filling

#

sorry for all of the questions haha very new to this