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.

Added `Order#payment_method` and `Order#payment_source`

Damian Legawiec7dc89404e8a2
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 9ae0693fde..9e23a8871b 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -398,6 +398,20 @@ module Spree
end
end
+ # Returns the payment method for the order
+ #
+ # @return [Spree::PaymentMethod] the payment method for the order
+ def payment_method
+ payments.valid.not_store_credits.first&.payment_method
+ end
+
+ # Returns the payment source for the order
+ #
+ # @return [Spree::PaymentSource] the payment source for the order
+ def payment_source
+ payments.valid.not_store_credits.first&.source
+ end
+
def can_ship?
complete? || resumed? || awaiting_return? || returned?
end
diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb
index d77efb6199..b9df74598e 100644
--- a/core/spec/models/spree/order_spec.rb
+++ b/core/spec/models/spree/order_spec.rb
@@ -1928,4 +1928,34 @@ describe Spree::Order, type: :model do
end
end
end
+
+ describe '#payment_method' do
+ subject { order.payment_method }
+
+ let(:order) { create(:order) }
+ let(:payment_method) { create(:simple_credit_card_payment_method, stores: [store]) }
+
+ before do
+ create(:payment, order: order, payment_method: payment_method)
+ end
+
+ it 'returns the payment method' do
+ expect(subject).to eq(payment_method)
+ end
+ end
+
+ describe '#payment_source' do
+ subject { order.payment_source }
+
+ let(:order) { create(:order) }
+ let(:payment_source) { create(:credit_card) }
+
+ before do
+ create(:payment, order: order, source: payment_source)
+ end
+
+ it 'returns the payment source' do
+ expect(subject).to eq(payment_source)
+ end
+ end
end