Class: Workarea::Storefront::Checkout::PaymentViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Includes:
Workarea::Storefront::CheckoutContent, OrderPricing
Defined in:
app/view_models/workarea/storefront/checkout/payment_view_model.rb

Instance Method Summary collapse

Methods included from OrderPricing

#advance_payment_amount, #order_balance, #store_credit?, #store_credit_amount, #total_adjustments

Methods included from Workarea::Storefront::CheckoutContent

#content_lookup

Methods included from DisplayContent

#browser_title, #content, #content_blocks, #content_blocks_for, #meta_description, #open_graph_asset

Instance Method Details

#credit_cardPayment::Tender::CreditCard?

The credit card tender for the payment. Used for outputting errors and form fields.

Returns:

  • (Payment::Tender::CreditCard, nil)


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.

Returns:

  • (Boolean)


40
41
42
# File 'app/view_models/workarea/storefront/checkout/payment_view_model.rb', line 40

def credit_card?
  !!payment.credit_card
end

#credit_cardsArray<CreditCardViewModel>

The list of saved credit cards from the current Payment. Returns an empty list if user or email are blank.

Returns:



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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_idString?

The Payment::SavedCreditCard#id for the current payment.

Returns:

  • (String, nil)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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