Sha256: 149bfb5ff4c84be3a80d11fc329ed82dfa058dccccaa0839dbe69e8f0283c062

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Yeepay
  module Service
    module Card
      #发起支付交易
      def self.create_trade(options = {})
        options = Yeepay::Service.string_key2_sym(options)
        #组合支付请求参数
        trade_data = gen_params(options)
        trade_data[:hmac] = Yeepay::Service.hmac_md5_sign(trade_data)
        warn("\ntrade_data #{trade_data}")

        #发起支付请求
        begin
          res = open("#{GATEWAY_URL}?#{trade_data.collect { |key, value| "#{key}=#{value}" }.join('&')}").read
          warn("\nres #{res}")
        rescue => err
          warn("\nSocketError #{err}\n\n")
          return {}
        end

        #处理支付结果
        res_data = receive_response(options, res)
        warn("\nres_data #{res_data}")
        res_data
      end

      #校验支付签名
      def self.verify?(options={})
        options = Yeepay::Service.string_key2_sym(options)
        notify_params = res_verifying_params(options)
        warn("\nnotfy_params  #{notify_params}")
        notify_hmac = Yeepay::Service.hmac_md5_sign(notify_params)

        warn("\nnotify_sign #{options[:hmac]}, verify_sign: #{notify_hmac}")
        notify_hmac == options[:hmac]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yeepay-0.2.2 lib/yeepay/service/card.rb
yeepay-0.2.0 lib/yeepay/service/card.rb
yeepay-0.1.9 lib/yeepay/service/card.rb