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.

Improve `PaymentSource` model to work with gateways using payment profiles, eg. Stripe

Damian Legawiec8a74281755dc
diff --git a/core/app/models/spree/payment_source.rb b/core/app/models/spree/payment_source.rb
index 58b747c4d2..57cb81b9bb 100644
--- a/core/app/models/spree/payment_source.rb
+++ b/core/app/models/spree/payment_source.rb
@@ -3,7 +3,7 @@ module Spree
include Spree::Metadata
belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
- belongs_to :user, class_name: 'Spree::User', optional: true
+ belongs_to :user, class_name: Spree.user_class.to_s, optional: true
validates_uniqueness_of :gateway_payment_profile_id, scope: :type
end
diff --git a/core/db/migrate/20241218183905_add_gateway_customer_profile_id_to_spree_payment_sources.rb b/core/db/migrate/20241218183905_add_gateway_customer_profile_id_to_spree_payment_sources.rb
new file mode 100644
index 0000000000..cd37011d3e
--- /dev/null
+++ b/core/db/migrate/20241218183905_add_gateway_customer_profile_id_to_spree_payment_sources.rb
@@ -0,0 +1,5 @@
+class AddGatewayCustomerProfileIdToSpreePaymentSources < ActiveRecord::Migration[6.1]
+ def change
+ add_column :spree_payment_sources, :gateway_customer_profile_id, :string
+ end
+end
diff --git a/core/spec/services/spree/wallet/create_payment_source_spec.rb b/core/spec/services/spree/wallet/create_payment_source_spec.rb
index baa09a5c5a..cfb057f646 100644
--- a/core/spec/services/spree/wallet/create_payment_source_spec.rb
+++ b/core/spec/services/spree/wallet/create_payment_source_spec.rb
@@ -12,6 +12,7 @@ module Spree
let(:params) do
{
gateway_payment_profile_id: '12345',
+ gateway_customer_profile_id: '67890',
cc_type: 'visa',
last_digits: '1111',
name: 'John',