spree_core 5.1.0.beta3 → 5.1.0.beta4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dbf1c3a02958e3dcb370c47d5cd4e9c209924301fcf451e91cdce682e60ea74
4
- data.tar.gz: 83d62b4be4aeeb60fda78de84dfe73bd5ebf9603b32b5b938274be67a54c25a0
3
+ metadata.gz: 40078ca0fe53f0e6a2af34f66cec79f80823d752aceabac637f5e247b32976a6
4
+ data.tar.gz: 5ae9476bc4e0fee22c705e9b1979a4d29d1057066c20d017a8c956392d137712
5
5
  SHA512:
6
- metadata.gz: fdfef29cde021604e1309c49fd2218ced2bbf37c66b4642a88979955e57d6744a1f6630b1e8937aa4633d626f8c509bf8a7c3fc1c5bf76f0c5ba3f8472bd7fe1
7
- data.tar.gz: a2d843bd61853ce37850019f7d378a83cd7fe88b523f1be07354271350498e851625caa9a49f969cbf338a00c12bb289d55a449f8a212d1a8290bab75d720971
6
+ metadata.gz: ff673f06e666ffcf7b987182bbc226c6663a645a7fac34d14ae79021f076972f21de05e27639e920885cd2478dc17a2f1f648bcfcbb29987909a71ab71913e6d
7
+ data.tar.gz: e52971afaf599280aef97bbad4cc33d81621003770dd43edae06532bb86486584d0bfc758299896dbbb56a1f9fc71c34c68791b47bbe1ce8588ba786ec4a78b5
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ module PaymentSourceConcern
3
+ extend ActiveSupport::Concern
4
+
5
+ # Available actions for the payment source.
6
+ # @return [Array<String>]
7
+ def actions
8
+ %w{capture void credit}
9
+ end
10
+
11
+ # Indicates whether its possible to capture the payment
12
+ # @param payment [Spree::Payment]
13
+ # @return [Boolean]
14
+ def can_capture?(payment)
15
+ payment.pending? || payment.checkout?
16
+ end
17
+
18
+ # Indicates whether its possible to void the payment.
19
+ # @param payment [Spree::Payment]
20
+ # @return [Boolean]
21
+ def can_void?(payment)
22
+ !payment.failed? && !payment.void?
23
+ end
24
+
25
+ # Indicates whether its possible to credit the payment. Note that most gateways require that the
26
+ # payment be settled first which generally happens within 12-24 hours of the transaction.
27
+ # @param payment [Spree::Payment]
28
+ # @return [Boolean]
29
+ def can_credit?(payment)
30
+ payment.completed? && payment.credit_allowed > 0
31
+ end
32
+
33
+ # Returns true if the payment source has a payment profile.
34
+ # @return [Boolean]
35
+ def has_payment_profile?
36
+ gateway_customer_profile_id.present? || gateway_payment_profile_id.present?
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,8 @@ module Spree
2
2
  class CreditCard < Spree.base_class
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
4
  include Spree::Metadata
5
+ include Spree::PaymentSourceConcern
6
+
5
7
  if defined?(Spree::Webhooks::HasWebhooks)
6
8
  include Spree::Webhooks::HasWebhooks
7
9
  end
@@ -135,30 +137,6 @@ module Spree
135
137
  brand.present? ? brand.upcase : Spree.t(:no_cc_type)
136
138
  end
137
139
 
138
- def actions
139
- %w{capture void credit}
140
- end
141
-
142
- # Indicates whether its possible to capture the payment
143
- def can_capture?(payment)
144
- payment.pending? || payment.checkout?
145
- end
146
-
147
- # Indicates whether its possible to void the payment.
148
- def can_void?(payment)
149
- !payment.failed? && !payment.void?
150
- end
151
-
152
- # Indicates whether its possible to credit the payment. Note that most gateways require that the
153
- # payment be settled first which generally happens within 12-24 hours of the transaction.
154
- def can_credit?(payment)
155
- payment.completed? && payment.credit_allowed > 0
156
- end
157
-
158
- def has_payment_profile?
159
- gateway_customer_profile_id.present? || gateway_payment_profile_id.present?
160
- end
161
-
162
140
  # ActiveMerchant needs first_name/last_name because we pass it a Spree::CreditCard and it calls those methods on it.
163
141
  # Looking at the ActiveMerchant source code we should probably be calling #to_active_merchant before passing
164
142
  # the object to ActiveMerchant but this should do for now.
