Class: Wechat::Pay::Client
- Inherits:
-
Object
- Object
- Wechat::Pay::Client
- Includes:
- Redpack
- Defined in:
- lib/wechat/pay/client.rb
Constant Summary collapse
- BASE_URL =
'https://api.mch.weixin.qq.com'- REQUIRED_OPTS =
%w(key password cert sign_key).map(&:to_sym).freeze
- ERRORS =
{ 'NO_AUTH' => NoAuthError, 'NOTENOUGH' => NotEnoughError, 'TIME_LIMITED' => TimeLimitedError, 'MONEY_LIMITED' => MoneyLimitedError }
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(mch_id, wxappid, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, params) ⇒ Object
Methods included from Redpack
#group_redpack, #redpack, #redpack_info
Constructor Details
#initialize(mch_id, wxappid, opts = {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wechat/pay/client.rb', line 32 def initialize(mch_id, wxappid, opts = {}) @mch_id = mch_id @wxappid = wxappid @opts = Hash[opts.map { |k, v| [k.to_sym, v] }] unless (REQUIRED_OPTS - @opts.keys).empty? fail format('%s required', REQUIRED_OPTS.join(',')) end @logger = Logger.new(STDOUT) rsa_setup @parser = Nori.new end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
30 31 32 |
# File 'lib/wechat/pay/client.rb', line 30 def logger @logger end |
Instance Method Details
#post(path, params) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/wechat/pay/client.rb', line 44 def post(path, params) merged_params = merge(params) logger.debug { merged_params } resp = resource(path).post(xml(sign(merged_params))) handle(resp) rescue RestClient::ExceptionWithResponse => err raise PayError, err.response end |