Sha256: 9f2f242fce81a62e88c5361818155c9d966bd5cd5d03e10292e9eed9977bceed

Contents?: true

Size: 1014 Bytes

Versions: 2

Compression:

Stored size: 1014 Bytes

Contents

require 'active_support/concern'

module Spree
  class Payment < ActiveRecord::Base
    module LoyaltyPoints
      extend ActiveSupport::Concern

        module ClassMethods

          def any_with_loyalty_points?
            by_loyalty_points.size != 0
          end
        end

      private

        def redeem_loyalty_points
          loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
          if by_loyalty_points? && redeemable_loyalty_points_balance?
            order.create_debit_transaction(loyalty_points_redeemed)
          end
        end

        def return_loyalty_points
          loyalty_points_redeemed = loyalty_points_for(amount, 'redeem')
          order.create_credit_transaction(loyalty_points_redeemed)
        end

        def by_loyalty_points?
          payment_method.type == "Spree::PaymentMethod::LoyaltyPoints"
        end

        def redeemable_loyalty_points_balance?
          amount >= Spree::Config.loyalty_points_redeeming_balance
        end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_loyalty_points-1.0.1 app/models/concerns/spree/payment/loyalty_points.rb
spree_loyalty_points-1.0.0 app/models/concerns/spree/payment/loyalty_points.rb