pevey / sveltekit-medusa-starter

Starter project to help you create your Medusa-powered ecommerce application
MIT License
117 stars 12 forks source link

Cannot read properties of undefined (reading 'total') #7

Open fobtac opened 8 months ago

fobtac commented 8 months ago

After setting up my medusajs backend and configuring environment variables, I am able to implement products from the backend and add them to the cart. However, when I click "checkout" from the cart, and the checkout page loads, I get the message "your cart is empty" even after adding items to the cart. My terminal throws a TypeError:

{ id: 'u8IbOL8OTM6n96FJ5d9sX', type: 'response', timestamp: '2023-12-24T07:39:55.142Z', url: 'http://localhost:9000/store/carts/cart_01HJDBBVCN2GBPS5ZW5XRWS6PE/payment-session', status: 400, statusText: 'Bad Request' } TypeError: Cannot read properties of undefined (reading 'total') at POST (M:\storefront\src\routes\checkout\turnstile+server.ts:18:14) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Module.render_endpoint (M:\storefront\node_modules\@sveltejs\kit\src\runtime\server\endpoint.js:43:18) at async resolve (M:\storefront\node_modules\@sveltejs\kit\src\runtime\server\respond.js:404:17) at async Object.handle (M:\storefront\src\hooks.server.ts:10:21)
at async Module.respond (M:\storefront\node_modules\@sveltejs\kit\src\runtime\server\respond.js:274:20) at async file:///M:/storefront/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:510:22

I get these same results both before and after adding Stripe to my app.

Any Ideas? Thank you!

techydad05 commented 7 months ago

Did you ever solve this problem?

fobtac commented 7 months ago

Did you ever solve this problem?

Unfortunately not yet. Are you having the same issue?

pevey commented 7 months ago

Both the Medusa backend and the Stripe API have been updated since this starter was last updated. It will need to be tweaked to get it working again.

I no longer use Medusa. I use Vendure.

techydad05 commented 7 months ago

@fobtac yes Im having the same issue and Ill start figuring out how to make it work again. Ill let ya know when I do.

fobtac commented 7 months ago

@techydad05 that would be awesome! i'm fairly new to coding so you would definitely be better at solving this than i. i'll still keep digging though and keep you posted.

dianaow commented 6 months ago

@fobtac @techydad05 did you manage to find a solution? I am encountering the same error when integrating stripe. The returned cart variable is undefined because the post request failed. The error occurs\when creating a payment session with Medusa, with the 404 response error message being: 'Could not find a payment provider with id: stripe'

I have already set up stripe on the Medusa backend and admin. Unfortunately, documentation doesn't divulge anything else useful beyond setting up the stripe plugin. https://docs.medusajs.com/plugins/payment/stripe

clemsos commented 6 months ago

This worked our of the box for me on a fresh install. I just add to enable stripe (with local CLI) on the server and turnstile on the (local) client.

dianaow commented 6 months ago

@clemsos Do you mean to generate the Client Secret for the payment intent with Stripe instead of Medusa?

I keep on trying to make medusa.carts.setPaymentSession(locals.cartid, { provider_id: 'stripe'}) return without any errors because I want to obtain the Client Secret from it's response

clemsos commented 6 months ago

@dianaow I had the same error as @fobtac initially but it turned out that looking at the logs of the backend server stripe wasn't enable correctly. I used the stripe shell cli to start a localhost test session, which provided me with a webhook secret that I added in the .env of the backend server as STRIPE_WEBHOOK_SECRET (as well as the sk... secret). I had also added api key and secret to the .env of the svelte app. That worked correctly after that

dianaow commented 6 months ago

@clemsos Oh ok, yes I read about the stripe webhooks from the medusa docs (https://docs.medusajs.com/plugins/payment/stripe) but assumed it wasn't needed now because i'm not in production mode. i only want to test the plugin

pevey commented 6 months ago

If you are new to Medusa and just testing it out, I strongly recommend you look at Vendure instead. https://github.com/pevey/sveltekit-vendure-starter

dianaow commented 6 months ago

@clemsos unfortunately, setting up the webhooks, starting up 'localhost:4242/webhooks ', and specifying the webhook signing secret in .env file didn't resolve the issue. How did you identify that stripe wasn't setup properly through looking at the backend logs?

Screenshot 2024-03-07 at 7 09 40 PM

I could generate a payment intent from Stripe instead of through the Medusa API call (to select a payment session) and trigger a test payment successfully upon form submission. However, I still want to tie both Medusa and Stripe together, so that the Medusa admin knows about the order. Also, without a payment session selected, I get the same 'Could not find a payment provider with id: stripe' when an address/shipping option update is submitted through the Stripe form.

My last resort is to just reinstall the medusa backend and admin.

Are you using live or test Stripe API keys?

pevey commented 6 months ago

If you are using Medusa's stripe plugin, http://localhost:4242 is not the correct webhooks url. Please consult the documentation.

dianaow commented 6 months ago

@pevey Oh right, thank you! It should be localhost:9000/stripe/hooks

JoaquinPiersigilli commented 4 months ago

@pevey Can I asked why you moved from medusa to vendure?