Class: Workarea::Checkout::Steps::GiftCard

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/checkout/steps/gift_card.rb

Instance Method Summary collapse

Instance Method Details

#complete?Boolean

Whether this step of checkout is considered complete. Requires either no gift cards applied, or that all gift cards are valid with a balance. No balance could mean a card is expired, or has been used.

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'app/models/workarea/checkout/steps/gift_card.rb', line 42

def complete?
  !payment.gift_card? ||
    (
      payment.gift_cards.all?(&:valid?) &&
      payment.gift_cards.none? { |g| g.balance.zero? }
    )
end

#remove(id) ⇒ Boolean

Removes a gift card from payment, updates order pricing and readjusts tender amounts.

Parameters:

  • id (String)

    the gift card tender id

Returns:

  • (Boolean)

    whether the update succeeded (payment was saved)



28
29
30
31
32
33
34
# File 'app/models/workarea/checkout/steps/gift_card.rb', line 28

def remove(id)
  payment.gift_cards.find(id).destroy
rescue Mongoid::Errors::DocumentNotFound
  # no op
ensure
  update_order
end

#update(params = {}) ⇒ Boolean

Add a gift card tender to the order, updates pricing and adjusts the tender amounts for all existing tenders.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :gift_card_number (String)

    a gift card number to apply

Returns:

  • (Boolean)

    whether the update succeeded (payment were saved)



13
14
15
16
17
18
19
# File 'app/models/workarea/checkout/steps/gift_card.rb', line 13

def update(params = {})
  gift_card_params = extract_gift_card_params(params)

  add_gift_card(gift_card_params) if applicable_gift_card?(gift_card_params)

  update_order
end