@@ -0,0 +1,33 @@
1
+ module Spree
2
+ class Gateway::CustomPaymentSourceMethod < Gateway
3
+ def provider_class
4
+ self.class
5
+ end
6
+
7
+ def payment_source_class
8
+ Spree::PaymentSource
9
+ end
10
+
11
+ def payment_profiles_supported?
12
+ true
13
+ end
14
+
15
+ def show_in_admin?
16
+ false
17
+ end
18
+
19
+ def create_profile(payment)
20
+ return if payment.source.gateway_customer.present?
21
+
22
+ user = payment.source.user || payment.order.user
23
+ return if user.blank?
24
+
25
+ find_or_create_customer(user)
26
+ end
27
+
28
+ # simulate a 3rd party payment gateway api to fetch/or create a customer
29
+ def find_or_create_customer(user)
30
+ gateway_customers.find_or_create_by!(user: user, profile_id: "CUSTOMER-#{user.id}")
31
+ end
32
+ end
33
+ end
@@ -302,7 +302,8 @@ module Spree
302
302
  # Payment profile cannot be created without source
303
303
  return unless source
304
304
  # Imported payments shouldn't create a payment profile.
305
- return if source.imported
305
+ # Imported is only available on Spree::CreditCard, non-credit card payments should not have this attribute.
306
+ return if source.respond_to?(:imported) && source.imported
306
307
 
307
308
  payment_method.create_profile(self)
308
309
  rescue ActiveMerchant::ConnectionError => e
@@ -1,10 +1,31 @@
1
+ # This model is used to store payment sources for non-credit card payments, eg wallet, account, etc.
1
2
  module Spree
2
3
  class PaymentSource < Spree.base_class
3
4
  include Spree::Metadata
5
+ include Spree::PaymentSourceConcern
4
6
 
7
+ #
8
+ # Associations
9
+ #
5
10
  belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
6
11
  belongs_to :user, class_name: Spree.user_class.to_s, optional: true
7
12
 
13
+ #
14
+ # Validations
15
+ #
8
16
  validates_uniqueness_of :gateway_payment_profile_id, scope: :type
17
+
18
+ #
19
+ # Delegations
20
+ #
21
+ delegate :profile_id, to: :gateway_customer, prefix: true, allow_nil: true
22
+
23
+ # Returns the gateway customer for the user.
24
+ # @return [Spree::GatewayCustomer]
25
+ def gateway_customer
26
+ return if user.blank?
27
+
28
+ payment_method.gateway_customers.find_by(user: user)
29
+ end
9
30
  end
10
31
  end
@@ -36,6 +36,13 @@ module Spree
36
36
  @wished_items_count ||= variant_ids.count
37
37
  end
38
38
 
39
+ # returns the variant ids in the wishlist
40
+ #
41
+ # @return [Array<Integer>]
42
+ def variant_ids
43
+ @variant_ids ||= wished_items.pluck(:variant_id)
44
+ end
45
+
39
46
  def self.get_by_param(param)
40
47
  find_by(token: param)
41
48
  end
@@ -136,8 +136,15 @@ module Spree
136
136
  o.position = opt[:position]
137
137
  o.save!
138
138
  end
139
- option_value = option_type.option_values.where(name: opt[:value].parameterize).first_or_initialize do |o|
140
- o.name = o.presentation = opt[:value]
139
+
140
+ option_value_identificator = if opt[:option_value_name].present?
141
+ opt[:option_value_name]
142
+ else
143
+ opt[:option_value_presentation].parameterize
144
+ end
145
+
146
+ option_value = option_type.option_values.where(name: option_value_identificator).first_or_initialize do |o|
147
+ o.name = o.presentation = opt[:option_value_presentation]
141
148
  o.save!
142
149
  end
143
150
 
@@ -30,6 +30,15 @@
30
30
  <div class="flex-shrink-0">
31
31
  <%= payment_method_icon_tag source.class.to_s.demodulize.downcase, height: 30 %>
32
32
  </div>
33
+ <div>
34
+ <% if payment.payment_method.respond_to?(:source_partial_name) %>
35
+ <%= render partial: "spree/payment_sources/#{payment.payment_method.source_partial_name}", locals: { payment: payment, source: source } %>
36
+ <% elsif source.respond_to?(:name) %>
37
+ <%= source.name %>
38
+ <% else %>
39
+ <%= source.class.to_s.demodulize.downcase %>
40
+ <% end %>
41
+ </div>
33
42
  <% else %>
34
43
  <div class="flex-shrink-0">
35
44
  <%= payment_method_icon_tag payment.payment_method.payment_icon_name %>
