invertase / stripe-firebase-extensions

Repository of Firebase Extensions built by Stripe.
https://firebase.google.com/products/extensions
Apache License 2.0
423 stars 160 forks source link

adding firebaseRole doesn't add stripeRole #534

Open colindm opened 1 year ago

colindm commented 1 year ago

Describe the bug

Subscribing to a product on Firebase doesn't add a 'striperole' after the payment is processed even though everything else seems to work fine.

To Reproduce

Here's my code to generate the subscription URL

const handlePayment = async () => { const app = getApp(); const payments = getStripePayments(app, { productsCollection: "products", customersCollection: "customers", }); const session = await createCheckoutSession(payments, { price: my price id is here, allow_promotion_codes: true, success_url: "https://redistricter.com/", cancel_url: "https://redistricter.com/", }); window.location.assign(session.url); };

image

And here's the code where I check the striperole (after I've done the subscription on the same account):

async function getCustomClaimRole() { await firebase.auth().currentUser.getIdToken(true); const decodedToken = await firebase.auth().currentUser.getIdTokenResult(); console.log("Claims", decodedToken.claims); console.log("Stripe Role", decodedToken.claims.stripeRole); return decodedToken.claims.stripeRole; }

Which returns this:

image

Expected behavior

Striperole should exist if firebaseRole exists in the metadata of a Stripe product. Maybe I'm missing something or I messed up somewhere.

System information

kingcharlezz commented 11 months ago

Did you ever fix this?

I am having the same problem

juliushuck commented 11 months ago

For people that do not call getIdToken(true) with the true as a parameter, please check this issue: https://github.com/stripe/stripe-firebase-extensions/issues/478

MephestoKhaan commented 11 months ago

Same problem here, I am using getIDToken(true) as well

Edit: found my problem. I was using the embeeded PricingTable and that does not seem to sync at all with Firebase

dosstx commented 4 months ago

Is this still an issue or am I doing it wrong? This does not work for me! Anyone ?

colindm commented 4 months ago

Is this still an issue or am I doing it wrong? This does not work for me! Anyone ?

I gave up a while ago and just wrote my own code to manage the Stripe API connection. It was a pain in the ass and it took a couple days but this extension is so poorly maintained that I didn't have a choice. I imagine you'll probably have to do the same thing or manage subscriptions manually :(

dosstx commented 4 months ago

Is this still an issue or am I doing it wrong? This does not work for me! Anyone ?

I gave up a while ago and just wrote my own code to manage the Stripe API connection. It was a pain in the ass and it took a couple days but this extension is so poorly maintained that I didn't have a choice. I imagine you'll probably have to do the same thing or manage subscriptions manually

Did this not help? https://github.com/invertase/stripe-firebase-extensions/issues/478

colindm commented 4 months ago

Is this still an issue or am I doing it wrong? This does not work for me! Anyone ?

I gave up a while ago and just wrote my own code to manage the Stripe API connection. It was a pain in the ass and it took a couple days but this extension is so poorly maintained that I didn't have a choice. I imagine you'll probably have to do the same thing or manage subscriptions manually

Did this not help? #478

I switched away a few months ago before that patch was made. But I ran into a few other issues with this extension alongside this one I would've switched away anyways. My advice is that this extension might be OK if you don't have many customers (you'll just have to hand-hold it to make sure it works), but with more than a couple hundred customers it makes more sense to just do it yourself.

dosstx commented 4 months ago

@colindm thanks. I also tried that fix anyways and still had same problem...so not sure if it was actually fixed.

kolibrizas commented 3 weeks ago

I am also having this issue. I added firebaseRole: premium metadata on both price and product in Stripe (and they got synced to firebase database). After buying a product it doesn't get added to user claims and my check is

await user.reload();
const decodedToken = await user.getIdTokenResult(true);
console.log('decodedToken.claims', decodedToken.claims);
console.log('decodedToken.claims.stripeRole', decodedToken.claims.stripeRole); // undefined
return decodedToken.claims?.stripeRole === 'premium';