Sha256: 8ee00122fd94bc13fbca58563f186f0c4036fa4ae0d4bb2e989c16748ca77ef0

Contents?: true

Size: 1.55 KB

Versions: 80

Compression:

Stored size: 1.55 KB

Contents

module Spree
  class Payment < Spree::Base
    class GatewayOptions
      def initialize(payment)
        @payment = payment
      end

      def email
        order.email
      end

      def customer
        order.email
      end

      def customer_id
        order.user_id
      end

      def ip
        order.last_ip_address
      end

      def order_id
        "#{order.number}-#{@payment.number}"
      end

      def shipping
        order.ship_total * exchange_multiplier
      end

      def tax
        order.additional_tax_total * exchange_multiplier
      end

      def subtotal
        order.item_total * exchange_multiplier
      end

      def discount
        order.promo_total * exchange_multiplier
      end

      def currency
        @payment.currency
      end

      def billing_address
        order.bill_address.try(:active_merchant_hash)
      end

      def shipping_address
        order.ship_address.try(:active_merchant_hash)
      end

      def hash_methods
        [
          :email,
          :customer,
          :customer_id,
          :ip,
          :order_id,
          :shipping,
          :tax,
          :subtotal,
          :discount,
          :currency,
          :billing_address,
          :shipping_address
        ]
      end

      def to_hash
        Hash[hash_methods.map do |method|
          [method, send(method)]
        end]
      end

      private

      def order
        @payment.order
      end

      def exchange_multiplier
        @payment.payment_method.try(:exchange_multiplier) || 1.0
      end
    end
  end
end

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
spree_core-4.8.3 app/models/spree/payment/gateway_options.rb
spree_core-4.8.2 app/models/spree/payment/gateway_options.rb
spree_core-4.7.3 app/models/spree/payment/gateway_options.rb
spree_core-4.6.6 app/models/spree/payment/gateway_options.rb
spree_core-4.5.5 app/models/spree/payment/gateway_options.rb
spree_core-4.0.9 app/models/spree/payment/gateway_options.rb
spree_core-4.1.15 app/models/spree/payment/gateway_options.rb
spree_core-4.2.7 app/models/spree/payment/gateway_options.rb
spree_core-4.3.3 app/models/spree/payment/gateway_options.rb
spree_core-4.4.1 app/models/spree/payment/gateway_options.rb
spree_core-4.5.4 app/models/spree/payment/gateway_options.rb
spree_core-4.6.5 app/models/spree/payment/gateway_options.rb
spree_core-4.7.2 app/models/spree/payment/gateway_options.rb
spree_core-4.7.1 app/models/spree/payment/gateway_options.rb
spree_core-4.6.4 app/models/spree/payment/gateway_options.rb
spree_core-4.7.0 app/models/spree/payment/gateway_options.rb
spree_core-4.6.3 app/models/spree/payment/gateway_options.rb
spree_core-4.6.2 app/models/spree/payment/gateway_options.rb
spree_core-4.6.1 app/models/spree/payment/gateway_options.rb
spree_core-4.6.0 app/models/spree/payment/gateway_options.rb