RedwoodJS-stripe plugin v1 released!

Introducing Redwoodjs-Stripe plugin! A super simple way of scaffolding your very own commerce site using Stripe Checkout. By running one command you will get the boilerplate (schemas, services, and React hooks) you need for a simple online store as well as a little example store to show you how to use the plugin AND super simple cart functionality to help you get started. To get started, run the following command and enter your Stripe credentials when prompted:


npx @redwoodjs-stripe/cli@latest setup

This is only the beginning. Take a look at the docs for more information. There is much more to come! Please check it out and let me know what you think and what you would like to see.

A special thanks to RedwoodJS and Stripe teams for all the help :slight_smile:

12 Likes

Yay!

Excited to see the next features ahead as well!

1 Like

Hi @chrisvdm ,

Awesome work!

I’m trying to integrate the redwoodjs-stripe plugin into my web app. I was wondering if there’s any hook for checking whether the logged in user has an active stripe subscription?

Use case: pass the stripeId for the logged in use to a hook that returns true / false if a user has an active subscription or not. If not, redirect user to the “choose subscription” page.

Some help / example would be appreciated, as I’m struggling to figure out how to do this.

Thanks,
Charlie

1 Like

Hey Charlie - I am close to the edge of my understanding here… but checking this line

It looks like you may be able to check this field for available subscriptions.

There is also the Subscriptions SDL which presents a lot of fields, but maybe the status field would say active or not?

I’m not sure on the front end, through the hooks, where this property would be accessible. The README states “* Subscription support via useStripeCustomerPortal() hook” so I guess its available at some point.

1 Like

Hiya @charliem,

Thanks! Also thank you for giving the plugin a go.

There is no hook like that at the moment. Would something that returns a list of a customer’s active subscriptions work? Then you can check for empty list to redirect?

I’m busy working on something to do that. Will update once I’m finished.

1 Like

Hi Chris,

That would work great, actually - thank you! Maybe also include all stripe fields for a subscription, so that more logic can be implemented in the future using those fields. :pray:

Charlie

Hi @charliem,

So I have two ways of you getting subscriptions per customer. One is via the useStripeCustomer hook and the other via the useStripeSubscriptions hook…This PR has examples you can follow: https://github.com/chrisvdm/redwoodjs-stripe/pull/121

I’m trying out a new api so there could be bugs if you used the services directly ie made your own custom services using the plugin services. You should able to pass a Fragment to the hook and expand fields. Let me know if you have any issues.

@charliem I forgot to add run npx @redwoodjs-stripe/cli@latest upgrade to get the latest release. (v1.0.1)

Hi @chrisvdm

This is fantastic, exactly what I needed. Thank you.

FYI I think a bug was introduced with the prettyList function in stripeCustomerSearch. If the result of the search is null (as there’s no existing customer), prettyList is trying to convert that to an object, and I get a “Cannot convert undefined or null to object.”

I think the line below is causing the bug (whenever there’s no customer returned from the search, as one doesn’t exist yet).

@charliem Thanks for the catch!

You can upgrade now. prettyList checks for empty objects

@chrisvdm that worked and I have the whole integration working, thank you for your help!

I also have a feature idea: The context should also hold the subscriptions object, so that you can easily create logic in an app based on which subscription someone has.

Use case: activate / deactivate certain features based on whether someone is on a “Basic” or “Premium” subscription. Having that info in the context stack would be very useful.

@charliem I’m glad your integration is working and you are most welcome :slight_smile: Thank you for being patient.

Re feature idea: I can see the value in storing a customer’s subscription object in the context. I honestly hadn’t thought of that. Thank you

Please let me know if you have any more issues/ideas

2 Likes

@chrisvdm my pleasure, and thank you for such a great plugin! Will definitely reach out if I have more ideas :slight_smile: .

1 Like

@chrisvdm was wondering if you could help me debug an issue with the stripeWebhook function in the stripe plugin.

When testing the webhook locally, it all works correctly. However, when I try to test the webhook in production (I have it at domain.com/api/stripeWebhook), I get the following error when a stripe event is sent over:

Invoke Error 	{"errorType":"Error","errorMessage":"No webhook payload was provided.","type":"StripeSignatureVerificationError","raw":{"message":"No webhook payload was provided."},"stack":["Error: No webhook payload was provided.","    at parseEventDetails (/var/task/node_modules/@redwoodjs-stripe/api/node_modules/stripe/cjs/Webhooks.js:76:19)","    at Object.verifyHeader (/var/task/node_modules/@redwoodjs-stripe/api/node_modules/stripe/cjs/Webhooks.js:58:102)","    at Object.constructEvent (/var/task/node_modules/@redwoodjs-stripe/api/node_modules/stripe/cjs/Webhooks.js:11:28)","    at handleStripeWebhooks (/var/task/node_modules/@redwoodjs-stripe/api/dist/lib/index.js:76:43)","    at Object.handler (/var/task/api/dist/functions/stripeWebhook/stripeWebhook.js:44:49)","    at Runtime.handler (/var/task/___vc/__launcher.js:6:1468)","    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"]}

I’ve been trying to debug this, but no idea why it’s not working.

Thanks!

Hiya @charliem, sure I’ll take a look at this. Thank you again for letting me know

1 Like

Hi @chrisvdm - was doing some research this evening and stumbled upon this: Vercel Production API bodyParser (stripe webhooks) · Issue #1410 · redwoodjs/redwood · GitHub (I’m hosting on Vercel). Haven’t yet tried to see if it fixes the problem, but thought I should share in case it helps you with debugging.

Hi @charliem - thanks for this. From my looking it seems like this might be it. I’ll test and get back to you

1 Like

Hiya @charliem That link you shared was very helpful. Hopefully it works now.
You can just run:
npx @redwoodjs-stripe/cli@latest upgrade

Hey @chrisvdm - confirming it’s now working, thanks for the fix :pray: !

1 Like

Hi @chrisvdm

The current checkout implementation did not allow the use of allow_promotion_codes in the stripe checkout page. Added the flag as a parameter when creating a checkout session.

Would you mind testing & updating the package when you get a moment?

Thanks,
Emi

1 Like