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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.mdxindex ae9f6eb5d1..3317fa872f 100644--- a/docs/developer/core-concepts/payments.mdx+++ b/docs/developer/core-concepts/payments.mdx@@ -248,7 +248,7 @@ sequenceDiagramSpree API-->>Frontend: Payment createdFrontend->>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/completedSpree API-->>Frontend: Order completed```@@ -261,7 +261,7 @@ sequenceDiagramThe 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.rbindex 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 Spreeelseraise Core::GatewayError, Spree.t(:payment_processing_failed)end+ else+ yield unless processing?endenddiff --git a/spree/core/app/models/spree/payment_method/check.rb b/spree/core/app/models/spree/payment_method/check.rbindex 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 paymentdef 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.rbindex 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 doendcontext '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 dopayment.source = nil- allow(payment.payment_method).to receive_messages(source_required?: false)+ payment.payment_method = check_payment_methodend- specify do+ it 'processes successfully and transitions to pending' doexpect { 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')+ endendendend