Module: WechatPay::Ecommerce

Includes:
WechatPayHelper
Defined in:
lib/wechat-pay/ecommerce.rb,
lib/wechat-pay/ecommerce/bill.rb,
lib/wechat-pay/ecommerce/order.rb,
lib/wechat-pay/ecommerce/refund.rb,
lib/wechat-pay/ecommerce/balance.rb,
lib/wechat-pay/ecommerce/withdraw.rb,
lib/wechat-pay/ecommerce/applyment.rb,
lib/wechat-pay/ecommerce/subsidies.rb,
lib/wechat-pay/ecommerce/combine_order.rb,
lib/wechat-pay/ecommerce/profitsharing.rb

Overview

分账相关

Constant Summary collapse

TRADEBILL_FIELDS =

:nodoc:

[:bill_date].freeze
FUNDFLOWBILL_FIELDS =

:nodoc:

[:bill_date].freeze
ECOMMERCE_FUNDFLOWBILL_FIELDS =

:nodoc:

%i[bill_date account_type algorithm].freeze
QUERY_ORDER_FIELDS =

:nodoc:

%i[sub_mchid out_trade_no transaction_id].freeze
CLOSE_ORDER_FIELDS =

:nodoc:

%i[sub_mchid out_trade_no].freeze
INVOKE_REFUND_FIELDS =

:nodoc:

%i[sub_mchid out_trade_no total refund out_refund_no].freeze
QUERY_REFUND_FIELDS =

:nodoc:

%i[sub_mchid refund_id out_refund_no].freeze
RETURN_ADVANCE_REFUND_FIELDS =

:nodoc:

%i[refund_id sub_mchid].freeze
QUERY_RETURN_ADVANCE_REFUND_FIELDS =

:nodoc:

%i[sub_mchid refund_id].freeze
QUERY_REALTIME_BALANCE_FIELDS =

:nodoc:

[:sub_mchid].freeze
QUERY_ENDDAY_BALANCE_FIELDS =

:nodoc:

%i[sub_mchid date].freeze
QUERY_PLATFORM_REALTIME_BALANCE_FIELDS =

:nodoc:

%i[account_type].freeze
QUERY_PLATFORM_ENDDAY_BALANCE_FIELDS =

:nodoc:

%i[account_type date].freeze
WITHDRAW_FIELDS =

:nodoc:

%i[sub_mchid out_request_no amount].freeze
QUERY_WITHDRAW_FIELDS =

:nodoc:

%i[withdraw_id out_request_no sub_mchid].freeze
PLATFORM_WITHDRAW_FIELDS =

:nodoc:

%i[out_request_no amount account_type].freeze
QUERY_PLATFORM_WITHDRAW_FIELDS =

:nodoc:

%i[withdraw_id out_request_no].freeze
DOWNLOAD_EXCEPTION_WITHDRAW_FILE =

:nodoc:

%i[bill_type bill_date].freeze
QUERY_APPLYMENT_FIELDS =

:nodoc:

%i[applyment_id out_request_no].freeze
INVOKE_QUERY_SETTLEMENT_FIELDS =

:nodoc:

[:sub_mchid].freeze
INVOKE_MODIFY_SETTLEMENT_FIELDS =

:nodoc:

%i[sub_mchid account_type account_bank bank_address_code account_number].freeze
REQUEST_SUBSIDIES_FIELDS =

:nodoc:

%i[sub_mchid transaction_id amount description].freeze
RETURN_SUBSIDIES_FIELDS =

:nodoc:

%i[sub_mchid transaction_id amount description out_order_no].freeze
CANCEL_SUBSIDIES_FIELDS =

:nodoc:

%i[sub_mchid transaction_id description].freeze
QUERY_COMBINE_ORDER_FIELDS =

:nodoc:

%i[combine_out_trade_no].freeze
CLOSE_COMBINE_ORDER_FIELDS =

:nodoc:

%i[combine_out_trade_no sub_orders].freeze
REQUEST_PROFITSHARING_FIELDS =

:nodoc:

%i[out_trade_no transaction_id sub_mchid out_order_no receivers finish].freeze
QUERY_PROFITSHARING_FIELDS =

:nodoc:

%i[out_order_no transaction_id sub_mchid].freeze
RETURN_PROFITSHARING_FIELDS =

:nodoc:

%i[sub_mchid order_id out_order_no out_return_no return_mchid amount description].freeze
QUERY_RETURN_PROFITSHARING_FIELDS =

:nodoc:

%i[sub_mchid order_id out_order_no out_return_no].freeze
FINISH_PROFITSHARING_FIELDS =

