Class: Wechatpay::Api::V2::Client
- Inherits:
-
Object
- Object
- Wechatpay::Api::V2::Client
- Includes:
- Pay
- Defined in:
- lib/wechatpay/api/v2/client.rb
Instance Attribute Summary collapse
-
#appid ⇒ Object
readonly
Returns the value of attribute appid.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#mch_id ⇒ Object
readonly
Returns the value of attribute mch_id.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(appid, mch_id, **opts) ⇒ Client
constructor
A new instance of Client.
- #parse(body) ⇒ Object
- #post(url, params, headers = {}) ⇒ Object
- #verify(response) ⇒ Object
Methods included from Pay
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
#appid ⇒ Object (readonly)
Returns the value of attribute appid.
19 20 21 |
# File 'lib/wechatpay/api/v2/client.rb', line 19 def appid @appid end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
19 20 21 |
# File 'lib/wechatpay/api/v2/client.rb', line 19 def key @key end |
#logger ⇒ Object
Returns the value of attribute logger.
20 21 22 |
# File 'lib/wechatpay/api/v2/client.rb', line 20 def logger @logger end |
#mch_id ⇒ Object (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 |
#site ⇒ Object
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 |