Module: Wechatpay::Service

Defined in:
lib/wechatpay/service.rb

Class Method Summary collapse

Class Method Details

.pay_params(prepay_id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wechatpay/service.rb', line 28

def pay_params(prepay_id)
  options = {
    appId: Wechatpay::Config.app_id,
    timeStamp: Wechatpay::Utils.timestamp,
    nonceStr: Wechatpay::Utils.nonce_str,
    package: "prepay_id=#{prepay_id}",
    signType: "MD5"
  }
  options[:paySign] = Wechatpay::Sign.md5(options)
  options.delete :appId
  options
end

.unified_order(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wechatpay/service.rb', line 7

def unified_order(options)
  config = Wechatpay::Config
  options = {
    appid: config.app_id,
    mch_id: config.mch_id,
    nonce_str: Wechatpay::Utils.nonce_str
  }.merge(options)

  body = Wechatpay::Utils.add_sign_and_generate_xml_body(options)
  response = HTTParty.post(
    Wechatpay::Config::UNIFIED_ORDER_URL,
    :body => body
  )
  result = Hash.from_xml(response.body)["xml"]
  if Wechatpay::Sign.valid?(result)
    result
  else
    nil
  end
end