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.

Extend GatewayOptions to include `order` and `payment` accessible

Damian Legawiec5dbcc7d6f134
diff --git a/core/app/models/spree/payment/gateway_options.rb b/core/app/models/spree/payment/gateway_options.rb
index b864a05661..73fa66b177 100644
--- a/core/app/models/spree/payment/gateway_options.rb
+++ b/core/app/models/spree/payment/gateway_options.rb
@@ -3,16 +3,17 @@ module Spree
class GatewayOptions
def initialize(payment)
@payment = payment
+ @order = payment.order
end
+ attr_reader :payment, :order
+ delegate :currency, to: :payment
+ delegate :email, to: :order
+
def statement_descriptor_suffix
order.number
end
- def email
- order.email
- end
-
def customer
order.email
end
@@ -26,7 +27,7 @@ module Spree
end
def order_id
- "#{order.number}-#{@payment.number}"
+ "#{order.number}-#{payment.number}"
end
def shipping
@@ -45,10 +46,6 @@ module Spree
order.promo_total * exchange_multiplier
end
- def currency
- @payment.currency
- end
-
def billing_address
order.bill_address.try(:active_merchant_hash)
end
@@ -82,12 +79,8 @@ module Spree
private
- def order
- @payment.order
- end
-
def exchange_multiplier
- @payment.payment_method.try(:exchange_multiplier) || 1.0
+ payment.payment_method.try(:exchange_multiplier) || 1.0
end
end
end
diff --git a/core/spec/models/spree/payment/gateway_options_spec.rb b/core/spec/models/spree/payment/gateway_options_spec.rb
index 881c024141..89ef7babaf 100644
--- a/core/spec/models/spree/payment/gateway_options_spec.rb
+++ b/core/spec/models/spree/payment/gateway_options_spec.rb
@@ -44,6 +44,18 @@ RSpec.describe Spree::Payment::GatewayOptions, type: :model do
double Spree::Address, active_merchant_hash: { ship: :address }
end
+ describe '#order' do
+ subject { options.order }
+
+ it { is_expected.to eq order }
+ end
+
+ describe '#payment' do
+ subject { options.payment }
+
+ it { is_expected.to eq payment }
+ end
+
describe '#email' do
subject { options.email }