Sha256: ffeef6409910fbfd41bea3a8bcc104de6306261e554f02a8cd6e0536d5cc8976

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

# coding: utf-8
# 客户端

module Reapal
  class Client

    attr_accessor :config

    def initialize(options_arg)
      options = Utils.symbolize_keys(options_arg)
      @config = {
        server_url: options[:server_url],
        partner_id: options[:partner_id],
        merchant_id: options[:merchant_id],
        md5_key: options[:md5_key],
        private_key: OpenSSL::PKey::RSA.new(options[:private_key], options[:private_key_pwd]),
        public_key: OpenSSL::X509::Certificate.new(options[:public_key]).public_key,
      }

      # 自动 include api 下的模块
      recursive_include_api('Reapal::Api')
      # 自动 include form 下的模块
      recursive_include_api('Reapal::Form')
    end

    def decode_notify_data(encryptkey, data)
      ::Reapal::Http::Decode.decode_notify_data(encryptkey, data, @config)
    end

    private
    def recursive_include_api(module_chain)
      modules = eval("#{module_chain}.constants").each{ |constant| eval("#{module_chain}::#{constant}").class.kind_of?(Module) }

      if modules.empty?
        self.class.send(:include, eval(module_chain))
      else
        modules.each{ |constant| recursive_include_api("#{module_chain}::#{constant}") }
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
reapal-0.10.1 lib/reapal/client.rb
reapal-0.10.0 lib/reapal/client.rb
reapal-0.9.13 lib/reapal/client.rb
reapal-0.9.12 lib/reapal/client.rb
reapal-0.9.11 lib/reapal/client.rb
reapal-0.9.10 lib/reapal/client.rb
reapal-0.9.9 lib/reapal/client.rb
reapal-0.9.7 lib/reapal/client.rb
reapal-0.9.6 lib/reapal/client.rb
reapal-0.9.5 lib/reapal/client.rb
reapal-0.9.3 lib/reapal/client.rb
reapal-0.9.2 lib/reapal/client.rb
reapal-0.9.1 lib/reapal/client.rb
reapal-0.9.0 lib/reapal/client.rb
reapal-0.3.0 lib/reapal/client.rb