#fedoraus

1 messages · Page 1 of 1 (latest)

wise carbonBOT
storm minnow
north sonnet
#

Hi, no

#

i'm using firebase functions

#

but i see some similitudes here

#

this is my code

#
  console.log('create_checkout_session');
  const {priceId} = req.body;
  const {customerId} = req.body;
  const session = await stripe.checkout.sessions.create({
    customer: customerId,
    mode: 'subscription',
    payment_method_types: ['card'],
    metadata: {product_id: ''},
    line_items: [
      {
        price: priceId,
        quantity: 1,
      },
    ],
    success_url: 'https://www.google.com/',
    cancel_url: 'https://www.youtube.com',
  });

  res.redirect(session.url);
});

exports.stripe = functions.https.onRequest(async (req, res) => {
  const sigHeader = req.headers['stripe-signature'] || '';
  let event;
  try {
    event = stripe.webhooks.constructEvent(req.rawBody, sigHeader, '');
  } catch (error) {
    res.status(400).send('Bad request sent.');
    return;
  }
  functions.logger.info(event);
  const {email} = await stripe.customers.retrieve(event.data.object.customer);
  await firestore.doc(email).set({subscription_date: new Date(), interval: 'monthly'}, {merge: true});
  res.sendStatus(200);
});
#

but its firebase functions

#

and i cant pass the uid into metadata

storm minnow
#

Why can't you pass it in metadata?

#

Also never share secrets in here. I recommend removing that whsec from your response and rolling the key

north sonnet
#

yeah, my bad

#

i cant pass, cuz i created firebase function

#

and i firebase gave me just link for this function

#

and it works separatly from my extendion

#

extension*

storm minnow
#

Ok I gotcha. Sorry I'm not an expert in firebase, but I can help with Webhooks. You can't edit the code for the firebase functions? Metadata is almost always the recommended approach for sending data to your webhook endpoint.

north sonnet
#

yes, i can edit the code, but i have no idea how to connect the uid of firebase user and customer_id

storm minnow
#

Ok. Can you describe more about your integration flow? Exactly how all the pieces connect? Then maybe I can try to provide a recommendation. Unfortunately I'm not a firebase expert though

north sonnet
#

im not a firebase expert too xd
so firstly i tried to use this function, but somet from here told me , that nobody use it

    const user = firebase.auth().currentUser;

    const docRef = await db
    .collection("customers")
    .doc(user.uid)
    .collection("checkout_sessions")
    .add({
        price: 'price_key', // todo price Id from your products price in the Stripe Dashboard
        success_url: document.location.origin, // return user to this screen on successful purchase
        cancel_url: document.location.origin // return user to this screen on failed purchase
    });

    // Wait for the CheckoutSession to get attached by the extension
    docRef.onSnapshot(async (snap) => {
        const {error,  sessionId } = snap.data();
        
        if (error) {
            // Show an error to your customer and inspect
            // your Cloud Function logs in the Firebase console.
            alert(`An error occurred: ${error.message}`);
        }
        
        if (sessionId) {
        // We have a session, let's redirect to Checkout
        const stripe = Stripe('pk_test_key');
        stripe.redirectToCheckout({ sessionId });
        }
    });```
#

and i couldnt get the session id

storm minnow
#

Ah gotcha. Since this seems to be mostly a firebase issue/question, I recommend going to somewhere like Stackoverflow to get help on how to get that piece from Firebase

#

But if you have any Stripe-specific questions, I'm happy to help further!

#

Apologies that my Firebase knowledge is limited

north sonnet
#

yeah, thank you very much!!

#

nevermind, its not your fault

#

❤️