:nodoc:

%i[transaction_id sub_mchid out_order_no description].freeze
QUERY_PROFITSHARING_AMOUNT_FIELDS =

:nodoc:

%i[transaction_id].freeze
ADD_PROFITSHARING_RECEIVERS_FIELDS =

:nodoc:

%i[type account name relation_type].freeze
DELETE_PROFITSHARING_RECEIVERS_FIELDS =

:nodoc:

%i[type account].freeze

Constants included from WechatPayHelper

WechatPayHelper::GATEWAY_URL

Class Method Summary collapse

Class Method Details

.add_profitsharing_receivers(params) ⇒ Object

添加分账接收方

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_7.shtml

Example:

WechatPay::Ecommerce.add_profitsharing_receivers(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body


181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/wechat-pay/ecommerce/profitsharing.rb', line 181

def add_profitsharing_receivers(params)
  url = '/v3/ecommerce/profitsharing/receivers/add'
  method = 'POST'

  params = {
    appid: WechatPay.app_id
  }.merge(params)

  payload_json = params.to_json

  make_request(
    method: method,
    path: url,
    for_sign: payload_json,
    payload: payload_json
  )
end

.applyment(payload) ⇒ Object

二级商户进件

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_1.shtml

Example:

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": "特殊情况,说明原因"
}
WechatPay::Ecommerce.applyment(params)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

.cancel_subsidies(params) ⇒ Object

取消补差

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_3.shtml

Example:

WechatPay::Ecommerce.return_subsidies(sub_mchid: '1600000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')


70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

.certificatesObject



126
127
128
129
130
131
132
133
134
135
136
137
# 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

.close_combine_order(params) ⇒ Object

关闭合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml

WechatPay::Ecommerce.close_combine_order(combine_out_trade_no: 'C202104302474')


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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

.close_order(params) ⇒ Object

关闭订单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_6.shtml

WechatPay::Ecommerce.close_order(sub_mchid: '16000008', out_trade_no: 'N3344445')


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# 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

.delete_profitsharing_receivers(params) ⇒ Object

删除分账接收方

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_8.shtml

Example:

WechatPay::Ecommerce.remove_profitsharing_receivers(type: 'PERSONAL_OPENID', account: 'oly6s5cLmmVzzr8iPyI6mJj7qG2s', name: 'Lan', relation_type: 'DISTRIBUTOR').body


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/wechat-pay/ecommerce/profitsharing.rb', line 211

def delete_profitsharing_receivers(params)
  url = '/v3/ecommerce/profitsharing/receivers/delete'
  method = 'POST'

  params = {
    appid: WechatPay.app_id
  }.merge(params)

  payload_json = params.to_json

  make_request(
    method: method,
    path: url,
    for_sign: payload_json,
    payload: payload_json
  )
end

.download_exception_withdraw_file(params) ⇒ Object

按日下载提现异常文件

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_4.shtml

WechatPay::Ecommerce.download_exception_withdraw_file(bill_type: 'NO_SUCC', bill_date: '2021-05-10')


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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

.ecommerce_fundflowbill(params) ⇒ Object

二级商户资金账单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_5.shtml

Example:

WechatPay::Ecommerce.ecommerce_fundflowbill(bill_date: '2021-04-30', account_type: 'ALL', algorithm: 'AEAD_AES_256_GCM')


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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

.finish_profitsharing(params) ⇒ Object

完结分账

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_5.shtml

Example:

WechatPay::Ecommerce.finish_profitsharing(sub_mchid: '160000', out_order_no: 'P202104303106', transaction_id: '4323400972202104305131070133', description: '直接打款到二级商户不分账').bod


129
130
131
132
133
134
135
136
137
138
139
140
141
# 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

.fundflowbill(params) ⇒ Object

申请资金账单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_2.shtml

Example:

WechatPay::Ecommerce.fundflowbill(bill_date: '2021-04-30')


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

.invoke_combine_transactions_in_appObject

app合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_1.shtml

Example:

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_app(params)


51
# File 'lib/wechat-pay/ecommerce/combine_order.rb', line 51

