medusa
medusa copied to clipboard
Gift card expiry date not being respected
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
- Create a gift-card with an expiration date in the past
- Add it to the cart
- 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:
Gift card used which expired on the 9th:
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...
same for coupons
up
@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.
I totally agree with you.
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?