Commit 992064fa097f657624bfbfdbb9e8ea174c0a8974
Exists in
master
Merge pull request #18 from yijiasu/master
加入撤销订单的功能
Showing
1 changed file
with
60 additions
and
0 deletions
Show diff stats
lib/wx_pay/service.rb
... | ... | @@ -66,6 +66,66 @@ module WxPay |
66 | 66 | r |
67 | 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 | + | |
96 | + INVOKE_MICROPAY_REQUIRED_FIELDS = %i(body out_trade_no total_fee spbill_create_ip auth_code) | |
97 | + def self.invoke_micropay(params) | |
98 | + params = { | |
99 | + appid: WxPay.appid, | |
100 | + mch_id: WxPay.mch_id, | |
101 | + nonce_str: SecureRandom.uuid.tr('-', '') | |
102 | + }.merge(params) | |
103 | + puts params | |
104 | + check_required_options(params, INVOKE_MICROPAY_REQUIRED_FIELDS) | |
105 | + | |
106 | + r = invoke_remote "#{GATEWAY_URL}/pay/micropay", make_payload(params) | |
107 | + | |
108 | + yield(r) if block_given? | |
109 | + | |
110 | + r | |
111 | + end | |
112 | + | |
113 | + ORDER_QUERY_REQUIRED_FIELDS = %i(out_trade_no) | |
114 | + def self.order_query(params) | |
115 | + params = { | |
116 | + appid: WxPay.appid, | |
117 | + mch_id: WxPay.mch_id, | |
118 | + nonce_str: SecureRandom.uuid.tr('-', '') | |
119 | + }.merge(params) | |
120 | + puts params | |
121 | + check_required_options(params, ORDER_QUERY_REQUIRED_FIELDS) | |
122 | + | |
123 | + r = invoke_remote "#{GATEWAY_URL}/pay/orderquery", make_payload(params) | |
124 | + | |
125 | + yield(r) if block_given? | |
126 | + | |
127 | + r | |
128 | + end | |
69 | 129 | |
70 | 130 | private |
71 | 131 | ... | ... |