Sha256: c6f96cd6050c7d782d4faab0f533c85e822ec52df095f12b1e5772e9cc776900

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'date'
require 'uri'
require 'http' # https://github.com/httprb/http

module LlPay
  module QueryOrder
    def self.query_single_order(sign_type, no_order, dt_order)
      query_order_hash = { oid_partner: LlPay.oid_partner, dt_order: dt_order, no_order: no_order }

      if sign_type == 'RSA'
        query_order_hash[:sign_type] = 'RSA'
        query_order_hash[:sign] = LlPay::Sign::RSA.sign(LlPay.rsa_pri_key, params_to_string(query_order_hash))
      else
        query_order_hash[:sign_type] = 'MD5'
        query_order_hash[:sign] = LlPay::Sign::MD5.sign(LlPay.md5_key, params_to_string(query_order_hash))
      end

      http_response = HTTP.post('https://yintong.com.cn/queryapi/orderquery.htm',
                                json: query_order_hash)

      response_hash = JSON.parse(http_response.body.to_s)

      if http_response.code == 200
        if response_hash['ret_code'] == 0000 && LlPay::Sign.verify?(params_to_string(response_hash))
          return response_hash
        else
          return response_hash
        end
      else
        return
      end
    end

    def self.params_to_string(params)
      params.sort.map do |k, v|
        "#{k}=#{v}" if v.to_s != '' && k.to_s != 'sign'
      end.compact.join('&')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ll_pay-0.2.0 lib/ll_pay/query_order.rb