Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fobtac opened this issue Dec 24, 2023 · 15 comments
Open

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

fobtac opened this issue Dec 24, 2023 · 15 comments

Comments

@fobtac
Copy link

fobtac commented Dec 24, 2023

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
Copy link

Did you ever solve this problem?

@fobtac
Copy link
Author

fobtac commented Jan 30, 2024

Did you ever solve this problem?

Unfortunately not yet. Are you having the same issue?

@pevey
Copy link
Owner

pevey commented Jan 30, 2024

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
Copy link

@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
Copy link
Author

fobtac commented Jan 31, 2024

@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
Copy link

dianaow commented Mar 6, 2024

@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
Copy link

clemsos commented Mar 6, 2024

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
Copy link

dianaow commented Mar 6, 2024

@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
Copy link

clemsos commented Mar 6, 2024

@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
Copy link

dianaow commented Mar 6, 2024

@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
Copy link
Owner

pevey commented Mar 6, 2024

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
Copy link

dianaow commented Mar 7, 2024

@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
Copy link
Owner

pevey commented Mar 7, 2024

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

@dianaow
Copy link

dianaow commented Mar 7, 2024

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

@JoaquinPiersigilli
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants