Class: Workarea::Checkout::CollectPayment
- Inherits:
-
Object
- Object
- Workarea::Checkout::CollectPayment
- Defined in:
- app/models/workarea/checkout/collect_payment.rb
Instance Method Summary collapse
- #action ⇒ Object
- #balance ⇒ Object
-
#initialize(checkout) ⇒ CollectPayment
constructor
A new instance of CollectPayment.
- #purchase ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(checkout) ⇒ CollectPayment
Returns a new instance of CollectPayment.
6 7 8 9 |
# File 'app/models/workarea/checkout/collect_payment.rb', line 6 def initialize(checkout) @checkout = checkout @order = checkout.order end |
Instance Method Details
#action ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/workarea/checkout/collect_payment.rb', line 35 def action # TODO deprecated, remove in v3.6 return 'purchase!' if Workarea.config.auto_capture if @order.items.all?(&:shipping?) Workarea.config.checkout_payment_action[:shipping] elsif @order.items.any?(&:shipping?) Workarea.config.checkout_payment_action[:partial_shipping] else Workarea.config.checkout_payment_action[:no_shipping] end end |
#balance ⇒ Object
24 25 26 |
# File 'app/models/workarea/checkout/collect_payment.rb', line 24 def balance @order.total_price - payment.tendered_amount end |
#purchase ⇒ Object
28 29 30 31 32 33 |
# File 'app/models/workarea/checkout/collect_payment.rb', line 28 def purchase return true if @order.total_price.zero? return false unless valid? payment.send(action, checkout: @checkout) end |
#valid? ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/workarea/checkout/collect_payment.rb', line 11 def valid? if balance > 0 payment.errors.add( :base, I18n.t('workarea.payment.insufficient_payment', balance: balance) ) return false end true end |