Is it possible to pass a custom key:value pair inside a session object with Run Payments with Stripe firebase Extension?

22 views Asked by At

I am trying to integrate an affiliate program into a project I am working on.

Inside firestore, I've successfully added a checkout session under my user -> checkout_session that contains the referral code using the following objects:

    const checkoutSessionData: CheckoutSessionData  = {
        price: process.env.NEXT_PUBLIC_STRIPE_PREMIUM_PRICE,
        success_url: `${window.location.origin}/dashboard`,
        cancel_url: `${window.location.origin}/dashboard`,
        mode: "subscription",
    };

    if (window.Rewardful?.referral) {
        checkoutSessionData.clientReferenceId = window.Rewardful.referral;
    }
    const checkoutSessionsCollection = collection(doc(collection(db, 'users'), id), 'checkout_sessions');
    const docRef = await addDoc(checkoutSessionsCollection, checkoutSessionData);


    onSnapshot(docRef, (snap) => {
        const data = snap.data();

        if (data) {
            const { error, url } = 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 (url) {
                // We have a Stripe Checkout URL, let's redirect.
                window.location.assign(url)
            }
        }
    });
} catch (error) {
    console.error("Error creating checkout session: ", error);
}

The problem is, even though the clientReferenceId is inside the checkout_session for the user, it is not appearing in the request POST body on stripe. Here is what stripe is receiving:

{
  "line_items": {
    "0": {
      "quantity": "1",
      "price": "priceID"
    }
  },
  "billing_address_collection": "required",
  "allow_promotion_codes": "false",
  "locale": "auto",
  "customer": "CUSTOMER_ID",
  "cancel_url": "CANCELURL",
  "mode": "subscription",
  "success_url": "SUCCESS_URL",
  "subscription_data": {
    "trial_from_plan": "true"
  }
}

I am using the Run Payments with Stripe Firebase Extension and believe that this is the reason the clientReferenceId is not being passed, so is it possible to add a custom key:value pair that can be passed by this extension, or will I have to create my own custom cloud functions?

0

There are 0 answers