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

Http Cart type payment_collection field is not a list #9738

Open
vethan opened this issue Oct 23, 2024 · 5 comments
Open

Http Cart type payment_collection field is not a list #9738

vethan opened this issue Oct 23, 2024 · 5 comments

Comments

@vethan
Copy link

vethan commented Oct 23, 2024

Bug report

Describe the bug

Line 76 medusa/packages/core/types/src/http/cart/common.ts reads:
payment_collection?: BasePaymentCollection

However a list of payment collections is passed when requests are made from the backend. Should either the medusa backend should send single objects, or this type should be BasePaymentCollection[]

System information

Medusa version (including plugins): 2.0.0
Node.js version: N/A
Database:N/A
Operating system:N/A
Browser (if relevant):

Steps to reproduce the behavior

  1. Create a cart with a payment collection with medusa SDK
  2. Try to access cart.payment_collection.payment_sessions
  3. It will be undefined
  4. Access cart.payment_collection[0].payment_sessions
  5. It will be defined but type checking will report an error

Expected behavior

Either cart.payment_collection.payment_sessions should contain payment sessions, or the type should be a list

Screenshots

If applicable, add screenshots to help explain your problem
N/A

Code snippets

If applicable, add code samples to help explain your problem
N/A

Additional context

Add any other context about the problem here
N/A

@vethan
Copy link
Author

vethan commented Oct 23, 2024

I'm just dumb and wrote bad code

@vethan vethan closed this as completed Oct 23, 2024
@vethan vethan reopened this Oct 23, 2024
@vethan
Copy link
Author

vethan commented Oct 23, 2024

Turns out not entirely my fault. Seems that sometimes cart.payment_collection is an object, and other times it is an array. It has seems to become an array if you hit a "Could not delete all payment sessions" error, at which point it will stay an array. Not sure how to reproduce as yet, but will keep trying to investigate

@vethan
Copy link
Author

vethan commented Oct 23, 2024

Seems to be the case if you create two payment collections in quick succession (So still bad code that you shouldn't write)

@olivermrbl
Copy link
Contributor

if you create two payment collections in quick succession

@vethan, do you mean you send two requests using the JS-SDK method store.cart.initiatePaymentSessions?

@vethan
Copy link
Author

vethan commented Oct 24, 2024

I was calling medusaSdk.store.payment.initiatePaymentSession in two consecutive re-renders, which caused a 'Could not delete all payment sessions' error.

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

No branches or pull requests

2 participants