Commit 2ed2421b00af87f2fa3ad37a34321c1b35f143ab
1 parent
95819f0c
Exists in
master
Add downloadbill api
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6
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 | ... | ... |