Sha256: 297ca6f6a5a3608e7b7e8a1e178dd7d8c84e272ec68c36461a338fdd93abe213

Contents?: true

Size: 621 Bytes

Versions: 5

Compression:

Stored size: 621 Bytes

Contents

module Supercharged
  module Helpers
    @gateways = {}

    def self.gateway(name)
      @gateways[name.to_sym] || raise("Gateway not registered")
    end

    def self.init_gateway(name, options)
      klass = gateway_class_by_name(name)
      gateway = klass.new(options)
      add_gateway(name, gateway)
    end

    private

  	def self.gateway_class_by_name(name)
      "ActiveMerchant::Billing::#{name.to_s.camelcase}Gateway".classify.constantize
    rescue NameError
      raise "Unknown gateway '#{name}'"
    end

    def self.add_gateway(name, gateway)
      @gateways[name.to_sym] = gateway
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
supercharged-2.1.0 lib/supercharged/helpers.rb
supercharged-2.0.4 lib/supercharged/helpers.rb
supercharged-2.0.3 lib/supercharged/helpers.rb
supercharged-2.0.2 lib/supercharged/helpers.rb
supercharged-2.0.1 lib/supercharged/helpers.rb