Commit ce10402fe8c17af6c78289335a23e8cda1e1ea73

Authored by Jun Jiang
Committed by GitHub
2 parents 95819f0c 2ed2421b
Exists in master

Merge pull request #37 from Eric-Guo/download_bill

Add downloadbill api
Showing 1 changed file with 21 additions and 4 deletions   Show diff stats
lib/wx_pay/service.rb
... ... @@ -183,7 +183,24 @@ module WxPay
183 183  
184 184 r
185 185 end
186   -
  186 +
  187 + DOWNLOAD_BILL_REQUIRED_FIELDS = [:bill_date, :bill_type]
  188 + def self.download_bill(params, options = {})
  189 + params = {
  190 + appid: options.delete(:appid) || WxPay.appid,
  191 + mch_id: options.delete(:mch_id) || WxPay.mch_id,
  192 + nonce_str: SecureRandom.uuid.tr('-', ''),
  193 + }.merge(params)
  194 +
  195 + check_required_options(params, DOWNLOAD_BILL_REQUIRED_FIELDS)
  196 +
  197 + r = invoke_remote("#{GATEWAY_URL}/pay/downloadbill", make_payload(params), options)
  198 +
  199 + yield r if block_given?
  200 +
  201 + r
  202 + end
  203 +
187 204 def self.sendgroupredpack(params, options={})
188 205 params = {
189 206 wxappid: options.delete(:appid) || WxPay.appid,
... ... @@ -255,10 +272,10 @@ module WxPay
255 272 }.merge(options)
256 273 )
257 274  
258   - if r
  275 + begin
259 276 WxPay::Result.new(Hash.from_xml(r))
260   - else
261   - nil
  277 + rescue REXML::ParseException
  278 + r
262 279 end
263 280 end
264 281 end
... ...