Module: SpreeCmCommissioner::PaymentDecorator
- Defined in:
- app/models/spree_cm_commissioner/payment_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #can_void? ⇒ Boolean
- #check_payment_method? ⇒ Boolean
- #payment_receive_manually? ⇒ Boolean
-
#process! ⇒ Object
order trigger payment.process! when calling order.next.
-
#set_payable ⇒ Object
must set current_user_instance before hand.
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 3 def self.prepended(base) base.attr_accessor :current_user_instance base.belongs_to :payable, polymorphic: true, optional: true base.before_save :set_payable # Lock inventory hold for payment after the payment row is fully committed. # Using after_commit (not after_create) ensures the hold is only locked when # a real payment record permanently exists in the DB. Multiple payments for the # same order (retries) each refresh the 5-minute window — LockForPayment is idempotent. base.after_commit :lock_holds_for_payment, on: :create base.whitelisted_ransackable_attributes |= %w[payable_id] end |
Instance Method Details
#can_void? ⇒ Boolean
35 36 37 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 35 def can_void? state.in? %i[pending processing completed checkout] end |
#check_payment_method? ⇒ Boolean
31 32 33 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 31 def check_payment_method? payment_method.is_a?(Spree::PaymentMethod::Check) end |
#payment_receive_manually? ⇒ Boolean
27 28 29 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 27 def payment_receive_manually? check_payment_method? && payment_method.auto_capture? && order.ticket_seller_user? end |
#process! ⇒ Object
order trigger payment.process! when calling order.next.
21 22 23 24 25 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 21 def process! return complete! if payment_receive_manually? super end |
#set_payable ⇒ Object
must set current_user_instance before hand
41 42 43 |
# File 'app/models/spree_cm_commissioner/payment_decorator.rb', line 41 def set_payable self.payable = current_user_instance.presence if completed? end |