medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.06k stars 2.63k forks source link

Gift card being applied inconsistently in cart and order #5005

Open Arsenalist opened 1 year ago

Arsenalist commented 1 year ago

To reproduce:

Discord Link: https://discord.com/channels/876835651130097704/1150475042669465692

Medusa version (including plugins): 1..14 Node.js version: 16

Cart screen image

Order screen image

Stripe is getting charged

image

Database: Postgres 12 Operating system: Linux

This piece of code in cart.ts decorateTotals() does not check if region has gift card taxable when calculating gift cardable amount:

    const giftCardTotal = await this.newTotalsService_.getGiftCardTotals(
      cart.subtotal - cart.discount_total,
      {
        region: cart.region,
        giftCards: cart.gift_cards,
      }
    )

While this one in order.ts createFromCart() does:

      const giftCardableAmount =
        (cart.region?.gift_cards_taxable
          ? cart.subtotal! - cart.discount_total!
          : cart.total! + cart.gift_card_total!) || 0 // we re add the gift card total to compensate the fact that the decorate total already removed this amount from the total

I also don't think this is correct decorateTotals() is correct since gift card applies to whole amount in the cart, not just subtotal-discount_total. I mentioned that in Discord as well.

Arsenalist commented 1 year ago

Submitted this: https://github.com/medusajs/medusa/pull/5015

adrien2p commented 1 year ago

@olivermrbl mentionning you here so that you have the full context of the origin of the pr

Arsenalist commented 1 year ago

For the record, I believe the correct behaviour is for the gift card to cover everything (sub total, tax, shipping). So Stripe should not be getting charged at all if gift card is worth like $40