Class: Workarea::Checkout::Steps::GiftCard
- Inherits:
-
Base
- Object
- Base
- Workarea::Checkout::Steps::GiftCard
- Defined in:
- app/models/workarea/checkout/steps/gift_card.rb
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Whether this step of checkout is considered complete.
-
#remove(id) ⇒ Boolean
Removes a gift card from payment, updates order pricing and readjusts tender amounts.
-
#update(params = {}) ⇒ Boolean
Add a gift card tender to the order, updates pricing and adjusts the tender amounts for all existing tenders.
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.
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.
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.
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 |