module WechatPay::Ecommerce
# 服务商相关接口封装(电商平台,服务商有许多接口共用) 文档: pay.weixin.qq.com/wiki/doc/apiv3_partner/open/pay/chapter3_3_3.shtml
PS: 电商收付通的所有接口已经封装完毕,有需要再补充。
商户进件相关
余额相关
账单相关
合并订单相关
订单相关
分账相关
退款相关
补差相关
提现相关
Public Class Methods
添加分账接收方
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_7.shtml
Example:
“` ruby WechatPay::Ecommerce.add_profitsharing_receivers
(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 181 def add_profitsharing_receivers(params) url = '/v3/ecommerce/profitsharing/receivers/add' method = 'POST' params = params.merge({ appid: WechatPay.app_id }) payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
二级商户进件
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_1.shtml
Example:
“` ruby params = {
"organization_type": "2", "business_license_info": { "business_license_copy": "47ZC6GC-vnrbEg05InE4d2I6_H7I4", "business_license_number": "123456789012345678", "merchant_name": "腾讯科技有限公司", "legal_person": "张三" }, "organization_cert_info": { "organization_copy": "47ZC6GC-vnrbEny__Ie_An5-tCpqxuGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4 ", "organization_time": "[\"2014-01-01\",\"长期\"]", "organization_number": "12345679-A" }, "id_card_info": { "id_card_copy": "jTpGmxUX3FBWVQ5NJTZvlKC-ehEuo0BJqRTvDujqhThn4ReFxikqJ5YW6zFQ", "id_card_national": "47ZC6GC-vnrbEny__Ie_AnGprrKhpVBDIUv0OF4wFNIO4kqg05InE4d2I6_H7I4", "id_card_name": "pVd1HJ6z7UtC + xriudjD5AqhZ9evAM + Jv1z0NVa8MRtelw / wDa4SzfeespQO / 0 kjiwfqdfg =", "id_card_number": "UZFETyabYFFlgvGh6R4vTzDRgzvA2HtP5VHahNhSUqhR9iuGTunRPRVFg ==", "id_card_valid_time": "2026-06-06" }, "need_account_info": true, "account_info": { "bank_account_type": "74", "account_name": "fTA4TXc8yMOwFCYeGPktOOSbOBei3KAmUWHGxCQo2hfaC7xumTqXR7 / NyRHpFKXURQFcmmw ==", "account_bank": "工商银行", "bank_address_code": "110000", "bank_branch_id": "402713354941", "bank_name": "施秉县农村信用合作联社城关信用社", "account_number": "d+xT+MQCvrLHUVD5Fnx30mr4L8sPndjXTd75kPkyjqnoMRrEEaYQE8ZRGYoeorwC" }, "contact_info": { "contact_type": "65", "contact_name": "pVd1HJ6zyvPedzGaV+Xy7UDa4SzfeespQO / 0 kjiwfqdfg ==", "contact_id_card_number": "UZFETyabYFFlgvGh6R4vTzDEOiZZ4ka9+5RgzvA2rJx+NztYUbN209rqR9iuGTunRPRVFg ==", "mobile_phone": "Uy5Hb0c5Se/orEbrWze/ROHu9EPAs/CigDlJ2fnyzC1ppJNBrqcBszhYQUlu5zn6o2uZpBhAsQwd3QAjw==", "contact_email": "Uy5Hb0c5Se/orEbrWze/ROHu9EPAs/CigDlJ2fnyzC1ppJNaLZExOEzmUn6o2uZpBhAsQwd3QAjw==" }, "sales_scene_info": { "store_name": "爱烧烤", "store_url": "http://www.qq.com", "store_qr_code": "jTpGmxUX3FBWVQ5NJTZvlKX_gdU4cRz7z5NxpnFuAujqhThn4ReFxikqJ5YW6zFQ" }, "merchant_shortname": "爱烧烤", "out_request_no": "APPLYMENT_00000000001", "qualifications": "[\"jTpGmxUX3FBWVQ5NJInE4d2I6_H7I4\"]", "business_addition_pics": "[\"jTpGmg05InE4d2I6_H7I4\"]", "business_addition_desc": "特殊情况,说明原因"
} “`
“` ruby WechatPay::Ecommerce.applyment(params)
“`
# File lib/wechat-pay/ecommerce/applyment.rb, line 67 def self.applyment(payload) url = '/v3/ecommerce/applyments/' method = 'POST' payload_json = payload.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json, extra_headers: { 'Wechatpay-Serial' => WechatPay.platform_serial_no } ) end
取消补差
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_3.shtml
Example:
“` ruby WechatPay::Ecommerce.return_subsidies
(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333') “`
# File lib/wechat-pay/ecommerce/subsidies.rb, line 70 def self.cancel_subsidies(params) url = '/v3/ecommerce/subsidies/cancel' method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
证书获取
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_3.shtml
Example:
“` ruby WechatPay::Ecommerce.certificates
“`
# File lib/wechat-pay/ecommerce/applyment.rb, line 126 def self.certificates url = '/v3/certificates' method = 'GET' make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
关闭合单
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
“` ruby WechatPay::Ecommerce.close_combine_order
(combine_out_trade_no: 'C202104302474') “`
# File lib/wechat-pay/ecommerce/combine_order.rb, line 89 def self.close_combine_order(params) combine_out_trade_no = params.delete(:combine_out_trade_no) url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}/close" payload = { combine_appid: WechatPay.app_id }.merge(params) payload_json = payload.to_json method = 'POST' make_request( method: method, for_sign: payload_json, payload: payload_json, path: url ) end
关闭订单
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_6.shtml
“` ruby WechatPay::Ecommerce.close_order
(sub_mchid: '16000008', out_trade_no: 'N3344445') “`
# File lib/wechat-pay/ecommerce/order.rb, line 95 def self.close_order(params) out_trade_no = params.delete(:out_trade_no) url = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}/close" params = params.merge({ sp_mchid: WechatPay.mch_id }) method = 'POST' make_request( method: method, path: url, for_sign: params.to_json, payload: params.to_json ) end
@private @!macro [attach] define_transaction_method
$1合单 Document: $3 Example: ``` ruby params = { combine_out_trade_no: 'combine_out_trade_no', combine_payer_info: { openid: 'client open id' }, sub_orders: [ { mchid: 'mchid', sub_mchid: 'sub mchid', attach: 'attach', amount: { total_amount: 100, currency: 'CNY' }, out_trade_no: 'out_trade_no', description: 'description' } ], notify_url: 'the_url' } WechatPay::Ecommerce.invoke_combine_transactions_in_$1(params) ``` @!method invoke_combine_transactions_in_$1 @!scope class
# File lib/wechat-pay/ecommerce/combine_order.rb, line 40 def self.define_combine_transaction_method(key, value, _document) const_set("INVOKE_COMBINE_TRANSACTIONS_IN_#{key.upcase}_FIELDS", %i[combine_out_trade_no combine_payer_info sub_orders notify_url].freeze) define_singleton_method("invoke_combine_transactions_in_#{key}") do |params| combine_transactions_method_by_suffix(value, params) end end
@private @!macro [attach] define_transaction_method
$1下单 Document: $3 Example: ``` params = { description: 'pay', out_trade_no: 'Order Number', payer: { sp_openid: 'wechat open id' }, amount: { total: 10 }, sub_mchid: 'Your sub mchid', notify_url: 'the url' } WechatPay::Ecommerce.invoke_transactions_in_$1(params) ``` @!method invoke_transactions_in_$1 @!scope class
# File lib/wechat-pay/ecommerce/order.rb, line 32 def self.define_transaction_method(key, value, _document) const_set("INVOKE_TRANSACTIONS_IN_#{key.upcase}_FIELDS", %i[sub_mchid description out_trade_no notify_url amount].freeze) define_singleton_method("invoke_transactions_in_#{key}") do |params| transactions_method_by_suffix(value, params) end end
删除分账接收方
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_8.shtml
Example:
“` ruby WechatPay::Ecommerce.remove_profitsharing_receivers(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 211 def delete_profitsharing_receivers(params) url = '/v3/ecommerce/profitsharing/receivers/delete' method = 'POST' params = params.merge({ appid: WechatPay.app_id }) payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
按日下载提现异常文件
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_4.shtml
“` ruby WechatPay::Ecommerce.download_exception_withdraw_file
(bill_type: 'NO_SUCC', bill_date: '2021-05-10') “`
# File lib/wechat-pay/ecommerce/withdraw.rb, line 136 def self.download_exception_withdraw_file(params) bill_type = params.delete(:bill_type) path = "/v3/merchant/fund/withdraw/bill-type/#{bill_type}" method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
二级商户资金账单
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_5.shtml
Example:
“` ruby WechatPay::Ecommerce.ecommerce_fundflowbill
(bill_date: '2021-04-30', account_type: 'ALL', algorithm: 'AEAD_AES_256_GCM') “`
# File lib/wechat-pay/ecommerce/bill.rb, line 74 def ecommerce_fundflowbill(params) path = '/v3/ecommerce/bill/fundflowbill' method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
完结分账
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_5.shtml
Example:
“` ruby WechatPay::Ecommerce.finish_profitsharing
(sub_mchid: '160000', out_order_no: 'P202104303106', transaction_id: '4323400972202104305131070133', description: '直接打款到二级商户不分账').bod “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 129 def finish_profitsharing(params) url = '/v3/ecommerce/profitsharing/finish-order' method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
申请资金账单
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_2.shtml
Example:
“` ruby WechatPay::Ecommerce.fundflowbill
(bill_date: '2021-04-30') “`
# File lib/wechat-pay/ecommerce/bill.rb, line 46 def fundflowbill(params) path = '/v3/bill/fundflowbill' method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
退款申请
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_1.shtml
Example:
“` ruby WechatPay::Ecommerce.invoke_refund
(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', total: 1, refund: 1, description: '退款', out_refund_no: 'R10000') # by transaction_id WechatPay::Ecommerce.invoke_refund
(sub_mchid: '1608977559', total: 1, refund: 1, description: '退款', out_trade_no: 'N202104302474', out_refund_no: 'R10000') # by out_trade_no “`
# File lib/wechat-pay/ecommerce/refund.rb, line 18 def self.invoke_refund(params) url = '/v3/ecommerce/refunds/apply' method = 'POST' amount = { refund: params.delete(:refund), total: params.delete(:total), currency: 'CNY' } params = params.merge({ amount: amount, sp_appid: WechatPay.app_id }) make_request( path: url, method: method, for_sign: params.to_json, payload: params.to_json ) end
图片上传
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter2_1_1.shtml
Example:
“` ruby WechatPay::Ecommerce.media_upload
(File.open('Your Image')) “`
# File lib/wechat-pay/ecommerce.rb, line 68 def self.media_upload(image) url = '/v3/merchant/media/upload' method = 'POST' meta = { filename: image.to_path, sha256: Digest::SHA256.hexdigest(image.read) } image.rewind payload = { meta: meta.to_json, file: image } make_request( method: method, path: url, for_sign: meta.to_json, payload: payload, extra_headers: { 'Content-Type' => nil # Pass nil to remove the Content-Type } ) end
视频上传
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter2_1_2.shtml
Example:
“` ruby WechatPay::Ecommerce.media_video_upload
(File.open('Your Video')) “`
# File lib/wechat-pay/ecommerce.rb, line 34 def self.media_video_upload(video) url = '/v3/merchant/media/video_upload' method = 'POST' meta = { filename: video.to_path, sha256: Digest::SHA256.hexdigest(video.read) } video.rewind payload = { meta: meta.to_json, file: video } make_request( method: method, path: url, for_sign: meta.to_json, payload: payload, extra_headers: { 'Content-Type' => nil } ) end
修改结算账号
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_4.shtml
Example:
“` ruby WechatPay::Ecommerce.modify_settlement
(sub_mchid: '15000000', account_type: 'ACCOUNT_TYPE_PRIVATE', account_bank: '工商银行', bank_address_code: '110000', account_number: WechatPay::Sign.sign_important_info
('755555555')) “`
# File lib/wechat-pay/ecommerce/applyment.rb, line 177 def self.modify_settlement(params) sub_mchid = params.delete(:sub_mchid) url = "/v3/apply4sub/sub_merchants/#{sub_mchid}/modify-settlement" method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json, extra_headers: { 'Wechatpay-Serial' => WechatPay.platform_serial_no } ) end
电商平台提现
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_5.shtml
Example:
“` ruby WechatPay::Ecommerce.platform_withdraw
(out_request_no: 'P10000', amount: 1, account_type: 'BASIC') WechatPay::Ecommerce.platform_withdraw
(out_request_no: 'P10000', amount: 1, account_type: 'FEES') “`
# File lib/wechat-pay/ecommerce/withdraw.rb, line 80 def self.platform_withdraw(params) url = '/v3/merchant/fund/withdraw' method = 'POST' make_request( method: method, path: url, for_sign: params.to_json, payload: params.to_json ) end
通过商户的申请单或微信的申请单号查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_2.shtml
Example:
“` ruby WechatPay::Ecommerce.query_applyment
(out_request_no: 'APPLYMENT_00000000005') # by out_request_no WechatPay::Ecommerce.query_applyment
(applyment_id: '200040444455566667') # by_applyment_id “`
# File lib/wechat-pay/ecommerce/applyment.rb, line 97 def self.query_applyment(params) if params[:applyment_id] applyment_id = params.delete(:applyment_id) url = "/v3/ecommerce/applyments/#{applyment_id}" else out_request_no = params.delete(:out_request_no) url = "/v3/ecommerce/applyments/out-request-no/#{out_request_no}" end method = 'GET' make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
合单查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml
“` ruby WechatPay::Ecommerce.query_order
(combine_out_trade_no: 'C202104302474') “`
# File lib/wechat-pay/ecommerce/combine_order.rb, line 64 def self.query_combine_order(params) combine_out_trade_no = params.delete(:combine_out_trade_no) url = "/v3/combine-transactions/out-trade-no/#{combine_out_trade_no}" method = 'GET' make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
日终余额查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_2.shtml
Example:
“` ruby WechatPay::Ecommerce.query_endday_balance
(sub_mchid: '1600000', date: '2019-08-17') “`
# File lib/wechat-pay/ecommerce/balance.rb, line 42 def self.query_endday_balance(params) sub_mchid = params.delete(:sub_mchid) path = "/v3/ecommerce/fund/balance/#{sub_mchid}" method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
订单查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml
“` ruby WechatPay::Ecommerce.query_order
(sub_mchid: '16000008', transaction_id: '4323400972202104305133344444') # by transaction_id WechatPay::Ecommerce.query_order
(sub_mchid: '16000008', out_trade_no: 'N202104302474') # by out_trade_no “`
# File lib/wechat-pay/ecommerce/order.rb, line 57 def self.query_order(params) if params[:transaction_id] params.delete(:out_trade_no) transaction_id = params.delete(:transaction_id) path = "/v3/pay/partner/transactions/id/#{transaction_id}" else params.delete(:transaction_id) out_trade_no = params.delete(:out_trade_no) path = "/v3/pay/partner/transactions/out-trade-no/#{out_trade_no}" end params = params.merge({ sp_mchid: WechatPay.mch_id }) method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
平台商户日终余额
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml
Example:
“` ruby WechatPay::Ecommerce.query_platform_endday_balance
(account_type: 'BASIC') WechatPay::Ecommerce.query_platform_endday_balance
(account_type: 'FEES') “`
# File lib/wechat-pay/ecommerce/balance.rb, line 98 def self.query_platform_endday_balance(params) account_type = params.delete(:account_type) path = "/v3/merchant/fund/dayendbalance/#{account_type}" method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
平台商户实时余额
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml
Example:
“` ruby WechatPay::Ecommerce.query_platform_realtime_balance
(account_type: 'BASIC') # basic account WechatPay::Ecommerce.query_platform_realtime_balance
(account_type: 'FEES') # fees account “`
# File lib/wechat-pay/ecommerce/balance.rb, line 71 def self.query_platform_realtime_balance(params) account_type = params.delete(:account_type) url = "/v3/merchant/fund/balance/#{account_type}" method = 'GET' make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
商户平台提现查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_6.shtml
Example:
“` ruby WechatPay::Ecommerce.query_platform_withdraw
(out_request_no: 'P1000') WechatPay::Ecommerce.query_platform_withdraw
(withdraw_id: '12313153') “`
# File lib/wechat-pay/ecommerce/withdraw.rb, line 105 def self.query_platform_withdraw(params) if params[:withdraw_id] params.delete(:out_request_no) withdraw_id = params.delete(:withdraw_id) url = "/v3/merchant/fund/withdraw/withdraw-id/#{withdraw_id}" else params.delete(:withdraw_id) out_request_no = params.delete(:out_request_no) url = "/v3/merchant/fund/withdraw/out-request-no/#{out_request_no}" end method = 'GET' make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
分账结果查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_2.shtml
Example:
“` ruby WechatPay::Ecommerce.query_profitsharing
(out_order_no: 'N202104288345', sub_mchid: '16000000', transaction_id: '4200001048202104280183691118') “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 51 def query_profitsharing(params) method = 'GET' query = build_query(params) path = '/v3/ecommerce/profitsharing/orders' url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
查询订单剩余待分金额
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_9.shtml
Example:
“` ruby WechatPay::Ecommerce.query_profitsharing_amount
({ transaction_id: '4323400972202104301286330188' }) “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 155 def query_profitsharing_amount(params) method = 'GET' transaction_id = params.delete(:transaction_id) url = "/v3/ecommerce/profitsharing/orders/#{transaction_id}/amounts" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
余额实时查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_1.shtml
Example:
“` ruby WechatPay::Ecommerce.query_realtime_balance
(sub_mchid: '1600000') “`
# File lib/wechat-pay/ecommerce/balance.rb, line 17 def self.query_realtime_balance(params) sub_mchid = params.delete(:sub_mchid) url = "/v3/ecommerce/fund/balance/#{sub_mchid}" method = 'GET' make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
退款查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_2.shtml
Example:
“` ruby WechatPay::Ecommerce.query_refund
(sub_mchid: '16000000', out_refund_no: 'N202104302474') # 注意这里的out_refund_no用的是商户订单号,微信文档有误 WechatPay::Ecommerce.query_refund
(sub_mchid: '16000000', refund_id: '420000103020210508005624628') # 注意这里的refund_id用的是微信交易单号transaction_id,微信文档有误 “`
# File lib/wechat-pay/ecommerce/refund.rb, line 53 def self.query_refund(params) if params[:refund_id] params.delete(:out_refund_no) refund_id = params.delete(:refund_id) path = "/v3/pay/partner/transactions/id/#{refund_id}" else params.delete(:refund_id) out_refund_no = params.delete(:out_refund_no) path = "/v3/pay/partner/transactions/out-trade-no/#{out_refund_no}" end params = params.merge({ sp_mchid: WechatPay.mch_id }) method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
退款查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_2.shtml
Example:
“` ruby WechatPay::Ecommerce.query_refund
(sub_mchid: '16000000', out_refund_no: 'N202104302474') # 注意这里的out_refund_no用的是商户订单号,微信文档有误 WechatPay::Ecommerce.query_refund
(sub_mchid: '16000000', refund_id: '420000103020210508005624628') # 注意这里的refund_id用的是微信交易单号transaction_id,微信文档有误 “`
# File lib/wechat-pay/ecommerce/refund.rb, line 119 def self.query_return_advance_refund(params) refund_id = params.delete(:refund_id) path = "/v3/ecommerce/refunds/#{refund_id}/return-advance" method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
分账回退结果查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_4.shtml
Example:
“` ruby WechatPay::Ecommerce.query_return_profitsharing
(sub_mchid: '1608747309', out_order_no: 'P202104306585', out_return_no: 'R202105023455') WechatPay::Ecommerce.query_return_profitsharing
(sub_mchid: '1608747309', order_id: '3008450740201411110007820472', out_return_no: 'R202105023455') “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 102 def query_return_profitsharing(params) method = 'GET' query = build_query(params) path = '/v3/ecommerce/profitsharing/returnorders' url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
查询结算账户
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_5.shtml
Example:
“` ruby WechatPay::Ecommerce.query_settlement
(sub_mchid: '16000000') “`
# File lib/wechat-pay/ecommerce/applyment.rb, line 151 def self.query_settlement(params) sub_mchid = params.delete(:sub_mchid) url = "/v3/apply4sub/sub_merchants/#{sub_mchid}/settlement" method = 'GET' make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
二级商户提现查询
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml
Example:
“` ruby WechatPay::Ecommerce.query_withdraw
(withdraw_id: '335556', sub_mchid: '160000') WechatPay::Ecommerce.query_withdraw
(out_request_no: 'P1000', sub_mchid: '160000') “`
# File lib/wechat-pay/ecommerce/withdraw.rb, line 43 def self.query_withdraw(params) if params[:withdraw_id] params.delete(:out_request_no) withdraw_id = params.delete(:withdraw_id) path = "/v3/ecommerce/fund/withdraw/#{withdraw_id}" else params.delete(:withdraw_id) out_request_no = params.delete(:out_request_no) path = "/v3/ecommerce/fund/withdraw/out-request-no/#{out_request_no}" end method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( method: method, path: url, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
分账请求
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_1.shtml
Example:
“` ruby params = {“out_trade_no”=>“P202104306585”, “transaction_id”=>“4323400972202104301286330188”, “sub_mchid”=>“160000”, “out_order_no”=>“N202104307987”, “finish”=>true, “receivers”=>[{“type”=>“MERCHANT_ID”, “receiver_account”=>“1607189890”, “amount”=>1, “description”=>“平台抽成”, “receiver_name”=>“CXOO5SF5sylMhSWjUBHQ6dBN0BTdrGExiziO8OEnJEG/nAa7gw6JTbsFQVhUbXD2er07Gcvt7qsLg7wYEe6iqNKbHHRWvChVVKWcKSyvfMOcRa95lxUkVn2+YdMmQ/Rt2h+xN7HMFMVPh9Py2c3sxnv1hZSraTEBWp577NOVwfSKiDTOAnbLtVtLbJndZ2N/bRXzW/gpbQV6TnnsrKPJ+NQ64kCedaYoO0XvEK1JavJju4kUAw/TnJ78jBMwj0gx2kfrsAgtwGrIGhrqhGcGHwwwPPDk5lS/iVaKpSdMvxOHN/9mrAqgqmvBg9uHRKE4sUqkZWuaiAFvYF9/5sLgjQ==”}]} WechatPay::Ecommerce.request_profitsharing(params)
“`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 19 def request_profitsharing(params) url = '/v3/ecommerce/profitsharing/orders' method = 'POST' params = params.merge({ appid: WechatPay.app_id }) payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json, extra_headers: { 'Wechatpay-Serial' => WechatPay.platform_serial_no } ) end
请求补差
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_1.shtml
Example:
“` ruby WechatPay::Ecommerce.request_subsidies
(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差') “`
# File lib/wechat-pay/ecommerce/subsidies.rb, line 18 def self.request_subsidies(params) url = '/v3/ecommerce/subsidies/create' method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
垫付退款回补
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_4.shtml
Example:
“` ruby WechatPay::Ecommerce.return_advance_refund
(refund_id: '50300908092021043008398036516', sub_mchid: '160000') “`
# File lib/wechat-pay/ecommerce/refund.rb, line 93 def self.return_advance_refund(params) refund_id = params.delete(:refund_id) url = "/v3/ecommerce/refunds/#{refund_id}/return-advance" method = 'POST' make_request( path: url, method: method, for_sign: params.to_json, payload: params.to_json ) end
请求分账回退
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_3.shtml
“` ruby WechatPay::Ecommerce.return_profitsharing
(out_order_no: 'P202104306585', sub_mchid: '16000000', out_return_no: 'R20210430223', return_mchid: '180000', amount: 1, description: '分账回退') WechatPay::Ecommerce.return_profitsharing
(order_id: '3008450740201411110007820472', sub_mchid: '16000000', out_return_no: 'R20210430223', return_mchid: '180000', amount: 1, description: '分账回退') “`
# File lib/wechat-pay/ecommerce/profitsharing.rb, line 76 def return_profitsharing(params) url = '/v3/ecommerce/profitsharing/returnorders' method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
补差回退
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_2.shtml
Example:
“` ruby WechatPay::Ecommerce.return_subsidies
(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333') “`
# File lib/wechat-pay/ecommerce/subsidies.rb, line 44 def self.return_subsidies(params) url = '/v3/ecommerce/subsidies/return' method = 'POST' payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
申请交易账单
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_1.shtml
Example:
“` ruby WechatPay::Ecommerce.tradebill
(bill_date: '2021-04-30') “`
# File lib/wechat-pay/ecommerce/bill.rb, line 18 def tradebill(params) path = '/v3/bill/tradebill' method = 'GET' query = build_query(params) url = "#{path}?#{query}" make_request( path: url, method: method, extra_headers: { 'Content-Type' => 'application/x-www-form-urlencoded' } ) end
二级商户提现
Document: pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_2.shtml
Example:
“` ruby WechatPay::Ecommerce.withdraw
(sub_mchid: '160000', out_request_no: 'P10000', amount: 1) “`
# File lib/wechat-pay/ecommerce/withdraw.rb, line 18 def self.withdraw(params) url = '/v3/ecommerce/fund/withdraw' method = 'POST' make_request( method: method, path: url, for_sign: params.to_json, payload: params.to_json ) end
Private Class Methods
# File lib/wechat-pay/ecommerce/combine_order.rb, line 113 def combine_transactions_method_by_suffix(suffix, params) url = "/v3/combine-transactions/#{suffix}" method = 'POST' params = params.merge({ combine_mchid: WechatPay.mch_id, combine_appid: WechatPay.app_id }) payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end
# File lib/wechat-pay/ecommerce/order.rb, line 115 def transactions_method_by_suffix(suffix, params) url = "/v3/pay/partner/transactions/#{suffix}" method = 'POST' params = params.merge({ sp_appid: WechatPay.app_id, sp_mchid: WechatPay.mch_id }) payload_json = params.to_json make_request( method: method, path: url, for_sign: payload_json, payload: payload_json ) end