#Ayla
1 messages · Page 1 of 1 (latest)
Cancelling the subscription by any means (Dashboard, API, customer portal) should ensure that the Firebase document is updated correctly to reflect that
This is what handles it: https://github.com/stripe/stripe-firebase-extensions/blob/477ceef1272c7d2a48afecdc82bc5146bf7043dc/firestore-stripe-payments/functions/src/index.ts#L557-L585
sure, but I have to take care of the firebase document myself? I don't do so for creating the subscription (via API). Documents like "payments" and "subscription" are created automatically
On customer.subscription.deleted events
No, the extension should handle that for you assuming you have webhooks configured correctly
hm, sorry, I think i didn't get it .. I followed the instructions in the extension documentation to create a nwe subscrition like so: const docRef = await db .collection('users') .doc(currentUser.uid) .collection('checkout_sessions') .add({ price: 'price_1GqIC8HYgolSBA35zoTTN2Zl', success_url: window.location.origin, cancel_url: window.location.origin, }); // Wait for the CheckoutSession to get attached by the extension docRef.onSnapshot((snap) => { const { error, url } = snap.data(); if (error) { // Show an error to your customer and // inspect your Cloud Function logs in the Firebase console. alert(`An error occured: ${error.message}`); } if (url) { // We have a Stripe Checkout URL, let's redirect. window.location.assign(url); } });
how would the process look like for cancleing the subscription
Ok, great. And that creates the Subscription in Stripe and reflected status in Firebase, yes?
jup
There's no specific function in the extension to cancel. You can either:
- call the API directly yourself: https://stripe.com/docs/billing/subscriptions/cancel
- cancel them in the Dashboard
- use the customer portal function in the extension to allow customers to manage and cancel their subscriptions themselves: https://github.com/stripe/stripe-firebase-extensions/blob/next/firestore-stripe-payments/POSTINSTALL.md#redirect-to-the-customer-portal
okay, great, Ill take a look to solution 1 and 3 and let you know if it works for me. Thanks for your help!
This is the customer portal, btw: https://stripe.com/docs/customer-management
hey, sorry, I did not manage to create a working solution. I initialize (in the react frontend) stripe like so: const initializeStripe = async () => { if (!stripePromise) { stripePromise = await loadStripe( process.env.REACT_APP_STRIPE_PK_KEY ); } return stripePromise; }; and when I use this to get my stripe object: const stripe = await getStripe(); it does not have a method stripe.subscriptions.del
That's because those methods are not available via Stripe.js, you need stripe-node to use server-side API requests like that
Means I cant use stripe in my react frontend?
Not to make direct API calls like that, no. You'd need a server-side function
hm, okay. Is there a reason, why some functionallity like creating subscriptions are available to access via the frontend code and others like deleting subscriptions are not?
The Stripe.js/React wrapper is mainly for using Elements and such, for collecting payment details
Creating Subscriptions isn't available via the front-end, not directly anyway. You're creating your subscriptions via the extension which, under the hood, uses the server-side APIs
It's just a convenient wrapper
alright, got it (: .. thanks