Class: Wechatpay::Api::V2::Client

Inherits:
Object
  • Object
show all
Includes:
Pay
Defined in:
lib/wechatpay/api/v2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pay

#jsapi_params, #unifiedorder

Constructor Details

#initialize(appid, mch_id, **opts) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
27
28
29
# File 'lib/wechatpay/api/v2/client.rb', line 22

def initialize(appid, mch_id, **opts)
  @appid = appid
  @mch_id = mch_id
  @key = opts[:key]
  @site = opts[:site] || 'https://api.mch.weixin.qq.com'

  @logger = Logger.new(STDOUT)
end

Instance Attribute Details

#appidObject (readonly)

Returns the value of attribute appid.



19
20
21
# File 'lib/wechatpay/api/v2/client.rb', line 19

def appid
  @appid
end

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/wechatpay/api/v2/client.rb', line 19

def key
  @key
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/wechatpay/api/v2/client.rb', line 20

def logger
  @logger
end

#mch_idObject (readonly)

Returns the value of attribute mch_id.



19
20
21
# File 'lib/wechatpay/api/v2/client.rb', line 19

def mch_id
  @mch_id
end

#siteObject

Returns the value of attribute site.



20
21
22
# File 'lib/wechatpay/api/v2/client.rb', line 20

def site
  @site
end

Instance Method Details

#parse(body) ⇒ Object



45
46
47
# File 'lib/wechatpay/api/v2/client.rb', line 45

def parse(body)
  parser.parse(body)
end

#post(url, params, headers = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/wechatpay/api/v2/client.rb', line 31

def post(url, params, headers = {})
  data = sign(merge(params))
  response = connection.post url, xml(data), headers
  logger.debug { { response: response } }
  handle(response.body)
end

#verify(response) ⇒ Object



38
39
40
41
42
43
# File 'lib/wechatpay/api/v2/client.rb', line 38

def verify(response)
  sign = response.delete(:sign)
  test = sign(response)
  logger.debug { { result: test } }
  sign == test[:sign]
end