Class: Workarea::Storefront::Checkout::PaymentViewModel
- Inherits:
-
ApplicationViewModel
- Object
- ApplicationViewModel
- Workarea::Storefront::Checkout::PaymentViewModel
- Defined in:
- app/view_models/workarea/storefront/checkout/payment_view_model.rb
Instance Method Summary collapse
-
#credit_card ⇒ Payment::Tender::CreditCard?
The credit card tender for the payment.
-
#credit_card? ⇒ Boolean
Whether the current payment is set to credit card.
-
#credit_cards ⇒ Array<CreditCardViewModel>
The list of saved credit cards from the current Payment.
-
#order_covered_by_advance_payments? ⇒ Boolean
Can advance payments (store credit, gift cards) cover the cost of the entire order? Used for hiding primary payments (e.g. credit cards) when not necessary to complete the order.
-
#order_covered_by_store_credit? ⇒ Boolean
Can the current store credit cover the entire order total? Used for rendering store credit messaging.
-
#saved_card_id ⇒ String?
The Payment::SavedCreditCard#id for the current payment.
-
#tender_required? ⇒ Boolean
Is another tender required? Used for rendering payment messaging.
-
#using_new_card? ⇒ Boolean
Whether this checkout should be using a new credit card.
Methods included from OrderPricing
#advance_payment_amount, #order_balance, #store_credit?, #store_credit_amount, #total_adjustments
Methods included from Workarea::Storefront::CheckoutContent
Methods included from DisplayContent
#browser_title, #content, #content_blocks, #content_blocks_for, #meta_description, #open_graph_asset
Instance Method Details
#credit_card ⇒ Payment::Tender::CreditCard?
The credit card tender for the payment. Used for outputting errors and form fields.
58 59 60 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 58 def credit_card payment.credit_card end |
#credit_card? ⇒ Boolean
Whether the current payment is set to credit card. Used to determine whether to output credit card errors.
40 41 42 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 40 def credit_card? !!payment.credit_card end |
#credit_cards ⇒ Array<CreditCardViewModel>
The list of saved credit cards from the current Payment. Returns an empty list if user or email are blank.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 67 def credit_cards @credit_cards ||= if user.blank? || order.email.blank? [] else payment.saved_credit_cards.map do |card| CreditCardViewModel.new( card, selected: selected_payment_id ) end end end |
#order_covered_by_advance_payments? ⇒ Boolean
Can advance payments (store credit, gift cards) cover the cost of the entire order? Used for hiding primary payments (e.g. credit cards) when not necessary to complete the order.
22 23 24 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 22 def order_covered_by_advance_payments? advance_payment_amount >= order.total_price end |
#order_covered_by_store_credit? ⇒ Boolean
Can the current store credit cover the entire order total? Used for rendering store credit messaging.
12 13 14 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 12 def order_covered_by_store_credit? store_credit_balance >= order.total_price end |
#saved_card_id ⇒ String?
The Payment::SavedCreditCard#id for the current payment.
49 50 51 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 49 def saved_card_id payment.saved_card_id end |
#tender_required? ⇒ Boolean
Is another tender required? Used for rendering payment messaging.
31 32 33 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 31 def tender_required? order_balance > 0 end |
#using_new_card? ⇒ Boolean
Whether this checkout should be using a new credit card. Used to determine whether the new credit card radio button should be checked.
86 87 88 |
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 86 def using_new_card? tender_required? && !credit_cards.any?(&:selected?) end |