medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
23.71k stars 2.28k forks source link

Gift card expiry date not being respected #6653

Open mortenengel opened 3 months ago

mortenengel commented 3 months ago

Bug report

Describe the bug

When creating a gift card with an expiration date, it can still be used after the expiration date.

System information

Medusa version (including plugins): 1.19.0 - admin 7.1.9 Node.js version: 18.16 Database: postgres Operating system: linux Browser (if relevant):

Steps to reproduce the behavior

  1. Create a gift-card with an expiration date in the past
  2. Add it to the cart
  3. Go through checkout and see that it's usable.

Expected behavior

Ideally you should get an error when adding, saying that the gift-card is too old. On top of this, checkout should also check the validity of gift-cards, as they could have been added before the valid-to date was set.

Screenshots

Order created on the 11th: image

Gift card used which expired on the 9th: image

Code snippets

Not applicable

Additional context

I have searched through cart, order and gift-cards functionality to try and find any code that could be buggy around this. But I don't see any signs of this being implemented anywhere...

mezzat11 commented 3 months ago

same for coupons

alessioacella commented 3 months ago

up

mezzat11 commented 3 months ago

@olivermrbl Same problem persists with gift cards: once a discount or gift card is applied to the cart, there's no subsequent validation. Validators should be in place to check stock, discounts, and prices every time the cart is loaded.

alessioacella commented 3 months ago

I totally agree with you.

mortenengel commented 3 months ago

As gift-cards with expiry dates are the very core of most of the orders on our shop, I have added a temporary "fix" to avoid this happening. I have subscribed to the CartService.Events.UPDATED and checked the cart for giftcard codes, if any are applied, I check that the gift-cards are still valid, and if not they're removed from the cart and deleted.

I don't mind doing a pull request for adding some "real" validation to the engine itself, but it requires some feedback from Medusa on how you would like this to be implemented. Should the check happen only on order creation? Should it happen every time the cart is updated? or when gift cards are added? Should the gift cards be removed from the basket, or somehow be marked as invalid in order to enable communication to the customers?

alessioacella commented 6 days ago

This seems like a very important issue, why isn't anyone responding?