Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix: store credit and gift card checkouts could not be placed (#14740)

Łukasz Adamczyk4edb1a3ff7d3
diff --git a/docs/developer/core-concepts/store-credits-gift-cards.mdx b/docs/developer/core-concepts/store-credits-gift-cards.mdx
index 0c8969ac2b..abb4ca8975 100644
--- a/docs/developer/core-concepts/store-credits-gift-cards.mdx
+++ b/docs/developer/core-concepts/store-credits-gift-cards.mdx
@@ -419,6 +419,8 @@ Store Credits and Gift Cards work differently at checkout:
- **Store Credits** - Require a customer account; applied from the customer's balance
- **Gift Cards** - Can be used by anyone (guests included); applied directly to the order via code
+Both are applied before the customer chooses how to pay, and neither appears among the cart's payment methods. An order uses one or the other, never both. A gift card covers as much of the total as its balance allows and keeps up as the total changes. See the [cart & checkout SDK guide](/developer/sdk/store/cart-checkout) for the calls.
+
### Checkout Flow
```mermaid
diff --git a/docs/developer/sdk/store/cart-checkout.mdx b/docs/developer/sdk/store/cart-checkout.mdx
index bf6308faf7..4757f9fb75 100644
--- a/docs/developer/sdk/store/cart-checkout.mdx
+++ b/docs/developer/sdk/store/cart-checkout.mdx
@@ -77,6 +77,8 @@ const cart = await client.carts.giftCards.apply(cartId, 'GC-ABCD-1234', options)
await client.carts.giftCards.remove(cartId, 'gc_abc123', options);
```
+A gift card pays as much of the total as its balance allows, and its share keeps up when delivery, discounts or tax change the total. A cart can use a gift card or store credit, not both.
+
### Fees and Duties
A cart may carry charges that are neither a product price nor tax: gift wrapping, a handling charge, a cash-on-delivery surcharge, or an import duty on a cross-border order. Each is a [fee](/developer/core-concepts/fees) on the cart, and the storefront should show every one of them before the customer pays.
@@ -174,6 +176,8 @@ await client.carts.storeCredits.apply(cartId, 25.00, options);
await client.carts.storeCredits.remove(cartId, options);
```
+Store credit is a balance, not one of the cart's `payment_methods`: apply it here, then collect whatever `amount_due` is left with a payment method. It can't be combined with a gift card on the same cart.
+
### Totals
The cart and order responses break the amount the customer pays into these totals. Each has a raw string value and a `display_` twin formatted in the cart's currency.
diff --git a/docs/plans/6.0-6.1-loyalty-gift-cards-store-credits.md b/docs/plans/6.0-6.1-loyalty-gift-cards-store-credits.md
index 306f6763f4..3694e16a63 100644
--- a/docs/plans/6.0-6.1-loyalty-gift-cards-store-credits.md
+++ b/docs/plans/6.0-6.1-loyalty-gift-cards-store-credits.md
@@ -130,6 +130,9 @@ The dashboard product form shows a "This product is a gift card" switch that hid
- Any new field on `Spree::StoreCredit` or `Spree::GiftCard` that a merchant would filter on must be added to the Ransack allowlist and the list's filter panel in the same change.
- Product-level behaviour that should not apply to prepaid money (tax, promotions, inventory, shipping) must check a single predicate on the product, so phase 2 can flip it in one place. Do not introduce a second "digital-only" or "non-physical" flag that would have to be reconciled with `gift_card`.
- Gift card codes never appear in events, logs or the buyer-facing order payload. Only the recipient email carries the code.
+- Store credit is never one of a cart's `payment_methods`. It is applied through `POST /carts/:id/store_credits` before the buyer chooses how to pay the rest.
+- A gift card and store credit are never combined on one order. Both apply paths refuse the second.
+- Resize a store credit payment only through `Payment#update_store_credit_amount!`. Completion takes the payment against the eligibility event recorded for its amount, so a bare `update_column(:amount)` leaves the order impossible to place.
## Open Questions
diff --git a/docs/plans/6.0-cart-order-split.md b/docs/plans/6.0-cart-order-split.md
index d5964b4003..11f4ee7eab 100644
--- a/docs/plans/6.0-cart-order-split.md
+++ b/docs/plans/6.0-cart-order-split.md
@@ -167,7 +167,7 @@ PHASE F — FINALIZE (one transaction; every step idempotent)
- **Offline payments collapse PAYMENT into FINALIZE.** With no network call there is nothing to compensate and no partial-failure window, so the whole completion is a single transaction. The three-phase shape exists for external gateways; offline methods take the degenerate path.
- **`payment_required?` is not "must be paid now".** A net-terms order completes with `payment_total: 0` and a `pending` payment — that is a *successfully completed, unpaid* order, not a failure. Completion must gate on "a valid payment exists covering the total" (today's `pending_payments.any? && unprocessed_payments.empty?` guard), never on `paid?`. `UpdateStatuses` reports `payment_status: none/authorized`; dunning and capture are post-completion admin/AR concerns.
-- **Store credit and gift cards are offline by the same rule** — already true today (`recalculate_store_credit_payment` in P3, store-credit payments voided last on compensation).
+- **Store credit and gift cards are offline by the same rule** — store-credit payments are voided last on compensation. A gift card's payment follows the total in `Carts::RecalculateTotals`, which P3's in-lock recalculation runs, so it is current when Y processes it (decisions.md 2026-09-24).
- **Mixed offline + external** (deposit on card, remainder on terms): any external component forces the external path; the offline components are processed inside the same phase and voided alongside on compensation.
- **B2B/backoffice orders** created through the Admin API bypass this pipeline's checkout ergonomics but must reuse the same service so idempotency, inventory finalization, and reservation release stay in one place — fixing today's asymmetry where `Orders::Complete` never releases reservations.
- **`allow_checkout_on_gateway_error`** keeps its meaning for external methods only; it must not mask offline failures (which indicate a bug or a rule violation, not a flaky network).
@@ -177,7 +177,7 @@ PHASE F — FINALIZE (one transaction; every step idempotent)
- **Async success (3DS / redirect / webhook).** Both writers call the same service: the customer's return-page `POST /complete` and `Payments::HandleWebhook`. Whoever runs first creates the order; the other replays it. The webhook keeps its `order.with_lock` + replay check, but safety comes from the unique index — the current 30-second job delay becomes a latency optimization, not a correctness mechanism.
- **Webhook says failed.** Mark the payment session failed; do **not** compensate an order unless one exists in `draft` with no other valid payment — then compensate as Y3. Cart stays active for another attempt.
- **Payment captured, finalize keeps failing** (e.g. DB partition). The order exists as `draft` with a successful payment. **Never auto-refund on transient failure.** A completion-recovery sweeper retries FINALIZE for stale `draft` orders with paid coverage; persistent failures alert operators. This is the precise scenario the order-before-payment ordering minimizes.
-- **Partial store credit + external payment.** Store-credit payments are (re)calculated in P3 (`recalculate_store_credit_payment` behavior carries over); the external session covers the remainder; Y2 processes both, store credit last-voided on compensation.
+- **Partial store credit or gift card + external payment.** A gift card's payment is resized by every totals recalculation, P3's included, and released when the total reaches zero. Applied store credit keeps the amount the buyer applied until it is applied again; nothing resizes it, so a total that falls below it overcharges the credit (open, decisions.md 2026-09-24). The two are never combined on one order. The external session covers the remainder; Y2 processes both, store credit last-voided on compensation.
- **Zero-total carts** (100% promo, gift card): Y is skipped entirely; F runs. The "never auto-complete during address updates" rule stays in `Carts::Update#try_advance` — only an explicit `Complete` call reaches this pipeline.
- **Late webhook after cart expiry.** Cannot happen by construction: the reaper never deletes carts with authorized/pending payment sessions (money-safety exclusion, Key Decision 7).
diff --git a/docs/plans/6.0-core-rewrite-tasks.md b/docs/plans/6.0-core-rewrite-tasks.md
index e5232d345c..01ba37d61b 100644
--- a/docs/plans/6.0-core-rewrite-tasks.md
+++ b/docs/plans/6.0-core-rewrite-tasks.md
@@ -230,7 +230,7 @@ The point of no return; biggest single wave. Everything before it exists so this
### T5.2 `Carts::Complete` — three-phase pipeline
- [x] **PREPARE** (one txn): replay via `completion_result(cart)` (order or order_group); `with_lock` + `completing_at` with TTL takeover; in-lock recalculation; `expected_total` drift guard (409 `cart_changed`); Validate; reservation availability check + hold extension; draft Order creation with copies (line items re-pointed, typed lines per the split-adjustments copy contract, fulfillments + selected rates, **address copies**, email/currency/locale/market/channel, guest token carried, `R` number) + unique `orders.cart_id`.
-- [x] **PAYMENT:** offline methods (Check, terms, COD, bank transfer, store credit, gift cards, manual) collapse into FINALIZE — single txn, nothing to compensate; external gateways outside any txn with Y3 compensation (destroy draft + copies, clear `completing_at`, 422 `payment_failed`); completion gates on "valid payment covers total", never `paid?`; store credit recalculated in P3 and voided last; `allow_checkout_on_gateway_error` external-only.
+- [x] **PAYMENT:** offline methods (Check, terms, COD, bank transfer, store credit, gift cards, manual) collapse into FINALIZE — single txn, nothing to compensate; external gateways outside any txn with Y3 compensation (destroy draft + copies, clear `completing_at`, 422 `payment_failed`); completion gates on "valid payment covers total", never `paid?`; gift card payments resized by every totals recalculation, P3's included (decisions.md 2026-09-24), and store credit voided last; `allow_checkout_on_gateway_error` external-only.
- [x] **FINALIZE** (one txn, every step idempotent): inventory finalize + unstock + reservation release (single home — fixes the admin-path asymmetry); counters behind persisted flags (coupon, gift card redeem, promo credits); vendor-split hook F3 (no-op single partition); `draft`→`placed` + `cart.completed_at` + `UpdateStatuses`; after_commit events (`order.placed`/`order.completed`), digital fulfillment via provider, account creation/newsletter as non-fatal side jobs.
- [x] Resumability structural (`status: 'draft'` + `cart_id` + `completed_at: nil` = finalize pending); completion-recovery sweeper job (retries FINALIZE for stale drafts with paid coverage; alerts on persistent failure; **never auto-refunds**); webhook writer (`Payments::HandleWebhook`) converges on the same service — 30s delay becomes latency optimization only.
- [x] Mutation guards: `completing_at` → 409 `cart_locked` on item/address/discount writes; `lock_version` → 409 `stale_cart`.
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index eaca1c9da1..1504134815 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1,3 +1,15 @@
+## 2026-09-24: Store credit is applied rather than chosen, and a gift card follows the total it pays
+
+**Context:** A buyer with a gift card that did not cover the cart was offered Store Credit as the only payment method, and Place Order did nothing (V-3668). Reproduced on `main` against a fresh install, which seeds exactly one payment method, Store Credit: $44.99 cart, card with $10.01 left, amount due $34.98, `payment_methods` `[Store Credit]`, and `POST /carts/:id/payments` answered 422 "Source can't be blank". The gift card was only what put Store Credit in the list: a buyer holding store credit and no gift card failed the same way, because that endpoint builds a payment with no source and a store credit payment needs one. The docs already describe store credit as a balance applied through `POST /carts/:id/store_credits` before choosing how to pay. Testing the combinations turned up four more defects. A gift card's payment never moved with the total: the resize existed as `Order#recalculate_store_credit_payment`, ran from `before_transition to: :payment`, and lost its only caller when the state machine went (6ff55b19f8), so a buyer paid $5.00 by card where $2.99 was owed while the gift card still held $2.01 — and switching to a cheaper delivery left the card paying the old, higher amount. Any change to a store credit payment's amount made the order impossible to place ("Could not find store credit"): `PaymentMethod::StoreCredit#purchase` takes a payment against the eligibility event recorded for its amount, and only creation recorded one. Applying credit, adding an address and applying credit again was enough. The same resize also counted the payment twice against its own credit, so a $30 credit ended up behind a $44.99 payment, the cart showed nothing due, and Place Order failed. `StoreCredits::Apply` spent a gift card's credit as if it were the buyer's own, so the card's balance paid for another cart while its own cart could neither be placed nor have the card removed. And mixing the two was refused in one direction only: store credit applied after a gift card inflated the card's payment, $10.01 of balance ending up behind $24.99 of payments.
+
+**Decision:** Store credit is never one of a cart's `payment_methods` (`Purchase::PaymentProcessing`), and the Store API payments endpoint refuses store credit, which passes its active-and-storefront-visible lookup but could only ever fail there. The deprecated `Order#collect_payment_methods` delegates to it rather than keeping its own copy of the rule. The `order.gift_card.present?` clause in `PaymentMethod::StoreCredit#available_for_order?` stays, because `Payment`'s own validation needs it for the gift card's payment. Resizing a store credit payment goes through one method, `Payment#update_store_credit_amount!`, which records a new eligibility event; `StoreCredits::Apply` and the gift card resize both use it. A resized payment grows only into its own credit's remaining balance, since a payment not yet taken reserves nothing, and any shortfall is drawn from the buyer's other credits, never the same one again. A gift card's payment follows the total in `Carts::RecalculateTotals` (orders inherit it), the seam every totals change passes through, including P3's in-lock recalculation. When the total reaches zero the card is released rather than resized, since a store credit cannot hold zero and a stale amount would charge the card for a free order. The resize draws only what the card can still give (`GiftCard#spendable_amount`): nothing more once it has expired, been redeemed or been cancelled, and never less than it already pays when an admin lowers the card's amount below what is in use. `GiftCards::Apply` sizes a new payment the same way. Item changes still unapply the card in `Carts::Recalculate`, as before. A gift card and store credit are never combined: `StoreCredits::Apply` refuses once a gift card is on the order, mirroring `GiftCards::Apply`, and draws only on the credits the buyer's balance counts — their own, in the order's store and currency.
+
+Rejected: seeding Store Credit with `storefront_visible: false`, which every existing install would miss and an admin could switch back on. Also rejected: dropping the gift card clause from `available_for_order?`, which breaks gift card application outright — tested. Also rejected: resizing only at completion, which the old plan text described. The amount due shown during checkout would stay wrong, and a remainder payment sized from it would overpay once the card grew.
+
+**Consequences:** Store Credit leaves the storefront's payment list. The storefront has no control that applies store credit, so its buyers cannot use store credit until it calls the endpoint; that is a storefront change, deliberately out of scope here. `POST /payments` now answers 422 `payment_method_unavailable` for store credit instead of "Source can't be blank". A cart that a gift card covers in full still completes without a payment, since the storefront already skips payment when nothing is due. Plain store credit is still not resized when the total changes, and the plans now say so instead of claiming it was. That leaves a pre-existing defect standing, reproduced here: a buyer who applies credit and then picks a cheaper delivery is charged the old amount — order R1028 took $44.99 of credit on a $39.99 total and reads `overcharged`. Shrinking the credit to fit the total would fix it; whether credit should also grow with the total is a product decision, so both are deferred. Gift card specs that faked totals on orders with no items now build real ones — they had asserted a $30 payment on an order whose recalculated total was $0, which held only because nothing resized it. Left alone, all pre-existing: one ordinary store credit can sit on two open carts at once, and the second fails at Place Order with no money lost — deferred. On an order authorised at checkout and charged later, `amount_due` subtracts captured store credit twice — skipped. The storefront shows nothing when Place Order fails. The Bogus test gateway never settles a payment session. A payment session for store credit answers 500. Applying a gift card to an empty cart reports "Amount must be greater than 0". The older refusal, a gift card after store credit, returns its untranslated key. `StoreCredits::Apply` takes the store credit payment method without scoping it to the order's store. The deprecated `Order#available_payment_methods` passes an argument that `collect_payment_methods` does not take, so it raises.
+
+**Plans amended:** `6.0-cart-order-split.md` (the offline payments bullet and the partial store credit edge case), `6.0-core-rewrite-tasks.md` (the PAYMENT line), `6.0-6.1-loyalty-gift-cards-store-credits.md` (three new Constraints on Current Work bullets).
+
## 2026-09-25: Editing a placed order's money re-derives its payment status
**Context:** Adding a charge to a paid order left it reading `paid` with money owed (V-3638). Reproduced on `main`: order R1001, total $205.00, paid $205.00; a $50.00 fee took the total to $255.00 and `amount_due` to $50.00 while `payment_status` stayed `paid`, and `update_statuses!` answered `partially_paid` at once. The stale status then stuck through every later edit: deleting the fee left a fully paid order reading `partially_paid`, and cutting a quantity until the customer had paid $100.00 over the total still read `partially_paid` rather than `overcharged`. The cause is a gap in the trigger list. `UpdateStatuses` runs from payment, refund, store credit, fulfillment and return events, and the post-placement edit services (fees, manual discounts, items) re-sum the totals and stop, because no event announces a total moving. Changing a fulfillment's delivery rate was the one edit that worked: `Fulfillments::Update` calls `update_statuses!` itself.
diff --git a/spree/api/app/controllers/spree/api/v3/store/carts/payments_controller.rb b/spree/api/app/controllers/spree/api/v3/store/carts/payments_controller.rb
index 1e1ec5c8c8..fd05ba9392 100644
--- a/spree/api/app/controllers/spree/api/v3/store/carts/payments_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/carts/payments_controller.rb
@@ -25,7 +25,9 @@ module Spree
)
end
- unless payment_method.available_for_order?(@cart)
+ # Store credit passes the lookup above but has its own endpoint, so
+ # it is never among the methods the cart offers.
+ unless @cart.payment_methods.include?(payment_method)
return render_error(
code: 'payment_method_unavailable',
message: Spree.t('api.v3.payments.method_unavailable'),
diff --git a/spree/api/spec/controllers/spree/api/v3/store/carts/gift_card_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/carts/gift_card_controller_spec.rb
index bbd8d7e3c6..83cc92fbb2 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/carts/gift_card_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/carts/gift_card_controller_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Spree::Api::V3::Store::Carts::GiftCardsController, type: :control
end
context 'when the card is already held by the customer\'s other cart' do
- let!(:other_cart) { create(:cart_with_line_items, store: store, customer: user) }
+ let!(:other_cart) { create(:cart_with_line_items, store: store, customer: user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
@@ -71,7 +71,7 @@ RSpec.describe Spree::Api::V3::Store::Carts::GiftCardsController, type: :control
end
context 'when the other cart is being completed' do
- let!(:other_cart) { create(:cart_with_line_items, store: store, customer: user) }
+ let!(:other_cart) { create(:cart_with_line_items, store: store, customer: user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
diff --git a/spree/api/spec/controllers/spree/api/v3/store/carts/payments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/store/carts/payments_controller_spec.rb
index 949787149e..df8193d3f9 100644
--- a/spree/api/spec/controllers/spree/api/v3/store/carts/payments_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/store/carts/payments_controller_spec.rb
@@ -81,6 +81,17 @@ RSpec.describe Spree::Api::V3::Store::Carts::PaymentsController, type: :controll
expect(response).to have_http_status(:not_found)
end
+ it 'rejects store credit, which is applied through its own endpoint' do
+ store_credit_method = create(:store_credit_payment_method, store: store)
+ create(:store_credit, customer: user, store: store, currency: order.currency)
+
+ post :create, params: { cart_id: order.prefixed_id, payment_method_id: store_credit_method.prefixed_id }
+
+ expect(response).to have_http_status(:unprocessable_content)
+ expect(json_response['error']['code']).to eq('payment_method_unavailable')
+ expect(order.reload.payments).to be_empty
+ end
+
it 'returns not found for invalid payment method' do
post :create, params: { cart_id: order.prefixed_id, payment_method_id: 'pm_invalid' }
diff --git a/spree/core/app/models/concerns/spree/purchase/gift_cards.rb b/spree/core/app/models/concerns/spree/purchase/gift_cards.rb
index 81e1a5246a..49c369eb3e 100644
--- a/spree/core/app/models/concerns/spree/purchase/gift_cards.rb
+++ b/spree/core/app/models/concerns/spree/purchase/gift_cards.rb
@@ -51,16 +51,22 @@ module Spree
payment = payments.checkout.store_credits.where(source: gift_card.store_credits).first
return unless payment
+ # Nothing is left for the card to pay, and a store credit cannot hold
+ # a zero amount, so the card is released rather than resized.
+ return remove_gift_card unless total.positive?
gift_card.with_lock do
- new_amount = [gift_card.amount_remaining + payment.amount, total].min
+ # A locking read: a plain reload can return the transaction's older
+ # snapshot, and a resize committed since would be applied again.
+ payment.lock!
+ new_amount = [gift_card.spendable_amount + payment.amount, total].min
next if payment.amount == new_amount
difference = new_amount - payment.amount
- # update_column bypasses Payment#max_amount validation which can
- # fail on stale in-memory state; bounds enforced via min() above.
- payment.update_column(:amount, new_amount)
payment.source.update_column(:amount, new_amount)
+ # Skips Payment#max_amount, which can fail on stale in-memory state;
+ # min() above bounds the amount.
+ payment.update_store_credit_amount!(new_amount)
gift_card.amount_used += difference
gift_card.save!
end
diff --git a/spree/core/app/models/concerns/spree/purchase/payment_processing.rb b/spree/core/app/models/concerns/spree/purchase/payment_processing.rb
index c3a90b7d58..f60af73bc9 100644
--- a/spree/core/app/models/concerns/spree/purchase/payment_processing.rb
+++ b/spree/core/app/models/concerns/spree/purchase/payment_processing.rb
@@ -31,11 +31,15 @@ module Spree
payments.pending
end
- # Active front-end payment methods available for this record.
+ # Active front-end payment methods available for this record. Store
+ # credit is never one of them: it is applied through its own endpoint
+ # before the buyer chooses how to pay the rest.
#
# @return [Array<Spree::PaymentMethod>]
def payment_methods
- store.payment_methods.active.storefront_visible.select { |payment_method| payment_method.available_for_order?(self) }
+ store.payment_methods.active.storefront_visible.select do |payment_method|
+ !payment_method.store_credit? && payment_method.available_for_order?(self)
+ end
end
# Free checkouts have no money to collect.
diff --git a/spree/core/app/models/spree/gift_card.rb b/spree/core/app/models/spree/gift_card.rb
index 73033ca134..ba0b06056a 100644
--- a/spree/core/app/models/spree/gift_card.rb
+++ b/spree/core/app/models/spree/gift_card.rb
@@ -94,6 +94,17 @@ module Spree
amount - amount_used - amount_authorized
end
+ # What the card can still give towards an order: nothing once it has
+ # expired, been redeemed or been cancelled, and never less than zero,
+ # since an admin can lower the amount below what is already in use.
+ #
+ # @return [BigDecimal]
+ def spendable_amount
+ return BigDecimal('0') if expired? || redeemed? || canceled?
+
+ [amount_remaining, 0].max
+ end
+
delegate :email, to: :customer, prefix: true, allow_nil: true
def self.json_api_columns
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index 2d26eb68d2..91611171ef 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -1341,22 +1341,11 @@ module Spree
def collect_payment_methods
Spree::Deprecation.warn('`Order#collect_payment_methods` is deprecated and will be removed in Spree 6.1. Use `payment_methods` instead.')
- store.payment_methods.active.storefront_visible.select { |pm| pm.available_for_order?(self) }
+ payment_methods
end
def credit_card_nil_payment?(attributes)
payments.store_credits.present? && attributes[:amount].to_f.zero?
end
-
- def recalculate_store_credit_payment
- recalculate_totals! if using_store_credit?
-
- if gift_card.present?
- recalculate_gift_card
- elsif using_store_credit?
- Spree.store_credit_apply_service.call(order: self)
- end
- end
-
end
end
diff --git a/spree/core/app/models/spree/payment.rb b/spree/core/app/models/spree/payment.rb
index ba1a2a1edf..5e49855c5c 100644
--- a/spree/core/app/models/spree/payment.rb
+++ b/spree/core/app/models/spree/payment.rb
@@ -263,6 +263,19 @@ module Spree
end || amount
end
+ # Resizes a store credit payment that has not been taken yet. Completion
+ # takes it against the eligibility event recorded for its amount, so the
+ # new amount needs one of its own.
+ #
+ # @param new_amount [BigDecimal]
+ # @return [void]
+ def update_store_credit_amount!(new_amount)
+ return if amount == new_amount
+
+ update_column(:amount, new_amount)
+ create_eligible_credit_event
+ end
+
def offsets_total
offsets.sum(:amount)
end
diff --git a/spree/core/app/services/spree/store_credits/apply.rb b/spree/core/app/services/spree/store_credits/apply.rb
index fb1e4fb8c7..18e430c21b 100644
--- a/spree/core/app/services/spree/store_credits/apply.rb
+++ b/spree/core/app/services/spree/store_credits/apply.rb
@@ -13,7 +13,10 @@ module Spree
# credit payment for a negative amount.
remaining_total = [amount ? [amount, @order.outstanding_balance].min : @order.outstanding_balance, 0].max
- return failure(nil, Spree.t(:error_user_does_not_have_any_store_credits)) unless @order.customer&.store_credits&.any?
+ # Mirrors Spree::GiftCards::Apply, which refuses a gift card once store
+ # credit is in use: the two are never combined on one order.
+ return failure(nil, Spree.t(:store_credit_using_gift_card_error)) if @order.gift_card.present?
+ return failure(nil, Spree.t(:error_user_does_not_have_any_store_credits)) unless spendable_store_credits.exists?
ApplicationRecord.transaction do
existing = @order.payments.store_credits.where(status: :checkout)
@@ -40,12 +43,10 @@ module Spree
# creating unnecessary invalid payment records on every recalculation.
def update_existing_payments(payments, remaining_total)
payments.each do |payment|
- credit = payment.source
- available = credit.amount_remaining + payment.amount
- new_amount = [available, remaining_total].min
+ new_amount = store_credit_amount(payment.source, remaining_total)
if new_amount.positive?
- payment.update_column(:amount, new_amount)
+ payment.update_store_credit_amount!(new_amount)
remaining_total -= new_amount
else
payment.invalidate!
@@ -53,19 +54,14 @@ module Spree
end
# If there's still remaining total, apply from additional store credits
- apply_store_credits(remaining_total) if remaining_total.positive?
+ apply_store_credits(remaining_total, except: payments.map(&:source_id)) if remaining_total.positive?
end
- def apply_store_credits(remaining_total)
+ def apply_store_credits(remaining_total, except: [])
payment_method = Spree::PaymentMethod::StoreCredit.available.first
raise 'Store credit payment method could not be found' unless payment_method
- # Only credits in the order's own currency: an older credit in another
- # currency would be drawn against first and, being unusable, either
- # overshoot the allowed amount or persist a payment that fails later
- # at authorization. This matches what the order already counts as
- # available (Purchase::StoreCredits#total_available_store_credit).
- @order.customer.store_credits.for_store(@order.store).where(currency: @order.currency).oldest_first.each do |credit|
+ spendable_store_credits.where.not(id: except).oldest_first.each do |credit|
break unless remaining_total.positive?
next if credit.amount_remaining.zero?
@@ -75,6 +71,12 @@ module Spree
end
end
+ def spendable_store_credits
+ return Spree::StoreCredit.none unless @order.customer
+
+ @order.customer.store_credits.without_gift_card.for_store(@order.store).where(currency: @order.currency)
+ end
+
def create_store_credit_payment(payment_method, credit, amount)
@order.payments.create!(
source: credit,
diff --git a/spree/core/app/workflows/spree/carts/recalculate_totals.rb b/spree/core/app/workflows/spree/carts/recalculate_totals.rb
index 2f9e7326a4..13c8a1e9ac 100644
--- a/spree/core/app/workflows/spree/carts/recalculate_totals.rb
+++ b/spree/core/app/workflows/spree/carts/recalculate_totals.rb
@@ -40,6 +40,7 @@ module Spree
step :fold_typed_rows
step :refresh_grand_total
step :persist_totals
+ step :resize_gift_card_payment unless money_frozen?
success(cart)
end
@@ -175,6 +176,10 @@ module Spree
cart.update_columns(columns)
end
+ def resize_gift_card_payment
+ cart.recalculate_gift_card
+ end
+
def money_frozen?
resum_only || (cart.is_a?(Spree::Order) && cart.completed?)
end
diff --git a/spree/core/app/workflows/spree/gift_cards/apply.rb b/spree/core/app/workflows/spree/gift_cards/apply.rb
index 6c5dc02244..e59b17e12b 100644
--- a/spree/core/app/workflows/spree/gift_cards/apply.rb
+++ b/spree/core/app/workflows/spree/gift_cards/apply.rb
@@ -185,7 +185,7 @@ module Spree
end
def amount
- @amount ||= [gift_card.amount_remaining, order.total].min
+ @amount ||= [gift_card.spendable_amount, order.total].min
end
def issue_store_credit
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index 2b77c818ca..744bc78017 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -2159,6 +2159,7 @@ en:
unable_to_find: Could not find store credit
unable_to_find_for_action: 'Could not find store credit for auth code: %{auth_code} for action: %{action}'
unable_to_void: 'Unable to void code: %{auth_code}'
+ store_credit_using_gift_card_error: You can't apply store credit after you applied a gift card.
store_credits: Store Credits
store_default: Default store
store_name: Store name
diff --git a/spree/core/spec/models/concerns/spree/purchase/payment_processing_spec.rb b/spree/core/spec/models/concerns/spree/purchase/payment_processing_spec.rb
index 483dee51c0..7b975fa130 100644
--- a/spree/core/spec/models/concerns/spree/purchase/payment_processing_spec.rb
+++ b/spree/core/spec/models/concerns/spree/purchase/payment_processing_spec.rb
@@ -153,9 +153,19 @@ RSpec.shared_examples 'a payment processing host' do
end
it 'excludes methods that report themselves unavailable for the record' do
- # Store credit is only offered when the customer actually holds credit.
+ unavailable = create(:credit_card_payment_method, store: store)
+ allow_any_instance_of(unavailable.class).to receive(:available_for_order?).and_return(false)
+
+ expect(record.payment_methods).not_to include(unavailable)
+ end
+
+ it 'never lists store credit, which is applied through its own endpoint' do
store_credit_method = create(:store_credit_payment_method, store: store)
+ customer = create(:customer)
+ record.update!(customer: customer)
+ create(:store_credit, customer: customer, store: store, currency: record.currency)
+ expect(store_credit_method.available_for_order?(record)).to be(true)
expect(record.payment_methods).not_to include(store_credit_method)
end
end
diff --git a/spree/core/spec/models/spree/catalog_for_buyer_spec.rb b/spree/core/spec/models/spree/catalog_for_buyer_spec.rb
index 18c1f62f33..82acf4a18a 100644
--- a/spree/core/spec/models/spree/catalog_for_buyer_spec.rb
+++ b/spree/core/spec/models/spree/catalog_for_buyer_spec.rb
@@ -59,7 +59,7 @@ RSpec.describe Spree::Catalog, '.for_buyer' do
Spree::Current.reset_catalog_memos
queries = 0
subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*, payload|
- queries += 1 if payload[:sql].to_s.include?('spree_companies')
+ queries += 1 if payload[:sql].to_s.include?('spree_companies') && !payload[:name].to_s.include?('SCHEMA')
end
5.times { described_class.for_buyer(store: store, customer: customer) }
diff --git a/spree/core/spec/models/spree/order_merger_spec.rb b/spree/core/spec/models/spree/order_merger_spec.rb
index 99467afbea..05faf41446 100644
--- a/spree/core/spec/models/spree/order_merger_spec.rb
+++ b/spree/core/spec/models/spree/order_merger_spec.rb
@@ -158,8 +158,8 @@ module Spree
end
context 'merging an order with a gift card' do
- let(:order_1) { create(:order, total: 20) }
- let(:order_2) { create(:order, gift_card: gift_card, total: 20) }
+ let(:order_1) { create(:order_with_totals, total: 20, line_items_price: 20) }
+ let(:order_2) { create(:order_with_totals, gift_card: gift_card, total: 20, line_items_price: 20) }
let(:gift_card) { create(:gift_card, amount: 20, amount_used: 20) }
let(:store_credit_payment_method) { create(:store_credit_payment_method) }
let(:store_credit) { create(:store_credit, originator: gift_card, amount: 20) }
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index e318490a5d..2fb6b280b9 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -507,8 +507,8 @@ describe Spree::Order, type: :model do
# Regression test for #4199
describe '#collect_frontend_payment_methods' do
- let(:ok_method) { double :payment_method, available_for_order?: true, available_for_store?: true, store: store }
- let(:no_method) { double :payment_method, available_for_order?: false, available_for_store?: true, store: store }
+ let(:ok_method) { double :payment_method, store_credit?: false, available_for_order?: true, available_for_store?: true, store: store }
+ let(:no_method) { double :payment_method, store_credit?: false, available_for_order?: false, available_for_store?: true, store: store }
let(:methods) { [ok_method, no_method] }
let(:store_2) { create(:store) }
let(:order_from_different_store) { create(:order, customer: user, store: store_2) }
diff --git a/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb b/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
index 51b4a3d37a..fab70dbb8b 100644
--- a/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
+++ b/spree/core/spec/models/spree/promotion_handler/coupon_with_gift_card_spec.rb
@@ -23,7 +23,7 @@ describe Spree::PromotionHandler::Coupon, type: :model do
end
context 'when the gift card is held by another open order' do
- let(:old_order) { create(:order, store: store) }
+ let(:old_order) { create(:order_with_totals, store: store, line_items_price: 30) }
before do
old_order.update_column(:total, 30)
diff --git a/spree/core/spec/services/spree/store_credits/apply_spec.rb b/spree/core/spec/services/spree/store_credits/apply_spec.rb
index 5c612ac827..765ef091c0 100644
--- a/spree/core/spec/services/spree/store_credits/apply_spec.rb
+++ b/spree/core/spec/services/spree/store_credits/apply_spec.rb
@@ -117,6 +117,12 @@ describe Spree::StoreCredits::Apply, type: :service do
expect(order.payments.where(status: 'invalid').count).to eq(0)
end
+ it 'records no new eligibility event when the amount has not changed' do
+ eligible_events = store_credit.store_credit_events.where(action: Spree::StoreCredit::ELIGIBLE_ACTION)
+
+ expect { described_class.call(order: order.reload) }.not_to(change { eligible_events.count })
+ end
+
it 'adjusts amount when order total changes' do
order.update_column(:total, 300)
@@ -126,6 +132,68 @@ describe Spree::StoreCredits::Apply, type: :service do
expect(order.payments.store_credits.checkout.count).to eq(1)
expect(order.payments.store_credits.checkout.first.amount).to eq(300)
end
+
+ # Regression: completion takes a store credit payment against the event
+ # recorded for its amount, so a payment resized after creation could no
+ # longer be taken ("Could not find store credit").
+ it 'can still take the payment after its amount changes' do
+ order.update_column(:total, 300)
+
+ described_class.call(order: order.reload)
+ payment = order.reload.payments.store_credits.checkout.first
+ payment.purchase!
+
+ expect(payment.reload).to be_completed
+ expect(store_credit.reload.amount_used).to eq(300)
+ end
+ end
+
+ # Regression: a payment not yet taken reserves nothing from its credit, but
+ # the resize counted it twice, so re-applying a credit smaller than the new
+ # total claimed more than it held and completion then failed.
+ context 'when re-applied after the total grows past the credit' do
+ let(:store_credit) { create(:store_credit, amount: 30, store: store) }
+ let(:order) { create(:order, customer: store_credit.customer, total: 40, store: store) }
+
+ before do
+ order.update_column(:total, 40)
+ described_class.call(order: order)
+ order.update_column(:total, 45)
+ end
+
+ it 'never takes more than the credit holds' do
+ described_class.call(order: order.reload)
+
+ payments = order.reload.payments.store_credits.checkout
+ expect(payments.count).to eq(1)
+ expect(payments.sum(:amount)).to eq(30)
+ end
+
+ it 'draws the rest from another credit rather than the same one twice' do
+ create(:store_credit, customer: store_credit.customer, amount: 100, store: store)
+
+ described_class.call(order: order.reload)
+
+ by_credit = order.reload.payments.store_credits.checkout.to_a.group_by(&:source_id).transform_values { |payments| payments.sum(&:amount) }
+ expect(by_credit[store_credit.id]).to eq(30)
+ expect(by_credit.values.sum).to eq(45)
+ end
+ end
+
+ context 'when a gift card is applied to the order' do
+ let(:store_credit) { create(:store_credit, amount: 500, store: store) }
+ let(:order) do
+ create(:order, customer: store_credit.customer, total: order_total, store: store,
+ gift_card: create(:gift_card, store: store))
+ end
+
+ before { order.update_column(:total, order_total) }
+
+ it 'refuses, since a gift card and store credit are not combined on one order' do
+ expect(subject).not_to be_success
+ expect(subject.error.to_s).to eq("You can't apply store credit after you applied a gift card.")
+ expect(order.reload.payments.store_credits).to be_empty
+ end
end
context 'there are multiple store credits' do
@@ -211,4 +279,39 @@ describe Spree::StoreCredits::Apply, type: :service do
expect(payments.first.amount).to eq(30)
end
end
+
+ # Regression: applying a gift card issues the customer a store credit that
+ # backs the card's payment on that one order. Drawing store credit for another
+ # order spent that balance a second time, leaving the gift card's own order
+ # unable to complete.
+ context 'when the customer holds a store credit issued by a gift card' do
+ let(:gift_card_customer) { create(:customer) }
+ let(:gift_card_order) { create(:order_with_line_items, store: store, customer: gift_card_customer) }
+
+ before do
+ create(:store_credit_payment_method)
+ gift_card_order.update_columns(total: 100, item_total: 100, payment_total: 0)
+ create(:store_credit, customer: gift_card_customer, amount: 80, store: store,
+ originator: create(:gift_card, amount: 100, store: store), created_at: 2.days.ago)
+ end
+
+ it "draws only against the customer's own store credit" do
+ create(:store_credit, customer: gift_card_customer, amount: 30, store: store, created_at: 1.day.ago)
+
+ described_class.call(order: gift_card_order)
+
+ payments = gift_card_order.reload.payments.store_credits
+ expect(payments.count).to eq(1)
+ expect(payments.first.source.originator).to be_nil
+ expect(payments.first.amount).to eq(30)
+ end
+
+ it 'refuses when the customer has no store credit of their own' do
+ result = described_class.call(order: gift_card_order)
+
+ expect(result).not_to be_success
+ expect(result.error.to_s).to eq('User does not have any Store Credits available')
+ expect(gift_card_order.reload.payments.store_credits).to be_empty
+ end
+ end
end
diff --git a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
index 296d8b5023..204cc1c4b7 100644
--- a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
@@ -120,6 +120,77 @@ module Spree
expect { described_class.call(cart: cart) }.not_to raise_error
expect(described_class.call(cart: cart)).to be_success
end
+
+ # Totals move without the items changing (delivery, a coupon, tax), and
+ # nothing else resizes the card's payment to follow them.
+ context 'with a gift card paying towards it' do
+ let(:gift_card) { create(:gift_card, amount: 100, store: store) }
+ let(:line_item) { cart.line_items.first }
+ let(:gift_card_payment) { cart.reload.payments.store_credits.checkout.first }
+
+ before do
+ create(:store_credit_payment_method)
+ cart.apply_gift_card(gift_card)
+ end
+
+ it 'grows the gift card payment when the total rises' do
+ line_item.update_column(:price, 25)
+
+ described_class.call(cart: cart)
+
+ expect(gift_card_payment.amount).to eq(cart.reload.total)
+ expect(gift_card.reload.amount_used).to eq(cart.total)
+ end
+
+ it 'shrinks it and returns the difference to the card when the total falls' do
+ line_item.update_column(:price, 5)
+
+ described_class.call(cart: cart)
+
+ expect(gift_card_payment.amount).to eq(cart.reload.total)
+ expect(gift_card.reload.amount_used).to eq(cart.total)
+ end
+
+ it 'releases the card and restores its balance when nothing is left to pay' do
+ line_item.update_column(:price, 0)
+
+ described_class.call(cart: cart)
+
+ expect(cart.reload.gift_card).to be_nil
+ expect(cart.payments.store_credits.checkout).to be_empty
+ expect(gift_card.reload.amount_used).to eq(0)
+ end
+
+ it 'draws no more from a card that has expired since it was applied' do
+ paid = gift_card_payment.amount
+ gift_card.update_column(:expires_at, 1.day.ago)
+ line_item.update_column(:price, 25)
+
+ described_class.call(cart: cart)
+
+ expect(gift_card_payment.reload.amount).to eq(paid)
+ expect(gift_card.reload.amount_used).to eq(paid)
+ end
+
+ it 'keeps what the card already pays when its amount is lowered below that' do
+ paid = gift_card_payment.amount
+ gift_card.update_column(:amount, 1)
+ line_item.update_column(:price, 25)
+
+ described_class.call(cart: cart)
+
+ expect(gift_card_payment.reload.amount).to eq(paid)
+ end
+
+ it 'leaves a resized payment that completion can still take' do
+ line_item.update_column(:price, 25)
+ described_class.call(cart: cart)
+
+ gift_card_payment.purchase!
+
+ expect(gift_card_payment.reload).to be_completed
+ end
+ end
end
end
end
diff --git a/spree/core/spec/workflows/spree/gift_cards/apply_spec.rb b/spree/core/spec/workflows/spree/gift_cards/apply_spec.rb
index f42feab215..0d2c983838 100644
--- a/spree/core/spec/workflows/spree/gift_cards/apply_spec.rb
+++ b/spree/core/spec/workflows/spree/gift_cards/apply_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Spree::GiftCards::Apply do
subject { described_class.call(gift_card: gift_card, order: order) }
let(:store) { Spree::Store.default }
- let(:order) { create(:order, store: store, customer: order_user) }
+ let(:order) { create(:order_with_totals, store: store, customer: order_user, line_items_price: 30) }
let(:order_user) { create(:user) }
let(:gift_card) { create(:gift_card, amount: 50, store: store, customer: gift_card_user) }
@@ -14,7 +14,6 @@ RSpec.describe Spree::GiftCards::Apply do
before do
order.update_column(:total, 30)
- order.update_column(:shipment_total, 10)
end
it 'applies the gift card to an order' do
@@ -110,7 +109,7 @@ RSpec.describe Spree::GiftCards::Apply do
let(:users) { Array.new(5) { create(:user) } }
let(:orders) do
users.map do |user|
- order = create(:order, store: store, customer: user)
+ order = create(:order_with_totals, store: store, customer: user, line_items_price: 80)
order.update_columns(total: 80, item_total: 80)
order
end
@@ -173,7 +172,7 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'when the gift card is already held by another open cart' do
- let(:other_cart) { create(:cart, store: store, customer: order_user) }
+ let(:other_cart) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
@@ -224,7 +223,7 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'when a hold no longer carries this card' do
- let!(:other_cart) { create(:cart, store: store, customer: order_user) }
+ let!(:other_cart) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 50) }
let!(:replacement_card) { create(:gift_card, amount: 50, store: store) }
before do
@@ -253,8 +252,8 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'when several carts hold the card' do
- let!(:first_hold) { create(:cart, store: store, customer: order_user) }
- let!(:second_hold) { create(:cart, store: store, customer: order_user) }
+ let!(:first_hold) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 10) }
+ let!(:second_hold) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 10) }
# Applying twice would move the card rather than leave both holding it,
# so the second hold is attached directly — the state this workflow has
@@ -299,7 +298,7 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'when a hold claims completion after the list is gathered' do
- let!(:other_cart) { create(:cart, store: store, customer: order_user) }
+ let!(:other_cart) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
@@ -324,7 +323,7 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'lock ordering' do
- let(:other_cart) { create(:cart, store: store, customer: order_user) }
+ let(:other_cart) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
@@ -369,7 +368,7 @@ RSpec.describe Spree::GiftCards::Apply do
end
context 'when the other cart is mid-completion' do
- let(:other_cart) { create(:cart, store: store, customer: order_user) }
+ let(:other_cart) { create(:cart_with_line_items, store: store, customer: order_user, line_items_price: 50) }
before do
other_cart.update_column(:total, 50)
@@ -400,7 +399,7 @@ RSpec.describe Spree::GiftCards::Apply do
context 'when a draft order from an in-flight checkout holds the card' do
let(:completing_cart) { create(:cart, store: store, customer: order_user) }
let!(:draft_order) do
- create(:order, store: store, customer: order_user, cart: completing_cart, status: 'draft').tap do |draft|
+ create(:order_with_totals, store: store, customer: order_user, cart: completing_cart, status: 'draft', line_items_price: 50).tap do |draft|
draft.update_column(:total, 50)
expect(Spree.gift_card_apply_workflow.call(gift_card: gift_card, order: draft)).to be_success
end
@@ -429,7 +428,7 @@ RSpec.describe Spree::GiftCards::Apply do
context 'when the gift card is held by a completed order' do
let!(:completed_order) do
- create(:order, store: store, customer: order_user).tap do |other|
+ create(:order_with_totals, store: store, customer: order_user, line_items_price: 50).tap do |other|
other.update_column(:total, 50)
expect(Spree.gift_card_apply_workflow.call(gift_card: gift_card, order: other)).to be_success
other.update_column(:completed_at, Time.current)
@@ -446,7 +445,7 @@ RSpec.describe Spree::GiftCards::Apply do
context 'when the order belongs to a non-default store' do
let(:other_store) { create(:store, default: false) }
- let(:order) { create(:order, store: other_store, customer: order_user) }
+ let(:order) { create(:order_with_totals, store: other_store, customer: order_user, line_items_price: 30) }
let(:gift_card) { create(:gift_card, amount: 50, store: other_store, customer: gift_card_user) }
it 'applies the gift card to the order' do
diff --git a/spree/core/spec/workflows/spree/gift_cards/remove_spec.rb b/spree/core/spec/workflows/spree/gift_cards/remove_spec.rb
index 09a00057c3..96a6f19171 100644
--- a/spree/core/spec/workflows/spree/gift_cards/remove_spec.rb
+++ b/spree/core/spec/workflows/spree/gift_cards/remove_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Spree::GiftCards::Remove do
subject { described_class.call(order: order) }
- let(:order) { create(:order) }
+ let(:order) { create(:order_with_totals, line_items_price: 30) }
let(:gift_card) { create(:gift_card, amount: 50, store: Spree::Store.default) }
@@ -13,7 +13,6 @@ RSpec.describe Spree::GiftCards::Remove do
before do
Spree::Config[:geocode_addresses] = false
order.update_column(:total, 30)
- order.update_column(:shipment_total, 10)
end
after do