redwoodjs / example-store-stripe

Redwood Example Store with Stripe Checkout Integration
https://superstore-redwood-stripe.netlify.app/
MIT License
41 stars 14 forks source link

3. Seeding your Stripe account step failed #457

Open ogawa5773 opened 1 year ago

ogawa5773 commented 1 year ago

What is happening

Follow the README and in the step "3. Seeding your Stripe account" I got an error like below

Error in script: Cannot find module '/Users/xxx/redwood/example-store-stripe/api/src/lib/stripe'
Require stack:
- /Users/xxx/example-store-stripe/scripts/seed-stripe.js
- /Users/xxx/example-store-stripe/node_modules/@redwoodjs/cli/dist/lib/exec.js
- /Users/xxx/example-store-stripe/node_modules/@redwoodjs/cli/dist/commands/execHandler.js
[FAILED] Cannot find module '/Users/xxx/example-store-stripe/api/src/lib/stripe'
[FAILED] Require stack:
[FAILED] - /Users/xxx/example-store-stripe/scripts/seed-stripe.js
[FAILED] - /Users/xxx/example-store-stripe/node_modules/@redwoodjs/cli/dist/lib/exec.js
[FAILED] - /Users/xxx/example-store-stripe/node_modules/@redwoodjs/cli/dist/commands/execHandler.js
The script exited with errors.

My Solution

I was able to proceed without any problems by revert the following commit

commit 822e875fb62649dc2df29553fa2b768dfb33e0ee (origin/tmp)
...
diff --git a/api/src/lib/stripe.js b/api/src/lib/stripe.js
deleted file mode 100644
index 78d89c9..0000000
--- a/api/src/lib/stripe.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import Stripe from 'stripe'
-
-export const stripe = new Stripe(process.env.STRIPE_SK)
-
-export const handleStripeWebhooks = (event, context, webhooksObj) => {
-  let stripeEvent
-  try {
-    const sig = event.headers['stripe-signature']
-    stripeEvent = stripe.webhooks.constructEvent(
-      event.body,
-      sig,
-      process.env.STRIPE_WEBHOOK_SK
-    )
-
-    let results = null
-    if (typeof webhooksObj[stripeEvent.type] !== 'undefined') {
-      results = webhooksObj[stripeEvent.type](event, context)
-    }
-    return results
-  } catch (error) {
-    console.log(error)
-    throw error
-  }
-}

Question

Is this an intentional file deletion or a bug?

jacebenson commented 3 months ago

Not sure, but since this comment, the readme uses a different env variable; here's my version

// ./api/src/lib/stripe.js

import Stripe from 'stripe'

export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)

export const handleStripeWebhooks = (event, context, webhooksObj) => {
  let stripeEvent
  try {
    const sig = event.headers['stripe-signature']
    stripeEvent = stripe.webhooks.constructEvent(
      event.body,
      sig,
      process.env.STRIPE_WEBHOOK_SK
    )

    let results = null
    if (typeof webhooksObj[stripeEvent.type] !== 'undefined') {
      results = webhooksObj[stripeEvent.type](event, context)
    }
    return results
  } catch (error) {
    console.log(error)
    throw error
  }
}