Sha256: a24cf0be53a398f78d918025cdf6c2cc208caa47d0ad354c15de69aec1c33873

Contents?: true

Size: 759 Bytes

Versions: 6

Compression:

Stored size: 759 Bytes

Contents

module Workarea
  module Storefront
    module GiftCardOrderPricing
      def gift_card
        return unless payment.gift_card.present?
        @gift_card ||= Workarea::Payment::GiftCard.find_by_token(
          payment.gift_card.number
        )
      end

      def gift_card_balance
        if gift_card.present?
          gift_card.balance
        else
          0.to_m
        end
      end

      def gift_card_amount
        if gift_card_balance > total_after_store_credit
          total_after_store_credit
        else
          gift_card_balance
        end
      end

      def total_after_store_credit
        order.total_price - store_credit_amount
      end

      def order_balance
        super - gift_card_amount
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-gift_cards-3.4.11 app/view_models/workarea/storefront/gift_card_order_pricing.rb
workarea-gift_cards-3.4.10 app/view_models/workarea/storefront/gift_card_order_pricing.rb
workarea-gift_cards-3.4.9 app/view_models/workarea/storefront/gift_card_order_pricing.rb
workarea-gift_cards-3.4.8 app/view_models/workarea/storefront/gift_card_order_pricing.rb
workarea-gift_cards-3.4.7 app/view_models/workarea/storefront/gift_card_order_pricing.rb
workarea-gift_cards-3.4.6 app/view_models/workarea/storefront/gift_card_order_pricing.rb