From 79784bf1386eacc5c756b2c4f403d64f060c9e88 Mon Sep 17 00:00:00 2001 From: Su Yijia Date: Thu, 24 Sep 2015 17:32:44 +0800 Subject: [PATCH] add invoke reverse --- lib/wx_pay/service.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+), 0 deletions(-) diff --git a/lib/wx_pay/service.rb b/lib/wx_pay/service.rb index ea58640..f68f4de 100644 --- a/lib/wx_pay/service.rb +++ b/lib/wx_pay/service.rb @@ -66,6 +66,33 @@ module WxPay r end + INVOKE_REVERSE_REQUIRED_FIELDS = %i(out_trade_no) + def self.invoke_reverse(params) + params = { + appid: WxPay.appid, + mch_id: WxPay.mch_id, + nonce_str: SecureRandom.uuid.tr('-', '') + }.merge(params) + + check_required_options(params, INVOKE_REVERSE_REQUIRED_FIELDS) + + # 微信退款需要双向证书 + # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4 + # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3 + + WxPay.extra_rest_client_options = { + ssl_client_cert: WxPay.apiclient_cert.certificate, + ssl_client_key: WxPay.apiclient_cert.key, + verify_ssl: OpenSSL::SSL::VERIFY_NONE + } + + r = invoke_remote "#{GATEWAY_URL}/secapi/pay/reverse", make_payload(params) + + yield(r) if block_given? + + r + end + private -- libgit2 0.21.0