@@ -98,6 +98,7 @@ module Spree
98
98
  Rails.application.config.spree.payment_methods = [
99
99
  Spree::Gateway::Bogus,
100
100
  Spree::Gateway::BogusSimple,
101
+ Spree::Gateway::CustomPaymentSourceMethod,
101
102
  Spree::PaymentMethod::Check,
102
103
  Spree::PaymentMethod::StoreCredit
103
104
  ]
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- VERSION = '5.1.0.beta3'.freeze
2
+ VERSION = '5.1.0.beta4'.freeze
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -271,7 +271,7 @@ module Spree
271
271
  :weight, :height, :width, :depth, :sku, :barcode, :cost_currency,
272
272
  :weight_unit, :dimensions_unit,
273
273
  {
274
- options: [:id, :name, :value, :position, :_destroy],
274
+ options: [:id, :name, :option_value_presentation, :option_value_name, :position, :_destroy],
275
275
  stock_items_attributes: [:id, :count_on_hand, :stock_location_id, :backorderable, :_destroy],
276
276
  prices_attributes: [:id, :amount, :compare_at_amount, :currency, :_destroy],
277
277
  price: {},
@@ -14,6 +14,11 @@ FactoryBot.define do
14
14
  create(:refund, amount: 5, payment: payment)
15
15
  end
16
16
  end
17
+
18
+ factory :custom_payment, class: Spree::Payment do
19
+ payment_method { create(:custom_payment_method, stores: [order.store]) }
20
+ source { create(:payment_source, user: order.user, payment_method: payment_method) }
21
+ end
17
22
  end
18
23
 
19
24
  factory :check_payment, class: Spree::Payment do
@@ -37,4 +37,9 @@ FactoryBot.define do
37
37
  active { true }
38
38
  auto_capture { true }
39
39
  end
40
+
41
+ factory :custom_payment_method, parent: :payment_method, class: Spree::Gateway::CustomPaymentSourceMethod do
42
+ type { 'Spree::Gateway::CustomPaymentSourceMethod' }
43
+ name { 'Custom' }
44
+ end
40
45
  end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :payment_source, class: Spree::PaymentSource do
3
+ association(:payment_method, factory: :custom_payment_method)
4
+ end
5
+ end
@@ -8,7 +8,7 @@ FactoryBot.define do
8
8
  end
9
9
 
10
10
  trait :preview do
11
- parent { create(:theme) }
11
+ parent { Spree::Store.default.default_theme || create(:theme, store: store) }
12
12
  end
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta3
4
+ version: 5.1.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-05-29 00:00:00.000000000 Z
13
+ date: 2025-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n-tasks
@@ -622,6 +622,7 @@ files:
622
622
  - app/models/concerns/spree/number_as_param.rb
623
623
  - app/models/concerns/spree/number_identifier.rb
624
624
  - app/models/concerns/spree/parameterizable_name.rb
625
+ - app/models/concerns/spree/payment_source_concern.rb
625
626
  - app/models/concerns/spree/previewable.rb
626
627
  - app/models/concerns/spree/product_scopes.rb
627
628
  - app/models/concerns/spree/ransackable_attributes.rb
@@ -686,6 +687,7 @@ files:
686
687
  - app/models/spree/gateway.rb
687
688
  - app/models/spree/gateway/bogus.rb
688
689
  - app/models/spree/gateway/bogus_simple.rb
690
+ - app/models/spree/gateway/custom_payment_source_method.rb
689
691
  - app/models/spree/gateway_customer.rb
690
692
  - app/models/spree/image.rb
691
693
  - app/models/spree/image/configuration/active_storage.rb
@@ -1266,6 +1268,7 @@ files:
1266
1268
  - lib/spree/testing_support/factories/payment_capture_event_factory.rb
1267
1269
  - lib/spree/testing_support/factories/payment_factory.rb
1268
1270
  - lib/spree/testing_support/factories/payment_method_factory.rb
1271
+ - lib/spree/testing_support/factories/payment_source_factory.rb
1269
1272
  - lib/spree/testing_support/factories/post_category_factory.rb
1270
1273
  - lib/spree/testing_support/factories/post_factory.rb
1271
1274
  - lib/spree/testing_support/factories/price_factory.rb
@@ -1345,9 +1348,9 @@ licenses:
1345
1348
  - BSD-3-Clause
1346
1349
  metadata:
1347
1350
  bug_tracker_uri: https://github.com/spree/spree/issues
1348
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta3
1351
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta4
1349
1352
  documentation_uri: https://docs.spreecommerce.org/
1350
- source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta3
1353
+ source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta4
1351
1354
  post_install_message:
1352
1355
  rdoc_options: []
1353
1356
  require_paths: