Module: WxPay::Service
- Defined in:
- lib/wx_pay/service.rb
Constant Summary collapse
- GATEWAY_URL =
'https://api.mch.weixin.qq.com'
- INVOKE_UNIFIEDORDER_REQUIRED_FIELDS =
[:body, :out_trade_no, :total_fee, :spbill_create_ip, :notify_url, :trade_type]
- GENERATE_APP_PAY_REQ_REQUIRED_FIELDS =
[:prepayid, :noncestr]
- INVOKE_REFUND_REQUIRED_FIELDS =
[:transaction_id, :out_trade_no, :out_refund_no, :total_fee, :refund_fee]
Class Method Summary collapse
- .generate_app_pay_req(params) ⇒ Object
- .invoke_refund(params) {|r| ... } ⇒ Object
- .invoke_unifiedorder(params) {|r| ... } ⇒ Object
Class Method Details
.generate_app_pay_req(params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wx_pay/service.rb', line 26 def self.generate_app_pay_req(params) params = { appid: WxPay.appid, partnerid: WxPay.mch_id, package: 'Sign=WXPay', timestamp: Time.now.to_i.to_s }.merge(params) (params, GENERATE_APP_PAY_REQ_REQUIRED_FIELDS) params[:sign] = WxPay::Sign.generate(params) params end |
.invoke_refund(params) {|r| ... } ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wx_pay/service.rb', line 42 def self.invoke_refund(params) params = { appid: WxPay.appid, mch_id: WxPay.mch_id, nonce_str: SecureRandom.uuid.tr('-', ''), op_user_id: WxPay.mch_id }.merge(params) (params, INVOKE_REFUND_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. = { 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/refund", make_payload(params) yield(r) if block_given? r end |
.invoke_unifiedorder(params) {|r| ... } ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wx_pay/service.rb', line 9 def self.invoke_unifiedorder(params) params = { appid: WxPay.appid, mch_id: WxPay.mch_id, nonce_str: SecureRandom.uuid.tr('-', '') }.merge(params) (params, INVOKE_UNIFIEDORDER_REQUIRED_FIELDS) r = invoke_remote("#{GATEWAY_URL}/pay/unifiedorder", make_payload(params)) yield r if block_given? r end |