solidus_core 1.0.0.pre → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/mailers/spree/carton_mailer.rb +1 -1
- data/app/mailers/spree/reimbursement_mailer.rb +3 -2
- data/app/mailers/spree/test_mailer.rb +1 -1
- data/app/models/concerns/spree/user_methods.rb +49 -0
- data/app/models/spree/ability.rb +2 -0
- data/app/models/spree/adjustment.rb +1 -0
- data/app/models/spree/adjustment_reason.rb +12 -0
- data/app/models/spree/app_configuration.rb +1 -1
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/inventory_unit.rb +10 -6
- data/app/models/spree/legacy_user.rb +4 -12
- data/app/models/spree/order.rb +15 -15
- data/app/models/spree/order/checkout.rb +20 -15
- data/app/models/spree/order/payments.rb +1 -5
- data/app/models/spree/order_cancellations.rb +1 -1
- data/app/models/spree/order_capturing.rb +1 -1
- data/app/models/spree/order_mutex.rb +1 -1
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/payment/processing.rb +39 -13
- data/app/models/spree/payment_method.rb +2 -2
- data/app/models/spree/permission_sets/base.rb +17 -0
- data/app/models/spree/permission_sets/configuration_display.rb +24 -0
- data/app/models/spree/permission_sets/configuration_management.rb +24 -0
- data/app/models/spree/permission_sets/dashboard_display.rb +9 -0
- data/app/models/spree/permission_sets/order_display.rb +15 -0
- data/app/models/spree/permission_sets/order_management.rb +15 -0
- data/app/models/spree/permission_sets/product_display.rb +18 -0
- data/app/models/spree/permission_sets/product_management.rb +19 -0
- data/app/models/spree/permission_sets/promotion_display.rb +12 -0
- data/app/models/spree/permission_sets/promotion_management.rb +12 -0
- data/app/models/spree/permission_sets/report_display.rb +9 -0
- data/app/models/spree/permission_sets/stock_display.rb +10 -0
- data/app/models/spree/permission_sets/stock_management.rb +11 -0
- data/app/models/spree/permission_sets/user_display.rb +11 -0
- data/app/models/spree/permission_sets/user_management.rb +11 -0
- data/app/models/spree/promotion/rules/item_total.rb +12 -33
- data/app/models/spree/promotion/rules/user.rb +2 -2
- data/app/models/spree/promotion_rule.rb +2 -2
- data/app/models/spree/reimbursement.rb +0 -12
- data/app/models/spree/return_authorization.rb +2 -2
- data/app/models/spree/return_item.rb +1 -0
- data/app/models/spree/return_reason.rb +18 -0
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +9 -26
- data/app/models/spree/store_credit.rb +31 -7
- data/app/models/spree/store_credit_event.rb +13 -11
- data/app/models/spree/store_credit_update_reason.rb +2 -0
- data/app/models/spree/user_class_handle.rb +21 -0
- data/app/models/spree/user_stock_location.rb +1 -1
- data/config/initializers/spree_user.rb +10 -0
- data/config/locales/en.yml +58 -16
- data/db/default/spree/return_reasons.rb +9 -0
- data/db/migrate/20140713140455_create_spree_return_authorization_reasons.rb +11 -9
- data/db/migrate/20150618212517_create_spree_store_credit_update_reasons.rb +8 -0
- data/db/migrate/20150619160613_create_adjustment_reason.rb +18 -0
- data/db/migrate/20150622144655_add_update_reason_to_store_credit_events.rb +5 -0
- data/db/migrate/20150623194316_add_return_authorization_reason_id_to_return_items.rb +7 -0
- data/db/migrate/20150623214058_seed_store_credit_update_reasons.rb +9 -0
- data/db/migrate/20150626200816_remove_shipping_method_id_from_spree_orders.rb +9 -0
- data/db/seeds.rb +9 -0
- data/lib/spree/core.rb +1 -4
- data/lib/spree/core/controller_helpers/auth.rb +15 -20
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/importer/order.rb +8 -5
- data/lib/spree/core/role_configuration.rb +70 -0
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +6 -0
- data/lib/spree/testing_support/factories/order_factory.rb +14 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +2 -4
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +3 -3
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -0
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +10 -0
- data/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/store_factory.rb +1 -1
- data/lib/spree/testing_support/order_walkthrough.rb +2 -7
- metadata +36 -10
- data/app/assets/images/logo/solidus.png +0 -0
- data/app/models/spree/item_adjustments.rb.orig +0 -93
- data/app/models/spree/return_authorization_reason.rb +0 -7
- data/app/models/spree/static_model_preferences.rb +0 -32
- data/config/initializers/user_class_extensions.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37901081f12d468225a333297e72fc9b18aa4a8e
|
4
|
+
data.tar.gz: 7ffcaa00028db2e02b2f8ba38a81365cb5f3b47c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90851a4dcb9df999a887eeb75c380a2ef27b1da6d063e34dd9a8daf2b40a1121e45e9983bb547f812f767e19f1f49bb562264fb42e57f70879eb6885b6178a47
|
7
|
+
data.tar.gz: b444a9f7a55c7c698d912b2dab2d6bb64c76729f4df514ba821a5d2bf922e99e514c4f2fa8e2a58977da6b9645a0b7eb8a9cf7be77f5b25685e47c4c5ff8262e
|
@@ -6,7 +6,7 @@ module Spree
|
|
6
6
|
@carton = Spree::Carton.find(carton_id)
|
7
7
|
subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
|
8
8
|
subject += "#{Spree::Store.current.name} #{Spree.t('shipment_mailer.shipped_email.subject')} ##{@carton.order_numbers.join(', ')}"
|
9
|
-
mail(to: @carton.order_emails, from: from_address, subject: subject)
|
9
|
+
mail(to: @carton.order_emails, from: from_address(Spree::Store.current), subject: subject)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -2,9 +2,10 @@ module Spree
|
|
2
2
|
class ReimbursementMailer < BaseMailer
|
3
3
|
def reimbursement_email(reimbursement, resend = false)
|
4
4
|
@reimbursement = reimbursement.respond_to?(:id) ? reimbursement : Spree::Reimbursement.find(reimbursement)
|
5
|
+
store = @reimbursement.order.store
|
5
6
|
subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
|
6
|
-
subject += "#{
|
7
|
-
mail(to: @reimbursement.order.email, from: from_address, subject: subject)
|
7
|
+
subject += "#{store.name} #{Spree.t('reimbursement_mailer.reimbursement_email.subject')} ##{@reimbursement.order.number}"
|
8
|
+
mail(to: @reimbursement.order.email, from: from_address(store), subject: subject)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -2,7 +2,7 @@ module Spree
|
|
2
2
|
class TestMailer < BaseMailer
|
3
3
|
def test_email(email)
|
4
4
|
subject = "#{Spree::Store.current.name} #{Spree.t('test_mailer.test_email.subject')}"
|
5
|
-
mail(to: email, from: from_address, subject: subject)
|
5
|
+
mail(to: email, from: from_address(Spree::Store.current), subject: subject)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Spree
|
2
|
+
module UserMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
include Spree::UserApiAuthentication
|
6
|
+
include Spree::UserReporting
|
7
|
+
include Spree::UserAddress
|
8
|
+
include Spree::UserPaymentSource
|
9
|
+
|
10
|
+
included do
|
11
|
+
extend Spree::DisplayMoney
|
12
|
+
|
13
|
+
has_many :role_users, foreign_key: "user_id", class_name: "Spree::RoleUser"
|
14
|
+
has_many :spree_roles, through: :role_users, source: :role
|
15
|
+
|
16
|
+
has_many :user_stock_locations, foreign_key: "user_id", class_name: "Spree::UserStockLocation"
|
17
|
+
has_many :stock_locations, through: :user_stock_locations
|
18
|
+
|
19
|
+
has_many :spree_orders, foreign_key: "user_id", class_name: "Spree::Order"
|
20
|
+
has_many :orders, foreign_key: "user_id", class_name: "Spree::Order"
|
21
|
+
|
22
|
+
has_many :store_credits, -> { includes(:credit_type) }, foreign_key: "user_id", class_name: "Spree::StoreCredit"
|
23
|
+
has_many :store_credit_events, through: :store_credits
|
24
|
+
money_methods :total_available_store_credit
|
25
|
+
|
26
|
+
belongs_to :ship_address, class_name: 'Spree::Address'
|
27
|
+
belongs_to :bill_address, class_name: 'Spree::Address'
|
28
|
+
end
|
29
|
+
|
30
|
+
# has_spree_role? simply needs to return true or false whether a user has a role or not.
|
31
|
+
def has_spree_role?(role_in_question)
|
32
|
+
spree_roles.any? { |role| role.name == role_in_question.to_s }
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Spree::Order] the most-recently-created incomplete order
|
36
|
+
# since the customer's last complete order.
|
37
|
+
def last_incomplete_spree_order(store: nil, only_frontend_viewable: true)
|
38
|
+
self_orders = self.orders
|
39
|
+
self_orders = self_orders.where(frontend_viewable: true) if only_frontend_viewable
|
40
|
+
self_orders = self_orders.where(store: store) if store
|
41
|
+
last_order = self_orders.order(:created_at).last
|
42
|
+
last_order unless last_order.try!(:completed?)
|
43
|
+
end
|
44
|
+
|
45
|
+
def total_available_store_credit
|
46
|
+
store_credits.reload.to_a.sum{ |credit| credit.amount_remaining }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/app/models/spree/ability.rb
CHANGED
@@ -27,6 +27,7 @@ module Spree
|
|
27
27
|
belongs_to :source, polymorphic: true
|
28
28
|
belongs_to :order, class_name: "Spree::Order"
|
29
29
|
belongs_to :promotion_code, :class_name => 'Spree::PromotionCode'
|
30
|
+
belongs_to :adjustment_reason, class_name: 'Spree::AdjustmentReason', inverse_of: :adjustments
|
30
31
|
|
31
32
|
validates :adjustable, presence: true
|
32
33
|
validates :order, presence: true
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
class AdjustmentReason < ActiveRecord::Base
|
3
|
+
has_many :adjustments, inverse_of: :adjustment_reason
|
4
|
+
|
5
|
+
validates :name, presence: true
|
6
|
+
validates :name, uniqueness: {case_sensitive: false}
|
7
|
+
validates :code, presence: true
|
8
|
+
validates :code, uniqueness: {case_sensitive: false}
|
9
|
+
|
10
|
+
scope :active, -> { where(active: true) }
|
11
|
+
end
|
12
|
+
end
|
@@ -138,7 +138,7 @@ module Spree
|
|
138
138
|
|
139
139
|
# @!attribute [rw] order_mutex_max_age
|
140
140
|
# @return [Integer] Max age of {OrderMutex} in seconds (default: 2 minutes)
|
141
|
-
preference :order_mutex_max_age, :integer, default:
|
141
|
+
preference :order_mutex_max_age, :integer, default: 120
|
142
142
|
|
143
143
|
# @!attribute [rw] orders_per_page
|
144
144
|
# @return [Integer] Orders to show per-page in the admin (default: +15+)
|
data/app/models/spree/carton.rb
CHANGED
@@ -3,7 +3,7 @@ class Spree::Carton < ActiveRecord::Base
|
|
3
3
|
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons
|
4
4
|
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :cartons
|
5
5
|
|
6
|
-
has_many :inventory_units, inverse_of: :carton
|
6
|
+
has_many :inventory_units, class_name: "Spree::InventoryUnit", inverse_of: :carton, dependent: :nullify
|
7
7
|
has_many :orders, -> { uniq }, through: :inventory_units
|
8
8
|
has_many :shipments, -> { uniq }, through: :inventory_units
|
9
9
|
|
@@ -17,7 +17,7 @@ module Spree
|
|
17
17
|
|
18
18
|
validates_presence_of :order, :shipment, :line_item, :variant
|
19
19
|
|
20
|
-
before_destroy :
|
20
|
+
before_destroy :ensure_can_destroy
|
21
21
|
|
22
22
|
scope :backordered, -> { where state: 'backordered' }
|
23
23
|
scope :on_hand, -> { where state: 'on_hand' }
|
@@ -143,11 +143,15 @@ module Spree
|
|
143
143
|
return_items.not_cancelled.first
|
144
144
|
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
def ensure_can_destroy
|
147
|
+
if !backordered? && !on_hand?
|
148
|
+
errors.add(:state, :cannot_destroy, state: self.state)
|
149
|
+
return false
|
150
|
+
end
|
151
|
+
|
152
|
+
unless shipment.pending?
|
153
|
+
errors.add(:base, :cannot_destroy_shipment_state, state: shipment.state)
|
154
|
+
return false
|
151
155
|
end
|
152
156
|
end
|
153
157
|
end
|
@@ -4,8 +4,7 @@ module Spree
|
|
4
4
|
# @note This class is intended to be modified by extensions (ex.
|
5
5
|
# spree_auth_devise)
|
6
6
|
class LegacyUser < Spree::Base
|
7
|
-
include
|
8
|
-
include UserPaymentSource
|
7
|
+
include UserMethods
|
9
8
|
|
10
9
|
self.table_name = 'spree_users'
|
11
10
|
|
@@ -14,14 +13,8 @@ module Spree
|
|
14
13
|
ActiveModel::Name.new(self, nil, "User")
|
15
14
|
end
|
16
15
|
|
17
|
-
has_many :orders, foreign_key: :user_id
|
18
|
-
|
19
16
|
before_destroy :check_completed_orders
|
20
17
|
|
21
|
-
def has_spree_role?(role)
|
22
|
-
true
|
23
|
-
end
|
24
|
-
|
25
18
|
def self.model_name
|
26
19
|
ActiveModel::Name.new Spree::LegacyUser, Spree, 'user'
|
27
20
|
end
|
@@ -30,9 +23,8 @@ module Spree
|
|
30
23
|
attr_accessor :password_confirmation
|
31
24
|
|
32
25
|
private
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
26
|
+
def check_completed_orders
|
27
|
+
raise Spree::Core::DestroyWithOrdersError if orders.complete.present?
|
28
|
+
end
|
37
29
|
end
|
38
30
|
end
|
data/app/models/spree/order.rb
CHANGED
@@ -13,6 +13,7 @@ module Spree
|
|
13
13
|
include Spree::Order::Payments
|
14
14
|
|
15
15
|
class InsufficientStock < StandardError; end
|
16
|
+
class CannotRebuildShipments < StandardError; end
|
16
17
|
|
17
18
|
extend Spree::DisplayMoney
|
18
19
|
money_methods :outstanding_balance, :item_total, :adjustment_total,
|
@@ -30,17 +31,10 @@ module Spree
|
|
30
31
|
attr_reader :coupon_code
|
31
32
|
attr_accessor :temporary_address, :temporary_credit_card
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
belongs_to :canceler, class_name: Spree.user_class.to_s
|
38
|
-
else
|
39
|
-
belongs_to :user
|
40
|
-
belongs_to :created_by
|
41
|
-
belongs_to :approver
|
42
|
-
belongs_to :canceler
|
43
|
-
end
|
34
|
+
belongs_to :user, class_name: Spree::UserClassHandle.new
|
35
|
+
belongs_to :created_by, class_name: Spree::UserClassHandle.new
|
36
|
+
belongs_to :approver, class_name: Spree::UserClassHandle.new
|
37
|
+
belongs_to :canceler, class_name: Spree::UserClassHandle.new
|
44
38
|
|
45
39
|
belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address'
|
46
40
|
alias_attribute :billing_address, :bill_address
|
@@ -524,9 +518,15 @@ module Spree
|
|
524
518
|
end
|
525
519
|
|
526
520
|
def create_proposed_shipments
|
527
|
-
|
528
|
-
|
529
|
-
|
521
|
+
if completed?
|
522
|
+
raise CannotRebuildShipments.new(Spree.t(:cannot_rebuild_shipments_order_completed))
|
523
|
+
elsif shipments.any? { |s| !s.pending? }
|
524
|
+
raise CannotRebuildShipments.new(Spree.t(:cannot_rebuild_shipments_shipments_not_pending))
|
525
|
+
else
|
526
|
+
adjustments.shipping.destroy_all
|
527
|
+
shipments.destroy_all
|
528
|
+
self.shipments = Spree::Stock::Coordinator.new(self).shipments
|
529
|
+
end
|
530
530
|
end
|
531
531
|
|
532
532
|
def apply_free_shipping_promotions
|
@@ -542,7 +542,7 @@ module Spree
|
|
542
542
|
# to delivery again so that proper updated shipments are created.
|
543
543
|
# e.g. customer goes back from payment step and changes order items
|
544
544
|
def ensure_updated_shipments
|
545
|
-
|
545
|
+
if !completed? && shipments.all?(&:pending?)
|
546
546
|
self.shipments.destroy_all
|
547
547
|
self.update_column(:shipment_total, 0)
|
548
548
|
restart_checkout_flow
|
@@ -72,16 +72,7 @@ module Spree
|
|
72
72
|
transition to: :payment, from: :confirm
|
73
73
|
end
|
74
74
|
|
75
|
-
before_transition to: :complete do
|
76
|
-
if order.payment_required? && order.payments.valid.empty?
|
77
|
-
order.errors.add(:base, Spree.t(:no_payment_found))
|
78
|
-
false
|
79
|
-
elsif order.payment_required?
|
80
|
-
order.process_payments!.tap do |success|
|
81
|
-
order.handle_failed_payments unless success
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
75
|
+
before_transition to: :complete, do: :process_payments_before_complete
|
85
76
|
after_transition to: :complete, do: :persist_user_credit_card
|
86
77
|
before_transition to: :payment, do: :set_shipments_cost
|
87
78
|
before_transition to: :payment, do: :create_tax_charge!
|
@@ -307,16 +298,30 @@ module Spree
|
|
307
298
|
if self.payments.from_credit_card.count == 0 && self.user && self.user.default_credit_card.try(:valid?)
|
308
299
|
cc = self.user.default_credit_card
|
309
300
|
self.payments.create!(payment_method_id: cc.payment_method_id, source: cc)
|
301
|
+
self.bill_address ||= self.user.bill_address.try!(:dup) if self.user.bill_address.try!(:valid?)
|
310
302
|
end
|
311
303
|
end
|
312
304
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
305
|
+
private
|
306
|
+
|
307
|
+
def process_payments_before_complete
|
308
|
+
return if !payment_required?
|
309
|
+
|
310
|
+
if payments.valid.empty?
|
311
|
+
errors.add(:base, Spree.t(:no_payment_found))
|
312
|
+
return false
|
313
|
+
end
|
314
|
+
|
315
|
+
if process_payments!
|
316
|
+
true
|
317
|
+
else
|
318
|
+
saved_errors = errors[:base]
|
319
|
+
payment_failed!
|
320
|
+
saved_errors.each { |error| errors.add(:base, error) }
|
321
|
+
false
|
322
|
+
end
|
317
323
|
end
|
318
324
|
|
319
|
-
private
|
320
325
|
# For payment step, filter order parameters to produce the expected nested
|
321
326
|
# attributes for a single payment and its source, discarding attributes
|
322
327
|
# for payment methods other than the one selected
|
@@ -9,7 +9,7 @@ module Spree
|
|
9
9
|
#
|
10
10
|
# Returns:
|
11
11
|
#
|
12
|
-
# - true if all
|
12
|
+
# - true if all pending payments processed successfully
|
13
13
|
#
|
14
14
|
# - true if a payment failed, ie. raised a GatewayError
|
15
15
|
# which gets rescued and converted to TRUE when
|
@@ -31,10 +31,6 @@ module Spree
|
|
31
31
|
process_payments_with(:purchase!)
|
32
32
|
end
|
33
33
|
|
34
|
-
def pending_payments
|
35
|
-
payments.select { |payment| payment.pending? }
|
36
|
-
end
|
37
|
-
|
38
34
|
def unprocessed_payments
|
39
35
|
payments.select { |payment| payment.checkout? }
|
40
36
|
end
|
@@ -29,7 +29,7 @@ class Spree::OrderCancellations
|
|
29
29
|
end
|
30
30
|
|
31
31
|
update_shipped_shipments(inventory_units)
|
32
|
-
Spree::OrderMailer.inventory_cancellation_email(@order, inventory_units).
|
32
|
+
Spree::OrderMailer.inventory_cancellation_email(@order, inventory_units.to_a).deliver_later if Spree::OrderCancellations.send_cancellation_mailer
|
33
33
|
end
|
34
34
|
|
35
35
|
@order.update!
|
@@ -41,7 +41,7 @@ class Spree::OrderCapturing
|
|
41
41
|
private
|
42
42
|
|
43
43
|
def sorted_payments(order)
|
44
|
-
payments = order.
|
44
|
+
payments = order.payments.pending
|
45
45
|
payments = payments.sort_by { |p| [@sorted_payment_method_classes.index(p.payment_method.class), p.id] }
|
46
46
|
end
|
47
47
|
end
|
@@ -5,7 +5,7 @@ module Spree
|
|
5
5
|
|
6
6
|
belongs_to :order, class_name: "Spree::Order"
|
7
7
|
|
8
|
-
scope :expired, -> { where(
|
8
|
+
scope :expired, -> { where(arel_table[:created_at].lteq(Spree::Config[:order_mutex_max_age].seconds.ago)) }
|
9
9
|
|
10
10
|
class << self
|
11
11
|
# Obtain a lock on an order, execute the supplied block and then release the lock.
|
@@ -64,7 +64,7 @@ class Spree::OrderShipping
|
|
64
64
|
# TODO: Remove tracking numbers from shipments.
|
65
65
|
shipment.update_attributes!(tracking: tracking_number)
|
66
66
|
|
67
|
-
if shipment.inventory_units.all? {|iu| iu.shipped? || iu.canceled? }
|
67
|
+
if shipment.inventory_units(true).all? {|iu| iu.shipped? || iu.canceled? }
|
68
68
|
# TODO: make OrderShipping#ship_shipment call Shipment#ship! rather than
|
69
69
|
# having Shipment#ship! call OrderShipping#ship_shipment. We only really
|
70
70
|
# need this `update_columns` for the specs, until we make that change.
|
@@ -1,11 +1,36 @@
|
|
1
1
|
module Spree
|
2
2
|
class Payment < Spree::Base
|
3
3
|
module Processing
|
4
|
+
# "process!" means:
|
5
|
+
# - Do nothing when:
|
6
|
+
# - There is no payment method
|
7
|
+
# - The payment method does not require a source
|
8
|
+
# - The payment is in the "processing" state
|
9
|
+
# - 'auto_capture?' is false and the payment is already authorized.
|
10
|
+
# - Raise an exception when:
|
11
|
+
# - The source is missing or invalid
|
12
|
+
# - The payment is in a state that cannot transition to 'processing'
|
13
|
+
# (failed/void/invalid states). Note: 'completed' can transition to
|
14
|
+
# 'processing' and thus calling #process! on a completed Payment
|
15
|
+
# will attempt to re-authorize/re-purchase the payment.
|
16
|
+
# - Otherwise:
|
17
|
+
# - If 'auto_capture?' is true:
|
18
|
+
# - Call #purchase on the payment gateway. (i.e. authorize+capture)
|
19
|
+
# even if the payment is already completed.
|
20
|
+
# - Else:
|
21
|
+
# - Call #authorize on the payment gateway even if the payment is
|
22
|
+
# already completed.
|
4
23
|
def process!
|
5
|
-
if payment_method
|
24
|
+
return if payment_method.nil?
|
25
|
+
|
26
|
+
if payment_method.auto_capture?
|
6
27
|
purchase!
|
7
28
|
else
|
8
|
-
|
29
|
+
if pending?
|
30
|
+
# do nothing. already authorized.
|
31
|
+
else
|
32
|
+
authorize!
|
33
|
+
end
|
9
34
|
end
|
10
35
|
end
|
11
36
|
|
@@ -106,19 +131,20 @@ module Spree
|
|
106
131
|
raise ArgumentError.new("handle_payment_preconditions must be called with a block")
|
107
132
|
end
|
108
133
|
|
109
|
-
if payment_method
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
134
|
+
return if payment_method.nil?
|
135
|
+
return if !payment_method.source_required?
|
136
|
+
|
137
|
+
if source
|
138
|
+
if !processing?
|
139
|
+
if payment_method.supports?(source) || token_based?
|
140
|
+
yield
|
141
|
+
else
|
142
|
+
invalidate!
|
143
|
+
raise Core::GatewayError.new(Spree.t(:payment_method_not_supported))
|
118
144
|
end
|
119
|
-
else
|
120
|
-
raise Core::GatewayError.new(Spree.t(:payment_processing_failed))
|
121
145
|
end
|
146
|
+
else
|
147
|
+
raise Core::GatewayError.new(Spree.t(:payment_processing_failed))
|
122
148
|
end
|
123
149
|
end
|
124
150
|
|