Class: Workarea::Storefront::AfterpayViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/storefront/afterpay_view_model.rb

Instance Method Summary collapse

Instance Method Details

#afterpay_countryObject



41
42
43
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 41

def afterpay_country
  Workarea.config.afterpay[:currency_country_map][currency.to_sym]
end

#installment_priceObject



28
29
30
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 28

def installment_price
  order.order_balance / Workarea.config.afterpay[:installment_count]
end

#max_priceObject



37
38
39
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 37

def max_price
  afterpay_configuration[:maximumAmount][:amount].to_m
end

#min_priceObject



32
33
34
35
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 32

def min_price
  return 0.to_m unless afterpay_configuration[:minimumAmount].present?
  afterpay_configuration[:minimumAmount][:amount].to_m
end

#order_total_in_range?Boolean

Orders must be between the min and max order total to qualify.

Returns:

  • (Boolean)


5
6
7
8
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 5

def order_total_in_range?
  return unless afterpay_configuration.present?
  order.order_balance >= min_price && order.order_balance <= max_price
end

#show?Boolean

Show if admin settings are enabled, there are configuration options returned from the API and the currency code is valid.

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 12

def show?
  return unless afterpay_settings.enabled?
  return unless valid_international_order?
  return unless afterpay_configuration.present?
  afterpay_country.present?
end

#show_on_cart?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 19

def show_on_cart?
  show? && afterpay_settings.display_on_cart?
end

#show_on_pdp?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/view_models/workarea/storefront/afterpay_view_model.rb', line 23

def show_on_pdp?
  show? && afterpay_settings.display_on_pdp?
end