Commit 79784bf1386eacc5c756b2c4f403d64f060c9e88
1 parent
ee0099fd
Exists in
master
add invoke reverse
Showing
1 changed file
with
27 additions
and
0 deletions
Show diff stats
lib/wx_pay/service.rb
@@ -66,6 +66,33 @@ module WxPay | @@ -66,6 +66,33 @@ module WxPay | ||
66 | r | 66 | r |
67 | end | 67 | end |
68 | 68 | ||
69 | + INVOKE_REVERSE_REQUIRED_FIELDS = %i(out_trade_no) | ||
70 | + def self.invoke_reverse(params) | ||
71 | + params = { | ||
72 | + appid: WxPay.appid, | ||
73 | + mch_id: WxPay.mch_id, | ||
74 | + nonce_str: SecureRandom.uuid.tr('-', '') | ||
75 | + }.merge(params) | ||
76 | + | ||
77 | + check_required_options(params, INVOKE_REVERSE_REQUIRED_FIELDS) | ||
78 | + | ||
79 | + # 微信退款需要双向证书 | ||
80 | + # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4 | ||
81 | + # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3 | ||
82 | + | ||
83 | + WxPay.extra_rest_client_options = { | ||
84 | + ssl_client_cert: WxPay.apiclient_cert.certificate, | ||
85 | + ssl_client_key: WxPay.apiclient_cert.key, | ||
86 | + verify_ssl: OpenSSL::SSL::VERIFY_NONE | ||
87 | + } | ||
88 | + | ||
89 | + r = invoke_remote "#{GATEWAY_URL}/secapi/pay/reverse", make_payload(params) | ||
90 | + | ||
91 | + yield(r) if block_given? | ||
92 | + | ||
93 | + r | ||
94 | + end | ||
95 | + | ||
69 | 96 | ||
70 | private | 97 | private |
71 | 98 |