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
Create spree payment sources (#11601)
GrzegorzStochel7cdea9e9d992
diff --git a/core/app/models/spree/payment_source.rb b/core/app/models/spree/payment_source.rbnew file mode 100644index 0000000000..058e621e3a--- /dev/null+++ b/core/app/models/spree/payment_source.rb@@ -0,0 +1,10 @@+module Spree+ class PaymentSource < Spree::Base+ include Metadata++ belongs_to :payment_method, class_name: 'Spree::PaymentMethod'+ belongs_to :user, class_name: 'Spree::User', optional: true++ validates_uniqueness_of :gateway_payment_profile_id, scope: :type+ end+enddiff --git a/core/db/migrate/20220113052823_create_payment_sources.rb b/core/db/migrate/20220113052823_create_payment_sources.rbnew file mode 100644index 0000000000..5fe84cd6a8--- /dev/null+++ b/core/db/migrate/20220113052823_create_payment_sources.rb@@ -0,0 +1,22 @@+class CreatePaymentSources < ActiveRecord::Migration[5.2]+ def change+ create_table :spree_payment_sources do |t|+ t.string :gateway_payment_profile_id+ t.string :type, index: true++ t.references :payment_method, index: true, foreign_key: { to_table: :spree_payment_methods }+ t.references :user, index: true, foreign_key: { to_table: :spree_users }++ if t.respond_to? :jsonb+ t.jsonb :public_metadata+ t.jsonb :private_metadata+ else+ t.json :public_metadata+ t.json :private_metadata+ end++ t.index [:type, :gateway_payment_profile_id], unique: true, name: 'index_payment_sources_on_type_and_gateway_payment_profile_id'+ t.timestamps+ end+ end+end