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.

Fixed: Check payment method now properly transitions to pending/compl… (#13762)

Damian Legawiec9a9ba931c41e
diff --git a/docs/developer/core-concepts/payments.mdx b/docs/developer/core-concepts/payments.mdx
index ae9f6eb5d1..3317fa872f 100644
--- a/docs/developer/core-concepts/payments.mdx
+++ b/docs/developer/core-concepts/payments.mdx
@@ -248,7 +248,7 @@ sequenceDiagram
Spree API-->>Frontend: Payment created
Frontend->>Spree API: PATCH /orders/:id/complete
- Spree API->>Spree API: process_payments! (no-op for manual methods)
+ Spree API->>Spree API: process_payments! (authorize succeeds immediately)
Spree API->>Spree API: Payment → pending/completed
Spree API-->>Frontend: Order completed
```
@@ -261,7 +261,7 @@ sequenceDiagram
The frontend calls `POST /payments` with the `payment_method_id`. Spree creates a `Payment` record in `checkout` state. No external provider interaction is needed.
</Step>
<Step title="Complete order">
- The frontend completes the order. Spree's `process_payments!` runs the payment method's authorize/purchase, which for manual methods is a no-op success. The payment transitions to `pending` (or `completed` with auto-capture) and the order completes.
+ The frontend completes the order. Spree's `process_payments!` runs the payment method's `authorize` (or `purchase` with auto-capture). For manual methods like Check, these return an immediate success — no external service is called. The payment transitions to `pending` (without auto-capture) or `completed` (with auto-capture) and the order completes. The merchant can later capture `pending` payments from the Admin Panel once the physical payment is received.
</Step>
</Steps>
diff --git a/spree/core/app/models/spree/payment/processing.rb b/spree/core/app/models/spree/payment/processing.rb
index 52e1f23224..6a8643367d 100644
--- a/spree/core/app/models/spree/payment/processing.rb
+++ b/spree/core/app/models/spree/payment/processing.rb
@@ -127,6 +127,8 @@ module Spree
else
raise Core::GatewayError, Spree.t(:payment_processing_failed)
end
+ else
+ yield unless processing?
end
end
diff --git a/spree/core/app/models/spree/payment_method/check.rb b/spree/core/app/models/spree/payment_method/check.rb
index 96786120ef..9914d95c86 100644
--- a/spree/core/app/models/spree/payment_method/check.rb
+++ b/spree/core/app/models/spree/payment_method/check.rb
@@ -4,6 +4,14 @@ module Spree
%w{capture void}
end
+ def authorize(*)
+ simulated_successful_billing_response
+ end
+
+ def purchase(*)
+ simulated_successful_billing_response
+ end
+
# Indicates whether its possible to capture the payment
def can_capture?(payment)
['checkout', 'pending'].include?(payment.state)
diff --git a/spree/core/spec/models/spree/payment_spec.rb b/spree/core/spec/models/spree/payment_spec.rb
index 91876f4dbf..fcbd79f50b 100644
--- a/spree/core/spec/models/spree/payment_spec.rb
+++ b/spree/core/spec/models/spree/payment_spec.rb
@@ -731,14 +731,26 @@ describe Spree::Payment, type: :model do
end
context 'with source optional' do
- context 'raises no error if source is not specified' do
+ context 'when payment method does not require source' do
+ let(:check_payment_method) { create(:check_payment_method, stores: [order.store], auto_capture: false) }
+
before do
payment.source = nil
- allow(payment.payment_method).to receive_messages(source_required?: false)
+ payment.payment_method = check_payment_method
end
- specify do
+ it 'processes successfully and transitions to pending' do
expect { payment.process! }.not_to raise_error
+ expect(payment.state).to eq('pending')
+ end
+
+ context 'with auto capture' do
+ let(:check_payment_method) { create(:check_payment_method, stores: [order.store], auto_capture: true) }
+
+ it 'processes successfully and transitions to completed' do
+ expect { payment.process! }.not_to raise_error
+ expect(payment.state).to eq('completed')
+ end
end
end
end