Sha256: f901496a0aab4cb7ee25dfafd9f0a2ea032392d29a0b6e0d7d405893aa090835

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

module Spree
  class KomojuGateway < Gateway
    preference :api_key, :string

    def provider_class
      ActiveMerchant::Billing::KomojuGateway
    end

    def options
      super.merge(login: preferred_api_key, test: preferred_test_mode, locale: locale)
    end

    def auto_capture?
      false
    end

    def payment_profiles_supported?
      false
    end

    def supports?(source)
      true
    end

    # We need to change shipping, tax, subtotal and discount from cents to dollar for Komoju gateway.
    # Because, Komoju gateway supports JPY currency only.
    #
    # Spree changes price from dollar to cents. Almost payment gateway supports cents only.
    # See. https://github.com/spree/spree/blob/master/core/app/models/spree/payment/gateway_options.rb
    def change_options_to_dollar(options)
      %i(shipping tax subtotal discount).each { |key| options[key] = options[key] / 100.0 }
      options
    end

    def gateway_type
      self.class.to_s.split("::Komoju").last.underscore
    end

    def method_type
      "komoju_#{gateway_type}"
    end

    def payment_source_class
      "Spree::#{gateway_type.camelcase}".constantize
    end

    private

    def locale
      I18n.locale == :ja ? "ja" : "en"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_komoju-0.1.4 app/models/spree/komoju_gateway.rb
spree_komoju-0.1.3 app/models/spree/komoju_gateway.rb
spree_komoju-0.1.2 app/models/spree/komoju_gateway.rb
spree_komoju-0.1.1 app/models/spree/komoju_gateway.rb
spree_komoju-0.1.0 app/models/spree/komoju_gateway.rb