medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Gift card expiry date not being respected

Open mortenengel opened this issue 11 months ago • 7 comments

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...

mortenengel avatar Mar 11 '24 10:03 mortenengel

same for coupons

mezzat11 avatar Mar 24 '24 12:03 mezzat11

up

alessioacella avatar Mar 25 '24 08:03 alessioacella

@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.

mezzat11 avatar Mar 29 '24 20:03 mezzat11

I totally agree with you.

alessioacella avatar Apr 05 '24 07:04 alessioacella

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?

mortenengel avatar Apr 05 '24 07:04 mortenengel