userbase-samples icon indicating copy to clipboard operation
userbase-samples copied to clipboard

[WIP] Change Netlify Stripe sample to use subscriptions

Open thorsten-stripe opened this issue 4 years ago • 4 comments

r? @j-berman

Howdy, this is really cool! While testing the sample I kept a log of the things I had to do to set everything up and I've compiled it into a README. Let me know what you think :)

I've also:

  • Added a .gitignore file to ignore the .env file
  • Added a .env.example file and copy instructions in the README
  • Extracted all client-side identifiers (Stripe publishable key; Userbase App ID) into a separate client_config.js file, for easier set up.

Question

Seeing that the button says "Purchase Subscription", would you mind changing the one-time SKU for a recurring plan: https://stripe.com/docs/payments/checkout/client-subscription

And once done, would be awesome to link the live demo from the README 🎉 Wdyt?

thorsten-stripe avatar Mar 03 '20 15:03 thorsten-stripe

Thanks @j-berman. This ended up a somewhat larger change as I've added a function handler to cancel the subscriptions, and also renames the webhook handler function.

PTAL and let me know what you think.

For this to work on your end, you will need to

  • Redeploy your functions (I think this will happen automatically when you merge)
  • Change the webhook URL in your Dashboard to end in /webhook

But that should be it.

thorsten-stripe avatar Mar 04 '20 08:03 thorsten-stripe

One question I had: Is it safe to assume that the userId is only known to an authenticated client? Or could there be an attack vector of someone sending cancel_subscription requests with someone else's userId?

And if the latter is the case, is there anyway to verify in the Netlify function if the user is authenticated?

thorsten-stripe avatar Mar 04 '20 09:03 thorsten-stripe

Daniel and I have been discussing this exact issue recently.

As of right now, the only way to see a user's userId is by signing in as the user, or as an admin viewing it in the admin panel, or accessing the Userbase server logs/database. But it's not something we explicitly expect people will keep secret. So short answer, yes, this is an attack vector.

We've been discussing adding a means to authenticate a user from a Netlify function and we're close to settling on an approach. For now, I'd say it's probably best to leave cancel functionality out of this demo until we implement this. It should be soon :)

j-berman avatar Mar 04 '20 18:03 j-berman

@j-berman sounds good. I've tagged this PR to [WIP] so we can leave it open until the authentication from Netlify functions feature ships and moved the previous changes to https://github.com/encrypted-dev/userbase-samples/pull/13 which we can merge now to have the README and such :)

thorsten-stripe avatar Mar 06 '20 06:03 thorsten-stripe