define_combine_transaction_method('app', 'app', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_1.shtml')

.invoke_combine_transactions_in_h5Object

h5合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_2.shtml

Example:

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_h5(params)


49
# File 'lib/wechat-pay/ecommerce/combine_order.rb', line 49

define_combine_transaction_method('h5', 'h5', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_2.shtml')

.invoke_combine_transactions_in_jsObject

js合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_3.shtml

Example:

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_js(params)


48
# File 'lib/wechat-pay/ecommerce/combine_order.rb', line 48

define_combine_transaction_method('js', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_3.shtml')

.invoke_combine_transactions_in_miniprogramObject

miniprogram合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml

Example:

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_miniprogram(params)


52
# File 'lib/wechat-pay/ecommerce/combine_order.rb', line 52

define_combine_transaction_method('miniprogram', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml')

.invoke_combine_transactions_in_nativeObject

native合单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_5.shtml

Example:

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_native(params)


50
# File 'lib/wechat-pay/ecommerce/combine_order.rb', line 50

define_combine_transaction_method('native', 'native', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_5.shtml')

.invoke_refund(params) ⇒ Object

退款申请

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_1.shtml

Example:

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


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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 = {
    amount: amount,
    sp_appid: WechatPay.app_id
  }.merge(params)

  make_request(
    path: url,
    method: method,
    for_sign: params.to_json,
    payload: params.to_json
  )
end

.invoke_transactions_in_appObject

app下单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_1.shtml

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_app(params)


42
# File 'lib/wechat-pay/ecommerce/order.rb', line 42

define_transaction_method('app', 'app', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_1.shtml')

.invoke_transactions_in_h5Object

h5下单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_4.shtml

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_h5(params)


43
# File 'lib/wechat-pay/ecommerce/order.rb', line 43

define_transaction_method('h5', 'h5', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_4.shtml')

.invoke_transactions_in_jsObject

js下单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_2.shtml

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_js(params)


41
# File 'lib/wechat-pay/ecommerce/order.rb', line 41

define_transaction_method('js', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_2.shtml')

.invoke_transactions_in_miniprogramObject

miniprogram下单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_3.shtml

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_miniprogram(params)


44
# File 'lib/wechat-pay/ecommerce/order.rb', line 44

define_transaction_method('miniprogram', 'jsapi', 'https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_3.shtml')

.invoke_transactions_in_nativeObject

native下单

Document: document missing

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_native(params)


40
# File 'lib/wechat-pay/ecommerce/order.rb', line 40

define_transaction_method('native', 'native', 'document missing')

.media_upload(image) ⇒ Object

图片上传

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter2_1_1.shtml

Example:

WechatPay::Ecommerce.media_upload(File.open('Your Image'))


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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

.media_video_upload(video) ⇒ Object

视频上传

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter2_1_2.shtml

Example:

WechatPay::Ecommerce.media_video_upload(File.open('Your Video'))


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

.modify_settlement(params) ⇒ Object

修改结算账号

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_4.shtml

Example:

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'))


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# 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

.platform_withdraw(params) ⇒ Object

电商平台提现

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_5.shtml

Example:

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')


80
81
82
83
84
85
86
87
88
89
90
# 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

.query_applyment(params) ⇒ Object

通过商户的申请单或微信的申请单号查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_2.shtml

Example:

WechatPay::Ecommerce.query_applyment(out_request_no: 'APPLYMENT_00000000005') # by out_request_no
WechatPay::Ecommerce.query_applyment(applyment_id: '200040444455566667') # by_applyment_id


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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

.query_combine_order(params) ⇒ Object

合单查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml

WechatPay::Ecommerce.query_order(combine_out_trade_no: 'C202104302474')


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

.query_endday_balance(params) ⇒ Object

日终余额查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_2.shtml

Example:

WechatPay::Ecommerce.query_endday_balance(sub_mchid: '1600000', date: '2019-08-17')


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

.query_order(params) ⇒ Object

订单查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml

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


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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

.query_platform_endday_balance(params) ⇒ Object

平台商户日终余额

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml

Example:

WechatPay::Ecommerce.query_platform_endday_balance(account_type: 'BASIC')
WechatPay::Ecommerce.query_platform_endday_balance(account_type: 'FEES')


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/wechat-pay/ecommerce/balance.rb', line 98

def self.query_platform_endday_balance(params)
   = params.delete(:account_type)
  path = "/v3/merchant/fund/dayendbalance/#{}"
  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

.query_platform_realtime_balance(params) ⇒ Object

平台商户实时余额

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml

Example:

WechatPay::Ecommerce.query_platform_realtime_balance(account_type: 'BASIC') # basic account
WechatPay::Ecommerce.query_platform_realtime_balance(account_type: 'FEES') # fees account


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wechat-pay/ecommerce/balance.rb', line 71

def self.query_platform_realtime_balance(params)
   = params.delete(:account_type)
  url = "/v3/merchant/fund/balance/#{}"
  method = 'GET'

  make_request(
    path: url,
    method: method,
    extra_headers: {
      'Content-Type' => 'application/x-www-form-urlencoded'
    }
  )
end

.query_platform_withdraw(params) ⇒ Object

商户平台提现查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_6.shtml

Example:

WechatPay::Ecommerce.query_platform_withdraw(out_request_no: 'P1000')
WechatPay::Ecommerce.query_platform_withdraw(withdraw_id: '12313153')


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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

.query_profitsharing(params) ⇒ Object

分账结果查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_2.shtml

Example:

WechatPay::Ecommerce.query_profitsharing(out_order_no: 'N202104288345', sub_mchid: '16000000', transaction_id: '4200001048202104280183691118')


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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

.query_profitsharing_amount(params) ⇒ Object

查询订单剩余待分金额

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_9.shtml

Example:

WechatPay::Ecommerce.query_profitsharing_amount({ transaction_id: '4323400972202104301286330188' })


155
156
157
158
159
160
161
162
163
164
165
166
167
# 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

.query_realtime_balance(params) ⇒ Object

余额实时查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_1.shtml

Example:

WechatPay::Ecommerce.query_realtime_balance(sub_mchid: '1600000')


17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

.query_refund(params) ⇒ Object

退款查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_2.shtml

Example:

WechatPay::Ecommerce.query_refund(sub_mchid: '16000000', out_refund_no: 'AFS202104302474')
WechatPay::Ecommerce.query_refund(sub_mchid: '16000000', refund_id: '50000000382019052709732678859')


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# 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/ecommerce/refunds/id/#{refund_id}"
  else
    params.delete(:refund_id)
    out_refund_no = params.delete(:out_refund_no)
    path = "/v3/ecommerce/refunds/out-refund-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

.query_return_advance_refund(params) ⇒ Object

退款查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_2.shtml

Example:

WechatPay::Ecommerce.query_refund(sub_mchid: '16000000', out_refund_no: 'AFS202104302474')
WechatPay::Ecommerce.query_refund(sub_mchid: '16000000', refund_id: '50000000382019052709732678859')


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# 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

.query_return_profitsharing(params) ⇒ Object

分账回退结果查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_4.shtml

Example:

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')


102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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

.query_settlement(params) ⇒ Object

查询结算账户

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_1_5.shtml

Example:

WechatPay::Ecommerce.query_settlement(sub_mchid: '16000000')


151
152
153
154
155
156
157
158
159
160
161
162
163
# 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

.query_withdraw(params) ⇒ Object

二级商户提现查询

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml

Example:

WechatPay::Ecommerce.query_withdraw(withdraw_id: '335556', sub_mchid: '160000')
WechatPay::Ecommerce.query_withdraw(out_request_no: 'P1000', sub_mchid: '160000')


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

.request_profitsharing(params) ⇒ Object

分账请求

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_1.shtml

Example:

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)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wechat-pay/ecommerce/profitsharing.rb', line 19

def request_profitsharing(params)
  url = '/v3/ecommerce/profitsharing/orders'
  method = 'POST'
  params = {
    appid: WechatPay.app_id
  }.merge(params)

  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

.request_subsidies(params) ⇒ Object

请求补差

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_1.shtml

Example:

WechatPay::Ecommerce.request_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差')


18
19
20
21
22
23
24
25
26
27
28
29
30
# 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

.return_advance_refund(params) ⇒ Object

垫付退款回补

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_6_4.shtml

Example:

WechatPay::Ecommerce.return_advance_refund(refund_id: '50300908092021043008398036516', sub_mchid: '160000')


93
94
95
96
97
98
99
100
101
102
103
104
# 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

.return_profitsharing(params) ⇒ Object

请求分账回退

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_4_3.shtml

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: '分账回退')


76
77
78
79
80
81
82
83
84
85
86
87
88
# 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

.return_subsidies(params) ⇒ Object

补差回退

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_5_2.shtml

Example:

WechatPay::Ecommerce.return_subsidies(sub_mchid: '16000000', transaction_id: '4323400972202104305131070170', amount: 1, description: '订单补差', out_order_no: 'P103333')


44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

.tradebill(params) ⇒ Object

申请交易账单

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_9_1.shtml

Example:

WechatPay::Ecommerce.tradebill(bill_date: '2021-04-30')


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

.withdraw(params) ⇒ Object

二级商户提现

Document: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_2.shtml

Example:

WechatPay::Ecommerce.withdraw(sub_mchid: '160000', out_request_no: 'P10000', amount: 1)


18
19
20
21
22
23
24
25
26
27
28
# 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