wxpay-nodejs-sdk 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ var zlib__default = /*#__PURE__*/_interopDefault(zlib);
15
15
  // src/core/client.ts
16
16
 
17
17
  // package.json
18
- var version = "0.2.5";
18
+ var version = "0.2.6";
19
19
 
20
20
  // src/version.ts
21
21
  var SDK_VERSION = version;
@@ -1334,30 +1334,16 @@ ${packageStr}
1334
1334
  };
1335
1335
  }
1336
1336
 
1337
- // src/services/jsapi.ts
1338
- var JsapiService = class {
1337
+ // src/services/base-payment.ts
1338
+ var BasePaymentService = class {
1339
1339
  client;
1340
1340
  constructor(client) {
1341
1341
  this.client = client;
1342
1342
  }
1343
1343
  /**
1344
- * JSAPI/小程序下单
1345
- *
1346
- * 商户通过此接口生成预付单并获取 prepay_id。
1347
- * prepay_id 有效期为 2 小时,超过 2 小时需重新请求。
1348
- *
1349
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791856
1350
- */
1351
- async createOrder(request) {
1352
- return this.client.post("/v3/pay/transactions/jsapi", request);
1353
- }
1354
- /**
1355
- * 查询 JSAPI 支付订单
1344
+ * 查询订单
1356
1345
  *
1357
1346
  * 支持通过微信支付订单号或商户订单号查询订单状态。
1358
- *
1359
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791858 (微信支付订单号查询订单)
1360
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791859 (商户订单号查询订单)
1361
1347
  */
1362
1348
  async queryOrderById(params) {
1363
1349
  if (params.transactionId) {
@@ -1370,8 +1356,6 @@ var JsapiService = class {
1370
1356
  }
1371
1357
  /**
1372
1358
  * 通过商户订单号查询订单
1373
- *
1374
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791859
1375
1359
  */
1376
1360
  async queryOrderByOutTradeNo(outTradeNo) {
1377
1361
  return this.client.get(`/v3/pay/transactions/out-trade-no/${outTradeNo}`, {
@@ -1380,36 +1364,16 @@ var JsapiService = class {
1380
1364
  }
1381
1365
  /**
1382
1366
  * 通过微信支付订单号查询订单
1383
- *
1384
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791858
1385
1367
  */
1386
1368
  async queryOrderByTransactionId(transactionId) {
1387
1369
  return this.client.get(`/v3/pay/transactions/id/${transactionId}`, {
1388
1370
  mchid: this.client.mchid
1389
1371
  });
1390
1372
  }
1391
- /**
1392
- * JSAPI 下单并生成调起支付参数
1393
- *
1394
- * 封装了下单和调起支付参数生成两个步骤,一次调用即可获得
1395
- * prepay_id 和前端 WeixinJSBridge.invoke() 所需的全部参数。
1396
- *
1397
- * @param request - 下单请求参数(需包含 appid)
1398
- * @param privateKey - 商户私钥
1399
- * @returns 下单响应 + 调起支付参数
1400
- */
1401
- async prepayWithRequestPayment(request, privateKey) {
1402
- const response = await this.createOrder(request);
1403
- const bridgeConfig = buildJsapiBridgeConfig(request.appid, response.data.prepay_id, privateKey);
1404
- return { ...response, bridgeConfig };
1405
- }
1406
1373
  /**
1407
1374
  * 关闭订单
1408
1375
  *
1409
1376
  * 对于未支付的订单,商户可通过此接口关闭订单。
1410
- * 关单后,订单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
1411
- *
1412
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791860
1413
1377
  */
1414
1378
  async closeOrder(outTradeNo, request) {
1415
1379
  return this.client.post(`/v3/pay/transactions/out-trade-no/${outTradeNo}/close`, request);
@@ -1418,9 +1382,6 @@ var JsapiService = class {
1418
1382
  * 申请退款
1419
1383
  *
1420
1384
  * 当订单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
1421
- * 仅支持支付成功后 1 年内的订单。
1422
- *
1423
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791862
1424
1385
  */
1425
1386
  async createRefund(request) {
1426
1387
  return this.client.post("/v3/refund/domestic/refunds", request);
@@ -1429,20 +1390,27 @@ var JsapiService = class {
1429
1390
  * 查询退款单
1430
1391
  *
1431
1392
  * 通过商户退款单号查询退款状态。
1432
- *
1433
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791863
1434
1393
  */
1435
1394
  async queryRefund(params) {
1436
1395
  return this.client.get(
1437
1396
  `/v3/refund/domestic/refunds/${params.outRefundNo}`
1438
1397
  );
1439
1398
  }
1399
+ /**
1400
+ * 申请异常退款
1401
+ *
1402
+ * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1403
+ */
1404
+ async applyAbnormalRefund(refundId, request) {
1405
+ return this.client.post(
1406
+ `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
1407
+ request
1408
+ );
1409
+ }
1440
1410
  /**
1441
1411
  * 申请交易账单
1442
1412
  *
1443
1413
  * 商户可通过此接口获取交易账单的下载链接。
1444
- *
1445
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791866
1446
1414
  */
1447
1415
  async tradeBill(params) {
1448
1416
  return this.client.get("/v3/bill/tradebill", params);
@@ -1451,49 +1419,52 @@ var JsapiService = class {
1451
1419
  * 申请资金账单
1452
1420
  *
1453
1421
  * 商户可通过此接口获取资金账单的下载链接。
1454
- *
1455
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791867
1456
1422
  */
1457
1423
  async fundFlowBill(params) {
1458
1424
  return this.client.get("/v3/bill/fundflowbill", params);
1459
1425
  }
1460
1426
  /**
1461
- * 申请异常退款
1427
+ * 下载账单
1462
1428
  *
1463
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1464
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
1429
+ * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
1430
+ */
1431
+ async downloadBill(downloadUrl) {
1432
+ return this.client.downloadRaw(downloadUrl);
1433
+ }
1434
+ };
1435
+
1436
+ // src/services/jsapi.ts
1437
+ var JsapiService = class extends BasePaymentService {
1438
+ /**
1439
+ * JSAPI/小程序下单
1465
1440
  *
1466
- * @param refundId - 微信支付退款单号
1467
- * @param request - 异常退款请求参数
1468
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791864
1441
+ * 商户通过此接口生成预付单并获取 prepay_id。
1442
+ * prepay_id 有效期为 2 小时,超过 2 小时需重新请求。
1443
+ *
1444
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791856
1469
1445
  */
1470
- async applyAbnormalRefund(refundId, request) {
1471
- return this.client.post(
1472
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
1473
- request
1474
- );
1446
+ async createOrder(request) {
1447
+ return this.client.post("/v3/pay/transactions/jsapi", request);
1475
1448
  }
1476
1449
  /**
1477
- * 下载账单
1450
+ * JSAPI 下单并生成调起支付参数
1478
1451
  *
1479
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
1480
- * 下载地址 5 分钟内有效,请及时下载。
1481
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
1452
+ * 封装了下单和调起支付参数生成两个步骤,一次调用即可获得
1453
+ * prepay_id 和前端 WeixinJSBridge.invoke() 所需的全部参数。
1482
1454
  *
1483
- * @param downloadUrl - 申请账单返回的 download_url
1484
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791868
1455
+ * @param request - 下单请求参数(需包含 appid)
1456
+ * @param privateKey - 商户私钥
1457
+ * @returns 下单响应 + 调起支付参数
1485
1458
  */
1486
- async downloadBill(downloadUrl) {
1487
- return this.client.downloadRaw(downloadUrl);
1459
+ async prepayWithRequestPayment(request, privateKey) {
1460
+ const response = await this.createOrder(request);
1461
+ const bridgeConfig = buildJsapiBridgeConfig(request.appid, response.data.prepay_id, privateKey);
1462
+ return { ...response, bridgeConfig };
1488
1463
  }
1489
1464
  };
1490
1465
 
1491
1466
  // src/services/h5.ts
1492
- var H5Service = class {
1493
- client;
1494
- constructor(client) {
1495
- this.client = client;
1496
- }
1467
+ var H5Service = class extends BasePaymentService {
1497
1468
  /**
1498
1469
  * H5 支付下单
1499
1470
  *
@@ -1505,51 +1476,92 @@ var H5Service = class {
1505
1476
  async createOrder(request) {
1506
1477
  return this.client.post("/v3/pay/transactions/h5", request);
1507
1478
  }
1479
+ };
1480
+
1481
+ // src/services/app.ts
1482
+ var AppService = class extends BasePaymentService {
1508
1483
  /**
1509
- * 查询订单
1484
+ * APP 支付下单
1510
1485
  *
1511
- * 支持通过微信支付订单号或商户订单号查询订单状态。
1486
+ * 商户通过此接口生成预付单并获取 prepay_id。
1487
+ * prepay_id 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1512
1488
  *
1513
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791837 (微信支付订单号查询订单)
1514
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791838 (商户订单号查询订单)
1489
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070347
1515
1490
  */
1516
- async queryOrderById(params) {
1517
- if (params.transactionId) {
1518
- return this.queryOrderByTransactionId(params.transactionId);
1519
- }
1520
- if (params.outTradeNo) {
1521
- return this.queryOrderByOutTradeNo(params.outTradeNo);
1522
- }
1523
- throw new Error("outTradeNo \u6216 transactionId \u5FC5\u987B\u63D0\u4F9B\u5176\u4E2D\u4E00\u4E2A");
1491
+ async createOrder(request) {
1492
+ return this.client.post("/v3/pay/transactions/app", request);
1524
1493
  }
1525
- async queryOrderByOutTradeNo(outTradeNo) {
1526
- return this.client.get(`/v3/pay/transactions/out-trade-no/${outTradeNo}`, {
1527
- mchid: this.client.mchid
1528
- });
1494
+ /**
1495
+ * APP 下单并生成调起支付参数
1496
+ *
1497
+ * 封装了下单和调起支付参数生成两个步骤,一次调用即可获得
1498
+ * prepay_id 和 APP 端调起支付所需的全部参数。
1499
+ *
1500
+ * @param request - 下单请求参数(需包含 appid)
1501
+ * @param privateKey - 商户私钥
1502
+ * @returns 下单响应 + 调起支付参数
1503
+ */
1504
+ async prepayWithRequestPayment(request, privateKey) {
1505
+ const response = await this.createOrder(request);
1506
+ const bridgeConfig = buildAppBridgeConfig(
1507
+ request.appid,
1508
+ this.client.mchid,
1509
+ response.data.prepay_id,
1510
+ privateKey
1511
+ );
1512
+ return { ...response, bridgeConfig };
1529
1513
  }
1530
- async queryOrderByTransactionId(transactionId) {
1531
- return this.client.get(`/v3/pay/transactions/id/${transactionId}`, {
1532
- mchid: this.client.mchid
1533
- });
1514
+ };
1515
+
1516
+ // src/services/native.ts
1517
+ var NativeService = class extends BasePaymentService {
1518
+ /**
1519
+ * Native 支付下单
1520
+ *
1521
+ * 商户通过此接口生成订单并获取二维码链接(code_url)。
1522
+ * code_url 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1523
+ *
1524
+ * 商户后端获取 code_url 后传递给前端,前端将其转换为二维码图片展示给用户。
1525
+ * 用户使用微信扫一扫扫描二维码后,将调起微信收银台完成支付。
1526
+ *
1527
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791877
1528
+ */
1529
+ async createOrder(request) {
1530
+ return this.client.post("/v3/pay/transactions/native", request);
1531
+ }
1532
+ };
1533
+
1534
+ // src/services/base-combine.ts
1535
+ var BaseCombineService = class {
1536
+ client;
1537
+ constructor(client) {
1538
+ this.client = client;
1534
1539
  }
1535
1540
  /**
1536
- * 关闭订单
1541
+ * 查询合单订单
1537
1542
  *
1538
- * 对于未支付的订单,商户可通过此接口关闭订单。
1539
- * 关单后,订单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
1543
+ * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
1544
+ */
1545
+ async queryOrderById(params) {
1546
+ return this.client.get(
1547
+ `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
1548
+ );
1549
+ }
1550
+ /**
1551
+ * 关闭合单订单
1540
1552
  *
1541
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791839
1553
+ * 对于未支付的合单订单,商户可通过此接口关闭订单。
1542
1554
  */
1543
- async closeOrder(outTradeNo, request) {
1544
- return this.client.post(`/v3/pay/transactions/out-trade-no/${outTradeNo}/close`, request);
1555
+ async closeOrder(params, request) {
1556
+ return this.client.post(
1557
+ `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
1558
+ request
1559
+ );
1545
1560
  }
1546
1561
  /**
1547
1562
  * 申请退款
1548
1563
  *
1549
- * 当订单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
1550
- * 仅支持支付成功后 1 年内的订单。
1551
- *
1552
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810597
1564
+ * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口对子单申请退款。
1553
1565
  */
1554
1566
  async createRefund(request) {
1555
1567
  return this.client.post("/v3/refund/domestic/refunds", request);
@@ -1558,8 +1570,6 @@ var H5Service = class {
1558
1570
  * 查询退款单
1559
1571
  *
1560
1572
  * 通过商户退款单号查询退款状态。
1561
- *
1562
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810601
1563
1573
  */
1564
1574
  async queryRefund(params) {
1565
1575
  return this.client.get(
@@ -1570,11 +1580,6 @@ var H5Service = class {
1570
1580
  * 申请异常退款
1571
1581
  *
1572
1582
  * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1573
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
1574
- *
1575
- * @param refundId - 微信支付退款单号
1576
- * @param request - 异常退款请求参数
1577
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810603
1578
1583
  */
1579
1584
  async applyAbnormalRefund(refundId, request) {
1580
1585
  return this.client.post(
@@ -1586,8 +1591,6 @@ var H5Service = class {
1586
1591
  * 申请交易账单
1587
1592
  *
1588
1593
  * 商户可通过此接口获取交易账单的下载链接。
1589
- *
1590
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810606
1591
1594
  */
1592
1595
  async tradeBill(params) {
1593
1596
  return this.client.get("/v3/bill/tradebill", params);
@@ -1596,8 +1599,6 @@ var H5Service = class {
1596
1599
  * 申请资金账单
1597
1600
  *
1598
1601
  * 商户可通过此接口获取资金账单的下载链接。
1599
- *
1600
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810609
1601
1602
  */
1602
1603
  async fundFlowBill(params) {
1603
1604
  return this.client.get("/v3/bill/fundflowbill", params);
@@ -1606,526 +1607,61 @@ var H5Service = class {
1606
1607
  * 下载账单
1607
1608
  *
1608
1609
  * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
1609
- * 下载地址 5 分钟内有效,请及时下载。
1610
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
1611
- *
1612
- * @param downloadUrl - 申请账单返回的 download_url
1613
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012810615
1614
1610
  */
1615
1611
  async downloadBill(downloadUrl) {
1616
1612
  return this.client.downloadRaw(downloadUrl);
1617
1613
  }
1618
1614
  };
1619
1615
 
1620
- // src/services/app.ts
1621
- var AppService = class {
1622
- client;
1623
- constructor(client) {
1624
- this.client = client;
1625
- }
1616
+ // src/services/combine.ts
1617
+ var CombineService = class extends BaseCombineService {
1626
1618
  /**
1627
- * APP 支付下单
1619
+ * JSAPI 合单下单
1628
1620
  *
1629
- * 商户通过此接口生成预付单并获取 prepay_id。
1621
+ * 商户通过此接口生成合单预付单并获取 prepay_id。
1630
1622
  * prepay_id 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1631
1623
  *
1632
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070347
1624
+ * 关键约束:
1625
+ * - combine_mchid 需先申请发起合单支付权限
1626
+ * - sub_orders 中的 mchid 需先申请接收合单支付权限
1627
+ * - 合单发起方和子单参与方需绑定同一个 combine_appid
1628
+ * - 子单数量为 2-10 笔
1629
+ * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
1630
+ *
1631
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556926
1633
1632
  */
1634
1633
  async createOrder(request) {
1635
- return this.client.post("/v3/pay/transactions/app", request);
1634
+ return this.client.post("/v3/combine-transactions/jsapi", request);
1636
1635
  }
1636
+ };
1637
+
1638
+ // src/services/combine-h5.ts
1639
+ var CombineH5Service = class extends BaseCombineService {
1637
1640
  /**
1638
- * 查询订单
1641
+ * H5 合单下单
1639
1642
  *
1640
- * 支持通过微信支付订单号或商户订单号查询订单状态。
1643
+ * 商户通过此接口生成 H5 合单支付链接(h5_url),用于在已配置 H5 支付域名的
1644
+ * 网页中跳转并唤起微信支付收银台。h5_url 有效期为 5 分钟,过期后需使用
1645
+ * 原下单参数重新请求。
1646
+ *
1647
+ * 关键约束:
1648
+ * - combine_mchid 需先申请发起合单支付权限
1649
+ * - sub_orders 中的 mchid 需先申请接收合单支付权限
1650
+ * - 合单发起方和子单参与方需绑定同一个 combine_appid
1651
+ * - 子单数量为 2-10 笔
1652
+ * - scene_info.payer_client_ip 需传真实的用户端 IP
1653
+ * - scene_info.h5_info 必填,需指定 type 为 Wap/iOS/Android 之一
1654
+ * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
1641
1655
  *
1642
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070354 (微信支付订单号查询订单)
1643
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070356 (商户订单号查询订单)
1656
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556961
1644
1657
  */
1645
- async queryOrderById(params) {
1646
- if (params.transactionId) {
1647
- return this.queryOrderByTransactionId(params.transactionId);
1648
- }
1649
- if (params.outTradeNo) {
1650
- return this.queryOrderByOutTradeNo(params.outTradeNo);
1651
- }
1652
- throw new Error("outTradeNo \u6216 transactionId \u5FC5\u987B\u63D0\u4F9B\u5176\u4E2D\u4E00\u4E2A");
1653
- }
1654
- async queryOrderByOutTradeNo(outTradeNo) {
1655
- return this.client.get(`/v3/pay/transactions/out-trade-no/${outTradeNo}`, {
1656
- mchid: this.client.mchid
1657
- });
1658
- }
1659
- async queryOrderByTransactionId(transactionId) {
1660
- return this.client.get(`/v3/pay/transactions/id/${transactionId}`, {
1661
- mchid: this.client.mchid
1662
- });
1663
- }
1664
- async prepayWithRequestPayment(request, privateKey) {
1665
- const response = await this.createOrder(request);
1666
- const bridgeConfig = buildAppBridgeConfig(
1667
- request.appid,
1668
- this.client.mchid,
1669
- response.data.prepay_id,
1670
- privateKey
1671
- );
1672
- return { ...response, bridgeConfig };
1673
- }
1674
- /**
1675
- * 关闭订单
1676
- *
1677
- * 对于未支付的订单,商户可通过此接口关闭订单。
1678
- * 关单后,订单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
1679
- *
1680
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070360
1681
- */
1682
- async closeOrder(outTradeNo, request) {
1683
- return this.client.post(`/v3/pay/transactions/out-trade-no/${outTradeNo}/close`, request);
1684
- }
1685
- /**
1686
- * 申请退款
1687
- *
1688
- * 当订单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
1689
- * 仅支持支付成功后 1 年内的订单。
1690
- *
1691
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070371
1692
- */
1693
- async createRefund(request) {
1694
- return this.client.post("/v3/refund/domestic/refunds", request);
1695
- }
1696
- /**
1697
- * 查询退款单
1698
- *
1699
- * 通过商户退款单号查询退款状态。
1700
- *
1701
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070374
1702
- */
1703
- async queryRefund(params) {
1704
- return this.client.get(
1705
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
1706
- );
1707
- }
1708
- /**
1709
- * 申请异常退款
1710
- *
1711
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1712
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
1713
- *
1714
- * @param refundId - 微信支付退款单号
1715
- * @param request - 异常退款请求参数
1716
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070379
1717
- */
1718
- async applyAbnormalRefund(refundId, request) {
1719
- return this.client.post(
1720
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
1721
- request
1722
- );
1723
- }
1724
- /**
1725
- * 申请交易账单
1726
- *
1727
- * 商户可通过此接口获取交易账单的下载链接。
1728
- *
1729
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070395
1730
- */
1731
- async tradeBill(params) {
1732
- return this.client.get("/v3/bill/tradebill", params);
1733
- }
1734
- /**
1735
- * 申请资金账单
1736
- *
1737
- * 商户可通过此接口获取资金账单的下载链接。
1738
- *
1739
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070400
1740
- */
1741
- async fundFlowBill(params) {
1742
- return this.client.get("/v3/bill/fundflowbill", params);
1743
- }
1744
- /**
1745
- * 下载账单
1746
- *
1747
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
1748
- * 下载地址 5 分钟内有效,请及时下载。
1749
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
1750
- *
1751
- * @param downloadUrl - 申请账单返回的 download_url
1752
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013070401
1753
- */
1754
- async downloadBill(downloadUrl) {
1755
- return this.client.downloadRaw(downloadUrl);
1756
- }
1757
- };
1758
-
1759
- // src/services/native.ts
1760
- var NativeService = class {
1761
- client;
1762
- constructor(client) {
1763
- this.client = client;
1764
- }
1765
- /**
1766
- * Native 支付下单
1767
- *
1768
- * 商户通过此接口生成订单并获取二维码链接(code_url)。
1769
- * code_url 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1770
- *
1771
- * 商户后端获取 code_url 后传递给前端,前端将其转换为二维码图片展示给用户。
1772
- * 用户使用微信扫一扫扫描二维码后,将调起微信收银台完成支付。
1773
- *
1774
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791877
1775
- */
1776
- async createOrder(request) {
1777
- return this.client.post("/v3/pay/transactions/native", request);
1778
- }
1779
- /**
1780
- * 查询订单
1781
- *
1782
- * 支持通过微信支付订单号或商户订单号查询订单状态。
1783
- *
1784
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791879 (微信支付订单号查询订单)
1785
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791880 (商户订单号查询订单)
1786
- */
1787
- async queryOrderById(params) {
1788
- if (params.transactionId) {
1789
- return this.queryOrderByTransactionId(params.transactionId);
1790
- }
1791
- if (params.outTradeNo) {
1792
- return this.queryOrderByOutTradeNo(params.outTradeNo);
1793
- }
1794
- throw new Error("outTradeNo \u6216 transactionId \u5FC5\u987B\u63D0\u4F9B\u5176\u4E2D\u4E00\u4E2A");
1795
- }
1796
- async queryOrderByOutTradeNo(outTradeNo) {
1797
- return this.client.get(`/v3/pay/transactions/out-trade-no/${outTradeNo}`, {
1798
- mchid: this.client.mchid
1799
- });
1800
- }
1801
- async queryOrderByTransactionId(transactionId) {
1802
- return this.client.get(`/v3/pay/transactions/id/${transactionId}`, {
1803
- mchid: this.client.mchid
1804
- });
1805
- }
1806
- /**
1807
- * 关闭订单
1808
- *
1809
- * 对于未支付的订单,商户可通过此接口关闭订单。
1810
- * 关单后,订单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
1811
- *
1812
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791881
1813
- */
1814
- async closeOrder(outTradeNo, request) {
1815
- return this.client.post(`/v3/pay/transactions/out-trade-no/${outTradeNo}/close`, request);
1816
- }
1817
- /**
1818
- * 申请退款
1819
- *
1820
- * 当订单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
1821
- * 仅支持支付成功后 1 年内的订单。
1822
- *
1823
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791883
1824
- */
1825
- async createRefund(request) {
1826
- return this.client.post("/v3/refund/domestic/refunds", request);
1827
- }
1828
- /**
1829
- * 查询退款单
1830
- *
1831
- * 通过商户退款单号查询退款状态。
1832
- *
1833
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791884
1834
- */
1835
- async queryRefund(params) {
1836
- return this.client.get(
1837
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
1838
- );
1839
- }
1840
- /**
1841
- * 申请异常退款
1842
- *
1843
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1844
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
1845
- *
1846
- * @param refundId - 微信支付退款单号
1847
- * @param request - 异常退款请求参数
1848
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791885
1849
- */
1850
- async applyAbnormalRefund(refundId, request) {
1851
- return this.client.post(
1852
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
1853
- request
1854
- );
1855
- }
1856
- /**
1857
- * 申请交易账单
1858
- *
1859
- * 商户可通过此接口获取交易账单的下载链接。
1860
- *
1861
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791887
1862
- */
1863
- async tradeBill(params) {
1864
- return this.client.get("/v3/bill/tradebill", params);
1865
- }
1866
- /**
1867
- * 申请资金账单
1868
- *
1869
- * 商户可通过此接口获取资金账单的下载链接。
1870
- *
1871
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791888
1872
- */
1873
- async fundFlowBill(params) {
1874
- return this.client.get("/v3/bill/fundflowbill", params);
1875
- }
1876
- /**
1877
- * 下载账单
1878
- *
1879
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
1880
- * 下载地址 5 分钟内有效,请及时下载。
1881
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
1882
- *
1883
- * @param downloadUrl - 申请账单返回的 download_url
1884
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012791889
1885
- */
1886
- async downloadBill(downloadUrl) {
1887
- return this.client.downloadRaw(downloadUrl);
1888
- }
1889
- };
1890
-
1891
- // src/services/combine.ts
1892
- var CombineService = class {
1893
- client;
1894
- constructor(client) {
1895
- this.client = client;
1896
- }
1897
- /**
1898
- * JSAPI 合单下单
1899
- *
1900
- * 商户通过此接口生成合单预付单并获取 prepay_id。
1901
- * prepay_id 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1902
- *
1903
- * 关键约束:
1904
- * - combine_mchid 需先申请发起合单支付权限
1905
- * - sub_orders 中的 mchid 需先申请接收合单支付权限
1906
- * - 合单发起方和子单参与方需绑定同一个 combine_appid
1907
- * - 子单数量为 2-10 笔
1908
- * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
1909
- *
1910
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556926
1911
- */
1912
- async createOrder(request) {
1913
- return this.client.post("/v3/combine-transactions/jsapi", request);
1914
- }
1915
- /**
1916
- * 查询合单订单
1917
- *
1918
- * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
1919
- *
1920
- * 订单状态(sub_orders[].trade_state):
1921
- * - SUCCESS:支付成功(终态)
1922
- * - NOTPAY:未支付
1923
- * - CLOSED:已关闭(终态)
1924
- *
1925
- * 注意:请勿使用非合单支付的查单接口查询合单订单。
1926
- *
1927
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421222
1928
- */
1929
- async queryOrderById(params) {
1930
- return this.client.get(
1931
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
1932
- );
1933
- }
1934
- /**
1935
- * 关闭合单订单
1936
- *
1937
- * 对于未支付的合单订单,商户可通过此接口关闭订单。
1938
- * 关单后,所有子单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
1939
- *
1940
- * 关键约束:
1941
- * - 只能整单关闭,不支持关闭部分子单
1942
- * - combine_appid、sub_orders 中的 mchid 和 out_trade_no 必须与下单时完全一致
1943
- * - 仅支持未支付状态的订单
1944
- *
1945
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421225
1946
- */
1947
- async closeOrder(params, request) {
1948
- return this.client.post(
1949
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
1950
- request
1951
- );
1952
- }
1953
- /**
1954
- * 申请退款
1955
- *
1956
- * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口对子单申请退款。
1957
- * 仅支持支付成功后 1 年内的订单。
1958
- *
1959
- * 注意:合单支付的订单无法通过合单总单号 combine_out_trade_no 退款,
1960
- * 需要传入子单的 transaction_id 或 out_trade_no。
1961
- *
1962
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421249
1963
- */
1964
- async createRefund(request) {
1965
- return this.client.post("/v3/refund/domestic/refunds", request);
1966
- }
1967
- /**
1968
- * 查询退款单
1969
- *
1970
- * 通过商户退款单号查询退款状态。
1971
- *
1972
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421261
1973
- */
1974
- async queryRefund(params) {
1975
- return this.client.get(
1976
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
1977
- );
1978
- }
1979
- /**
1980
- * 申请异常退款
1981
- *
1982
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
1983
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
1984
- *
1985
- * @param refundId - 微信支付退款单号
1986
- * @param request - 异常退款请求参数
1987
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421269
1988
- */
1989
- async applyAbnormalRefund(refundId, request) {
1990
- return this.client.post(
1991
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
1992
- request
1993
- );
1994
- }
1995
- };
1996
-
1997
- // src/services/combine-h5.ts
1998
- var CombineH5Service = class {
1999
- client;
2000
- constructor(client) {
2001
- this.client = client;
2002
- }
2003
- /**
2004
- * H5 合单下单
2005
- *
2006
- * 商户通过此接口生成 H5 合单支付链接(h5_url),用于在已配置 H5 支付域名的
2007
- * 网页中跳转并唤起微信支付收银台。h5_url 有效期为 5 分钟,过期后需使用
2008
- * 原下单参数重新请求。
2009
- *
2010
- * 关键约束:
2011
- * - combine_mchid 需先申请发起合单支付权限
2012
- * - sub_orders 中的 mchid 需先申请接收合单支付权限
2013
- * - 合单发起方和子单参与方需绑定同一个 combine_appid
2014
- * - 子单数量为 2-10 笔
2015
- * - scene_info.payer_client_ip 需传真实的用户端 IP
2016
- * - scene_info.h5_info 必填,需指定 type 为 Wap/iOS/Android 之一
2017
- * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
2018
- *
2019
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556961
2020
- */
2021
- async createOrder(request) {
2022
- return this.client.post("/v3/combine-transactions/h5", request);
2023
- }
2024
- /**
2025
- * 查询合单订单
2026
- *
2027
- * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
2028
- * 合单支付订单需使用合单查单接口,不可使用非合单支付的查单接口。
2029
- *
2030
- * 订单状态(sub_orders[].trade_state):
2031
- * - SUCCESS:支付成功(终态)
2032
- * - NOTPAY:未支付
2033
- * - CLOSED:已关闭(终态)
2034
- *
2035
- * 典型使用场景:
2036
- * - 用户支付后从收银台返回商户页面时,确认订单支付状态
2037
- * - 未收到支付成功回调通知时,主动查询确认订单状态
2038
- * - 关单前确认订单仍为未支付状态
2039
- *
2040
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421126
2041
- */
2042
- async queryOrderById(params) {
2043
- return this.client.get(
2044
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
2045
- );
2046
- }
2047
- /**
2048
- * 关闭合单订单
2049
- *
2050
- * 对于未支付的合单订单,商户可通过此接口关闭订单。
2051
- * 关单后,所有子单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
2052
- *
2053
- * 关键约束:
2054
- * - 只能整单关闭,不支持关闭部分子单
2055
- * - combine_appid、sub_orders 中的 mchid 和 out_trade_no 必须与下单时完全一致
2056
- * - 仅支持未支付状态的订单
2057
- * - 关单后订单为失败终态
2058
- *
2059
- * 典型使用场景:
2060
- * - 用户超过商户系统内部规定的支付时间
2061
- * - 超过下单时设置的 time_expire 时间
2062
- * - 因特殊原因需在可支付时间范围内关闭订单
2063
- *
2064
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421130
2065
- */
2066
- async closeOrder(params, request) {
2067
- return this.client.post(
2068
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
2069
- request
2070
- );
2071
- }
2072
- /**
2073
- * 申请退款(基于子单)
2074
- *
2075
- * 合单支付的订单退款,无法通过合单商户订单号(combine_out_trade_no)退款,
2076
- * 只能根据单个子单进行退款。传入子单的 out_trade_no 或 transaction_id。
2077
- *
2078
- * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
2079
- * 仅支持支付成功后 1 年内的订单。
2080
- *
2081
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421148
2082
- */
2083
- async createRefund(request) {
2084
- return this.client.post("/v3/refund/domestic/refunds", request);
2085
- }
2086
- /**
2087
- * 查询退款单
2088
- *
2089
- * 通过商户退款单号查询退款状态。
2090
- * 退款申请成功后,可通过此接口确认退款是否到账。
2091
- *
2092
- * 退款状态:
2093
- * - SUCCESS:退款成功
2094
- * - CLOSED:退款关闭
2095
- * - PROCESSING:退款处理中
2096
- * - ABNORMAL:退款异常
2097
- *
2098
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421156
2099
- */
2100
- async queryRefund(params) {
2101
- return this.client.get(
2102
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
2103
- );
2104
- }
2105
- /**
2106
- * 申请异常退款
2107
- *
2108
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
2109
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
2110
- *
2111
- * @param refundId - 微信支付退款单号
2112
- * @param request - 异常退款请求参数
2113
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421164
2114
- */
2115
- async applyAbnormalRefund(refundId, request) {
2116
- return this.client.post(
2117
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
2118
- request
2119
- );
1658
+ async createOrder(request) {
1659
+ return this.client.post("/v3/combine-transactions/h5", request);
2120
1660
  }
2121
1661
  };
2122
1662
 
2123
1663
  // src/services/combine-app.ts
2124
- var CombineAppService = class {
2125
- client;
2126
- constructor(client) {
2127
- this.client = client;
2128
- }
1664
+ var CombineAppService = class extends BaseCombineService {
2129
1665
  /**
2130
1666
  * APP 合单下单
2131
1667
  *
@@ -2143,329 +1679,45 @@ var CombineAppService = class {
2143
1679
  * - 子单数量为 2-10 笔
2144
1680
  * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
2145
1681
  *
2146
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556944
2147
- */
2148
- async createOrder(request) {
2149
- return this.client.post("/v3/combine-transactions/app", request);
2150
- }
2151
- /**
2152
- * 查询合单订单
2153
- *
2154
- * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
2155
- * 合单支付订单需使用合单查单接口,不可使用非合单支付的查单接口。
2156
- *
2157
- * 订单状态(sub_orders[].trade_state):
2158
- * - SUCCESS:支付成功(终态)
2159
- * - NOTPAY:未支付
2160
- * - CLOSED:已关闭(终态)
2161
- *
2162
- * 典型使用场景:
2163
- * - 用户支付后从微信收银台返回商户 APP 时,OpenSDK 回调 onResp 后确认订单支付状态
2164
- * - 未收到支付成功回调通知时,主动查询确认订单状态
2165
- * - 关单前确认订单仍为未支付状态
2166
- *
2167
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012557006
2168
- */
2169
- async queryOrderById(params) {
2170
- return this.client.get(
2171
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
2172
- );
2173
- }
2174
- /**
2175
- * 关闭合单订单
2176
- *
2177
- * 对于未支付的合单订单,商户可通过此接口关闭订单。
2178
- * 关单后,所有子单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
2179
- *
2180
- * 关键约束:
2181
- * - 只能整单关闭,不支持关闭部分子单
2182
- * - combine_appid、sub_orders 中的 mchid 和 out_trade_no 必须与下单时完全一致
2183
- * - 仅支持未支付状态的订单
2184
- * - 关单后订单为失败终态
2185
- *
2186
- * 典型使用场景:
2187
- * - 用户超过商户系统内部规定的支付时间
2188
- * - 超过下单时设置的 time_expire 时间
2189
- * - 因特殊原因需在可支付时间范围内关闭订单
2190
- *
2191
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012577452
2192
- */
2193
- async closeOrder(params, request) {
2194
- return this.client.post(
2195
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
2196
- request
2197
- );
2198
- }
2199
- /**
2200
- * 申请退款(基于子单)
2201
- *
2202
- * 合单支付的订单退款,无法通过合单商户订单号(combine_out_trade_no)退款,
2203
- * 只能根据单个子单进行退款。传入子单的 out_trade_no 或 transaction_id。
2204
- *
2205
- * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
2206
- * 仅支持支付成功后 1 年内的订单。
2207
- *
2208
- * 注意:
2209
- * - 一笔订单最多支持 50 次部分退款,间隔至少 1 分钟
2210
- * - 重试时必须使用原商户退款单号,避免重复退款
2211
- * - 接口返回成功仅表示受理成功,最终结果以回调通知和查询接口为准
2212
- *
2213
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556524
2214
- */
2215
- async createRefund(request) {
2216
- return this.client.post("/v3/refund/domestic/refunds", request);
2217
- }
2218
- /**
2219
- * 查询退款单
2220
- *
2221
- * 通过商户退款单号查询退款状态。
2222
- * 退款申请成功后,可通过此接口确认退款是否到账。
2223
- *
2224
- * 退款状态:
2225
- * - SUCCESS:退款成功
2226
- * - CLOSED:退款关闭
2227
- * - PROCESSING:退款处理中
2228
- * - ABNORMAL:退款异常
2229
- *
2230
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556587
2231
- */
2232
- async queryRefund(params) {
2233
- return this.client.get(
2234
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
2235
- );
2236
- }
2237
- /**
2238
- * 申请异常退款
2239
- *
2240
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
2241
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
2242
- *
2243
- * @param refundId - 微信支付退款单号
2244
- * @param request - 异常退款请求参数
2245
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013420988
2246
- */
2247
- async applyAbnormalRefund(refundId, request) {
2248
- return this.client.post(
2249
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
2250
- request
2251
- );
2252
- }
2253
- /**
2254
- * 申请交易账单
2255
- *
2256
- * 合单支付的订单账单是以子单为维度,每笔子单都会记录在各个子单商户账单内,
2257
- * 需要各个子单商户自己进行下载。
2258
- *
2259
- * 商户可通过此接口获取交易账单的下载链接,下载地址 5 分钟内有效。
2260
- *
2261
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556692
2262
- */
2263
- async tradeBill(params) {
2264
- return this.client.get("/v3/bill/tradebill", params);
2265
- }
2266
- /**
2267
- * 申请资金账单
2268
- *
2269
- * 商户可通过此接口获取资金账单的下载链接,下载地址 5 分钟内有效。
2270
- *
2271
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556748
2272
- */
2273
- async fundFlowBill(params) {
2274
- return this.client.get("/v3/bill/fundflowbill", params);
2275
- }
2276
- /**
2277
- * 下载账单
2278
- *
2279
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
2280
- * 下载地址 5 分钟内有效,请及时下载。
2281
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
2282
- *
2283
- * @param downloadUrl - 申请账单返回的 download_url
2284
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012085923
2285
- */
2286
- async downloadBill(downloadUrl) {
2287
- return this.client.downloadRaw(downloadUrl);
2288
- }
2289
- };
2290
-
2291
- // src/services/combine-miniprogram.ts
2292
- var CombineMiniProgramService = class {
2293
- client;
2294
- constructor(client) {
2295
- this.client = client;
2296
- }
2297
- /**
2298
- * 小程序合单下单
2299
- *
2300
- * 商户通过此接口生成小程序合单预付单并获取 prepay_id。
2301
- * 获取 prepay_id 后,配合 buildMiniProgramBridgeConfig 生成调起支付参数,
2302
- * 通过小程序 wx.requestPayment() 方法唤起微信支付收银台。
2303
- *
2304
- * prepay_id 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
2305
- *
2306
- * 关键约束:
2307
- * - combine_mchid 需先申请发起合单支付权限
2308
- * - sub_orders 中的 mchid 需先申请接收合单支付权限
2309
- * - 合单发起方和子单参与方需绑定同一个 combine_appid
2310
- * - combine_appid 必须为小程序 AppID
2311
- * - combine_payer_info.openid 在小程序场景下可选(由运行环境隐式提供)
2312
- * - 子单数量为 2-10 笔
2313
- * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
2314
- *
2315
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556931
2316
- */
2317
- async createOrder(request) {
2318
- return this.client.post(
2319
- "/v3/combine-transactions/jsapi",
2320
- request
2321
- );
2322
- }
2323
- /**
2324
- * 查询合单订单
2325
- *
2326
- * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
2327
- * 合单支付订单需使用合单查单接口,不可使用非合单支付的查单接口。
2328
- *
2329
- * 订单状态(sub_orders[].trade_state):
2330
- * - SUCCESS:支付成功(终态)
2331
- * - NOTPAY:未支付
2332
- * - CLOSED:已关闭(终态)
2333
- *
2334
- * 典型使用场景:
2335
- * - 用户支付后从收银台返回小程序页面时,requestPayment 回调后确认订单支付状态
2336
- * - 未收到支付成功回调通知时,主动查询确认订单状态
2337
- * - 关单前确认订单仍为未支付状态
2338
- *
2339
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421401
2340
- */
2341
- async queryOrderById(params) {
2342
- return this.client.get(
2343
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
2344
- );
2345
- }
2346
- /**
2347
- * 关闭合单订单
2348
- *
2349
- * 对于未支付的合单订单,商户可通过此接口关闭订单。
2350
- * 关单后,所有子单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
2351
- *
2352
- * 关键约束:
2353
- * - 只能整单关闭,不支持关闭部分子单
2354
- * - combine_appid、sub_orders 中的 mchid 和 out_trade_no 必须与下单时完全一致
2355
- * - 仅支持未支付状态的订单
2356
- * - 关单后订单为失败终态
2357
- *
2358
- * 典型使用场景:
2359
- * - 用户超过商户系统内部规定的支付时间
2360
- * - 超过下单时设置的 time_expire 时间
2361
- * - 因特殊原因需在可支付时间范围内关闭订单
2362
- *
2363
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421404
2364
- */
2365
- async closeOrder(params, request) {
2366
- return this.client.post(
2367
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
2368
- request
2369
- );
2370
- }
2371
- /**
2372
- * 申请退款(基于子单)
2373
- *
2374
- * 合单支付的订单退款,无法通过合单商户订单号(combine_out_trade_no)退款,
2375
- * 只能根据单个子单进行退款。传入子单的 out_trade_no 或 transaction_id。
2376
- *
2377
- * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
2378
- * 仅支持支付成功后 1 年内的订单。
2379
- *
2380
- * 注意:
2381
- * - 一笔订单最多支持 50 次部分退款,间隔至少 1 分钟
2382
- * - 重试时必须使用原商户退款单号,避免重复退款
2383
- * - 接口返回成功仅表示受理成功,最终结果以回调通知和查询接口为准
2384
- *
2385
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421410
2386
- */
2387
- async createRefund(request) {
2388
- return this.client.post("/v3/refund/domestic/refunds", request);
2389
- }
2390
- /**
2391
- * 查询退款单
2392
- *
2393
- * 通过商户退款单号查询退款状态。
2394
- * 退款申请成功后,可通过此接口确认退款是否到账。
2395
- *
2396
- * 退款状态:
2397
- * - SUCCESS:退款成功
2398
- * - CLOSED:退款关闭
2399
- * - PROCESSING:退款处理中
2400
- * - ABNORMAL:退款异常
2401
- *
2402
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421421
2403
- */
2404
- async queryRefund(params) {
2405
- return this.client.get(
2406
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
2407
- );
2408
- }
2409
- /**
2410
- * 申请异常退款
2411
- *
2412
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
2413
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
2414
- *
2415
- * @param refundId - 微信支付退款单号
2416
- * @param request - 异常退款请求参数
2417
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421429
2418
- */
2419
- async applyAbnormalRefund(refundId, request) {
2420
- return this.client.post(
2421
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
2422
- request
2423
- );
2424
- }
2425
- /**
2426
- * 申请交易账单
2427
- *
2428
- * 合单支付的订单账单是以子单为维度,每笔子单都会记录在各个子单商户账单内,
2429
- * 需要各个子单商户自己进行下载。
2430
- *
2431
- * 商户可通过此接口获取交易账单的下载链接,下载地址 5 分钟内有效。
2432
- *
2433
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421450
2434
- */
2435
- async tradeBill(params) {
2436
- return this.client.get("/v3/bill/tradebill", params);
2437
- }
2438
- /**
2439
- * 申请资金账单
2440
- *
2441
- * 商户可通过此接口获取资金账单的下载链接,下载地址 5 分钟内有效。
2442
- *
2443
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421456
1682
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556944
2444
1683
  */
2445
- async fundFlowBill(params) {
2446
- return this.client.get("/v3/bill/fundflowbill", params);
1684
+ async createOrder(request) {
1685
+ return this.client.post("/v3/combine-transactions/app", request);
2447
1686
  }
1687
+ };
1688
+
1689
+ // src/services/combine-miniprogram.ts
1690
+ var CombineMiniProgramService = class extends BaseCombineService {
2448
1691
  /**
2449
- * 下载账单
1692
+ * 小程序合单下单
2450
1693
  *
2451
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
2452
- * 下载地址 5 分钟内有效,请及时下载。
2453
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
1694
+ * 商户通过此接口生成小程序合单预付单并获取 prepay_id。
1695
+ * 获取 prepay_id 后,配合 buildMiniProgramBridgeConfig 生成调起支付参数,
1696
+ * 通过小程序 wx.requestPayment() 方法唤起微信支付收银台。
1697
+ *
1698
+ * prepay_id 有效期为 2 小时,超过 2 小时需使用原下单参数重新请求。
1699
+ *
1700
+ * 关键约束:
1701
+ * - combine_mchid 需先申请发起合单支付权限
1702
+ * - sub_orders 中的 mchid 需先申请接收合单支付权限
1703
+ * - 合单发起方和子单参与方需绑定同一个 combine_appid
1704
+ * - combine_appid 必须为小程序 AppID
1705
+ * - combine_payer_info.openid 在小程序场景下可选(由运行环境隐式提供)
1706
+ * - 子单数量为 2-10 笔
1707
+ * - time_expire 不能早于下单时间后 1 分钟,不能超过下单时间后 7 天
2454
1708
  *
2455
- * @param downloadUrl - 申请账单返回的 download_url
2456
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421461
1709
+ * @see https://pay.weixin.qq.com/doc/v3/merchant/4012556931
2457
1710
  */
2458
- async downloadBill(downloadUrl) {
2459
- return this.client.downloadRaw(downloadUrl);
1711
+ async createOrder(request) {
1712
+ return this.client.post(
1713
+ "/v3/combine-transactions/jsapi",
1714
+ request
1715
+ );
2460
1716
  }
2461
1717
  };
2462
1718
 
2463
1719
  // src/services/combine-native.ts
2464
- var CombineNativeService = class {
2465
- client;
2466
- constructor(client) {
2467
- this.client = client;
2468
- }
1720
+ var CombineNativeService = class extends BaseCombineService {
2469
1721
  /**
2470
1722
  * Native 合单下单
2471
1723
  *
@@ -2492,144 +1744,6 @@ var CombineNativeService = class {
2492
1744
  request
2493
1745
  );
2494
1746
  }
2495
- /**
2496
- * 查询合单订单
2497
- *
2498
- * 通过合单商户订单号查询合单订单的支付状态及各子单详情。
2499
- * 合单支付订单需使用合单查单接口,不可使用非合单支付的查单接口。
2500
- *
2501
- * 订单状态(sub_orders[].trade_state):
2502
- * - SUCCESS:支付成功(终态)
2503
- * - NOTPAY:未支付
2504
- * - CLOSED:已关闭(终态)
2505
- *
2506
- * 典型使用场景:
2507
- * - 用户扫码支付后,轮询确认订单支付状态
2508
- * - 未收到支付成功回调通知时,主动查询确认订单状态
2509
- * - 关单前确认订单仍为未支付状态
2510
- *
2511
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421316
2512
- */
2513
- async queryOrderById(params) {
2514
- return this.client.get(
2515
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}`
2516
- );
2517
- }
2518
- /**
2519
- * 关闭合单订单
2520
- *
2521
- * 对于未支付的合单订单,商户可通过此接口关闭订单。
2522
- * 关单后,所有子单状态从未支付(NOTPAY)流转为已关闭(CLOSED)。
2523
- *
2524
- * 关键约束:
2525
- * - 只能整单关闭,不支持关闭部分子单
2526
- * - combine_appid、sub_orders 中的 mchid 和 out_trade_no 必须与下单时完全一致
2527
- * - 仅支持未支付状态的订单
2528
- * - 关单后订单为失败终态
2529
- *
2530
- * 典型使用场景:
2531
- * - 用户超过商户系统内部规定的支付时间
2532
- * - 超过下单时设置的 time_expire 时间
2533
- * - 因特殊原因需在可支付时间范围内关闭订单
2534
- *
2535
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421330
2536
- */
2537
- async closeOrder(params, request) {
2538
- return this.client.post(
2539
- `/v3/combine-transactions/out-trade-no/${params.combineOutTradeNo}/close`,
2540
- request
2541
- );
2542
- }
2543
- /**
2544
- * 申请退款(基于子单)
2545
- *
2546
- * 合单支付的订单退款,无法通过合单商户订单号(combine_out_trade_no)退款,
2547
- * 只能根据单个子单进行退款。传入子单的 out_trade_no 或 transaction_id。
2548
- *
2549
- * 当子单状态为支付成功(SUCCESS)时,商户可通过此接口申请退款。
2550
- * 仅支持支付成功后 1 年内的订单。
2551
- *
2552
- * 注意:
2553
- * - 一笔订单最多支持 50 次部分退款,间隔至少 1 分钟
2554
- * - 重试时必须使用原商户退款单号,避免重复退款
2555
- * - 接口返回成功仅表示受理成功,最终结果以回调通知和查询接口为准
2556
- *
2557
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421340
2558
- */
2559
- async createRefund(request) {
2560
- return this.client.post("/v3/refund/domestic/refunds", request);
2561
- }
2562
- /**
2563
- * 查询退款单
2564
- *
2565
- * 通过商户退款单号查询退款状态。
2566
- * 退款申请成功后,可通过此接口确认退款是否到账。
2567
- *
2568
- * 退款状态:
2569
- * - SUCCESS:退款成功
2570
- * - CLOSED:退款关闭
2571
- * - PROCESSING:退款处理中
2572
- * - ABNORMAL:退款异常
2573
- *
2574
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421346
2575
- */
2576
- async queryRefund(params) {
2577
- return this.client.get(
2578
- `/v3/refund/domestic/refunds/${params.outRefundNo}`
2579
- );
2580
- }
2581
- /**
2582
- * 申请异常退款
2583
- *
2584
- * 当退款状态为 ABNORMAL 时,可通过此接口发起异常退款处理。
2585
- * 支持退款至用户银行卡或退款至交易商户银行账户两种方式。
2586
- *
2587
- * @param refundId - 微信支付退款单号
2588
- * @param request - 异常退款请求参数
2589
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421352
2590
- */
2591
- async applyAbnormalRefund(refundId, request) {
2592
- return this.client.post(
2593
- `/v3/refund/domestic/refunds/${refundId}/apply-abnormal-refund`,
2594
- request
2595
- );
2596
- }
2597
- /**
2598
- * 申请交易账单
2599
- *
2600
- * 合单支付的订单账单是以子单为维度,每笔子单都会记录在各个子单商户账单内,
2601
- * 需要各个子单商户自己进行下载。
2602
- *
2603
- * 商户可通过此接口获取交易账单的下载链接,下载地址 5 分钟内有效。
2604
- *
2605
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421361
2606
- */
2607
- async tradeBill(params) {
2608
- return this.client.get("/v3/bill/tradebill", params);
2609
- }
2610
- /**
2611
- * 申请资金账单
2612
- *
2613
- * 商户可通过此接口获取资金账单的下载链接,下载地址 5 分钟内有效。
2614
- *
2615
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421365
2616
- */
2617
- async fundFlowBill(params) {
2618
- return this.client.get("/v3/bill/fundflowbill", params);
2619
- }
2620
- /**
2621
- * 下载账单
2622
- *
2623
- * 通过申请账单接口返回的 download_url,以 GET 方式下载账单原始文件。
2624
- * 下载地址 5 分钟内有效,请及时下载。
2625
- * 返回的 data 为 Buffer,可能为 GZIP 压缩格式,需要自行解压。
2626
- *
2627
- * @param downloadUrl - 申请账单返回的 download_url
2628
- * @see https://pay.weixin.qq.com/doc/v3/merchant/4013421368
2629
- */
2630
- async downloadBill(downloadUrl) {
2631
- return this.client.downloadRaw(downloadUrl);
2632
- }
2633
1747
  };
2634
1748
 
2635
1749
  // src/services/profitsharing.ts
@@ -5390,6 +4504,19 @@ var PartnerTransferService = class {
5390
4504
  { sub_mchid: subMchid }
5391
4505
  );
5392
4506
  }
4507
+ /**
4508
+ * 通过微信单号查询转账单
4509
+ *
4510
+ * @param transferBillNo - 微信转账单号
4511
+ * @param subMchid - 特约商户号
4512
+ * @returns 转账单详情
4513
+ */
4514
+ async queryTransferByTransferBillNo(transferBillNo, subMchid) {
4515
+ return this.client.get(
4516
+ `/v3/fund-app/mch-transfer/partner/transfer-bills/transfer-bill-no/${transferBillNo}`,
4517
+ { sub_mchid: subMchid }
4518
+ );
4519
+ }
5393
4520
  /**
5394
4521
  * 撤销转账
5395
4522
  *
@@ -5402,6 +4529,155 @@ var PartnerTransferService = class {
5402
4529
  { sub_mchid: subMchid }
5403
4530
  );
5404
4531
  }
4532
+ // ============= 电子回单 =============
4533
+ /**
4534
+ * 商户单号申请电子回单
4535
+ *
4536
+ * 申请条件:
4537
+ * - 转账单据状态为 SUCCESS
4538
+ * - 传入了收款用户姓名
4539
+ * - 六个月内的转账单据
4540
+ *
4541
+ * 回单有效期为90天,过期需重新申请。
4542
+ *
4543
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4012716452
4544
+ */
4545
+ async applyElecSignByOutBillNo(request) {
4546
+ return this.client.post(
4547
+ "/v3/fund-app/mch-transfer/partner/elecsign/out-bill-no",
4548
+ request
4549
+ );
4550
+ }
4551
+ /**
4552
+ * 商户单号查询电子回单
4553
+ *
4554
+ * 当申请单状态为 FINISHED 时,返回回单文件的下载地址和摘要信息。
4555
+ * 下载地址有效期为10分钟,过期后需重新调用此接口获取。
4556
+ *
4557
+ * @param outBillNo - 商户单号
4558
+ * @param subMchid - 特约商户号
4559
+ *
4560
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4012716436
4561
+ */
4562
+ async queryElecSignByOutBillNo(outBillNo, subMchid) {
4563
+ return this.client.get(
4564
+ `/v3/fund-app/mch-transfer/partner/elecsign/out-bill-no/${outBillNo}`,
4565
+ { sub_mchid: subMchid }
4566
+ );
4567
+ }
4568
+ /**
4569
+ * 微信单号申请电子回单
4570
+ *
4571
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4012716456
4572
+ */
4573
+ async applyElecSignByTransferBillNo(request) {
4574
+ return this.client.post(
4575
+ "/v3/fund-app/mch-transfer/partner/elecsign/transfer-bill-no",
4576
+ request
4577
+ );
4578
+ }
4579
+ /**
4580
+ * 微信单号查询电子回单
4581
+ *
4582
+ * @param transferBillNo - 微信转账单号
4583
+ * @param subMchid - 特约商户号
4584
+ *
4585
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4012716455
4586
+ */
4587
+ async queryElecSignByTransferBillNo(transferBillNo, subMchid) {
4588
+ return this.client.get(
4589
+ `/v3/fund-app/mch-transfer/partner/elecsign/transfer-bill-no/${transferBillNo}`,
4590
+ { sub_mchid: subMchid }
4591
+ );
4592
+ }
4593
+ /**
4594
+ * 下载电子回单
4595
+ *
4596
+ * 通过申请电子回单接口返回的 download_url,以 GET 方式下载回单原始文件。
4597
+ * 下载地址有效期为 10 分钟,过期后需重新调用查询接口获取。
4598
+ * 返回的 data 为 PDF 文件的 Buffer。
4599
+ *
4600
+ * @param downloadUrl - 查询电子回单返回的 download_url
4601
+ * @returns 电子回单文件 Buffer
4602
+ *
4603
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4013866774
4604
+ */
4605
+ async downloadElecSign(downloadUrl) {
4606
+ return this.client.downloadRaw(downloadUrl);
4607
+ }
4608
+ // ============= 用户授权免确认模式 =============
4609
+ /**
4610
+ * 发起转账并完成免确认收款授权
4611
+ *
4612
+ * 在发起转账的同时申请免确认收款授权,用户确认收款时可同时完成授权。
4613
+ * 授权成功后,后续转账无需用户逐笔确认。
4614
+ *
4615
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4014399293
4616
+ */
4617
+ async createTransferWithAuthorization(request) {
4618
+ return this.client.post(
4619
+ "/v3/fund-app/mch-transfer/partner/transfer-bills/pre-transfer-with-authorization",
4620
+ request
4621
+ );
4622
+ }
4623
+ /**
4624
+ * 发起免确认收款授权
4625
+ *
4626
+ * 直接申请免确认收款授权,不发起转账。
4627
+ * 用户需在24小时内完成授权,未确认记录保留30天。
4628
+ * 同一微信号在同商户下待确认+已授权状态的授权单最多5个。
4629
+ *
4630
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4015901167
4631
+ */
4632
+ async createAuthorization(request) {
4633
+ return this.client.post(
4634
+ "/v3/fund-app/mch-transfer/partner/user-confirm-authorization",
4635
+ request
4636
+ );
4637
+ }
4638
+ /**
4639
+ * 商户单号查询授权结果
4640
+ *
4641
+ * @param request - 查询请求参数
4642
+ *
4643
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4014399423
4644
+ */
4645
+ async queryAuthorizationByOutAuthorizationNo(request) {
4646
+ const { sub_mchid, out_authorization_no, is_display_authorization } = request;
4647
+ return this.client.get(
4648
+ `/v3/fund-app/mch-transfer/partner/user-confirm-authorization/out-authorization-no/${out_authorization_no}`,
4649
+ { sub_mchid, is_display_authorization }
4650
+ );
4651
+ }
4652
+ /**
4653
+ * 用户授权后转账
4654
+ *
4655
+ * 用户完成授权后,商户可直接发起转账,无需用户逐笔确认收款。
4656
+ * 需要提供 authorization_id 或 out_authorization_no(二选一)。
4657
+ *
4658
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4014399371
4659
+ */
4660
+ async createTransferAfterAuthorization(request) {
4661
+ return this.client.post(
4662
+ "/v3/fund-app/mch-transfer/partner/transfer-bills/transfer",
4663
+ request
4664
+ );
4665
+ }
4666
+ /**
4667
+ * 解除免确认收款授权
4668
+ *
4669
+ * 商户可调用此接口帮助用户发起解除授权。
4670
+ * 用户也可通过微信支付入账消息的收款设置操作关闭授权。
4671
+ *
4672
+ * @see https://pay.weixin.qq.com/doc/v3/partner/4015653811
4673
+ */
4674
+ async closeAuthorization(request) {
4675
+ const { sub_mchid, out_authorization_no } = request;
4676
+ return this.client.post(
4677
+ `/v3/fund-app/mch-transfer/partner/user-confirm-authorization/out-authorization-no/${out_authorization_no}/close`,
4678
+ { sub_mchid }
4679
+ );
4680
+ }
5405
4681
  };
5406
4682
 
5407
4683
  // src/services/transfer-batch.ts