Class: Levelup::Utils::PaymentCalculator
- Inherits:
-
Object
- Object
- Levelup::Utils::PaymentCalculator
- Defined in:
- lib/levelup/utils/payment_calculator.rb
Overview
This is a tool to allow integrators to calculate various values to discount and tender
Class Method Summary collapse
-
.levelup_discount_to_apply(check_total_due_including_tax:, exempted_item_total:, merchant_funded_credit_available:, payment_amount_requested:, tax_amount_due:) ⇒ Object
Calculates the LevelUp discount to apply based on the arguments passed.
Instance Method Summary collapse
-
#gift_card_payment_to_apply ⇒ Object
Cent amount of LevelUp gift card payment to apply NOT including tip.
-
#gift_card_remaining_balance_after_payment ⇒ Object
Remaining balance in cents on LevelUp gift card after gift card payment has been applied.
-
#gift_card_tip_to_apply ⇒ Object
Cent amount of LevelUp gift card tip to apply NOT including LevelUp gift card payment.
-
#initialize(discount_applied:, gift_card_credit_available:, spend_amount_returned_from_levelup:, tip_returned_from_levelup:) ⇒ PaymentCalculator
constructor
A new instance of PaymentCalculator.
-
#levelup_payment_to_apply ⇒ Object
Cent amount of LevelUp payment to apply NOT including the tip amount.
-
#levelup_tip_to_apply ⇒ Object
Cent amount of LevelUp tip to apply NOT including payment amount.
-
#total_levelup_payment_to_apply_including_tip ⇒ Object
Total amount in cents of LevelUp payment to apply including both tip AND payment amounts.
Constructor Details
#initialize(discount_applied:, gift_card_credit_available:, spend_amount_returned_from_levelup:, tip_returned_from_levelup:) ⇒ PaymentCalculator
Returns a new instance of PaymentCalculator.
11 12 13 14 15 16 17 |
# File 'lib/levelup/utils/payment_calculator.rb', line 11 def initialize(discount_applied:, gift_card_credit_available:, spend_amount_returned_from_levelup:, tip_returned_from_levelup:) @discount_applied = discount_applied @gift_card_credit_available = gift_card_credit_available @spend_amount_returned_from_levelup = spend_amount_returned_from_levelup @tip_returned_from_levelup = tip_returned_from_levelup end |
Class Method Details
.levelup_discount_to_apply(check_total_due_including_tax:, exempted_item_total:, merchant_funded_credit_available:, payment_amount_requested:, tax_amount_due:) ⇒ Object
Calculates the LevelUp discount to apply based on the arguments passed
27 28 29 30 31 32 33 |
# File 'lib/levelup/utils/payment_calculator.rb', line 27 def self.levelup_discount_to_apply(check_total_due_including_tax:, exempted_item_total:, merchant_funded_credit_available:, payment_amount_requested:, tax_amount_due:) total_due_without_tax = check_total_due_including_tax - tax_amount_due max_discount = [payment_amount_requested, total_due_without_tax].min max_discount_less_exemptions = [0, max_discount - exempted_item_total].max [merchant_funded_credit_available, max_discount_less_exemptions].min end |
Instance Method Details
#gift_card_payment_to_apply ⇒ Object
Cent amount of LevelUp gift card payment to apply NOT including tip
36 37 38 |
# File 'lib/levelup/utils/payment_calculator.rb', line 36 def gift_card_payment_to_apply [spend_amount_after_discount, @gift_card_credit_available].min end |
#gift_card_remaining_balance_after_payment ⇒ Object
Remaining balance in cents on LevelUp gift card after gift card payment has been applied
41 42 43 |
# File 'lib/levelup/utils/payment_calculator.rb', line 41 def gift_card_remaining_balance_after_payment [0, @gift_card_credit_available - total_gift_card_payment_to_apply_including_tip].max end |
#gift_card_tip_to_apply ⇒ Object
Cent amount of LevelUp gift card tip to apply NOT including LevelUp gift card payment
46 47 48 |
# File 'lib/levelup/utils/payment_calculator.rb', line 46 def gift_card_tip_to_apply total_gift_card_payment_to_apply_including_tip - gift_card_payment_to_apply end |
#levelup_payment_to_apply ⇒ Object
Cent amount of LevelUp payment to apply NOT including the tip amount
51 52 53 |
# File 'lib/levelup/utils/payment_calculator.rb', line 51 def levelup_payment_to_apply [0, spend_amount_after_discount - @gift_card_credit_available].max end |
#levelup_tip_to_apply ⇒ Object
Cent amount of LevelUp tip to apply NOT including payment amount
56 57 58 |
# File 'lib/levelup/utils/payment_calculator.rb', line 56 def levelup_tip_to_apply total_levelup_payment_to_apply_including_tip - levelup_payment_to_apply end |
#total_levelup_payment_to_apply_including_tip ⇒ Object
Total amount in cents of LevelUp payment to apply including both tip AND payment amounts
61 62 63 |
# File 'lib/levelup/utils/payment_calculator.rb', line 61 def total_levelup_payment_to_apply_including_tip [0, total_amount_after_discount - @gift_card_credit_available].max end |