@celljs/wechat-pay 0.0.0-stage → 4.4.0

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.
Files changed (84) hide show
  1. package/README.md +106 -2
  2. package/cell.schema.json +73 -0
  3. package/cell.yml +10 -0
  4. package/esm/node/index.d.ts +5 -0
  5. package/esm/node/index.js +6 -0
  6. package/esm/node/index.js.map +1 -0
  7. package/esm/node/module.d.ts +3 -0
  8. package/esm/node/module.js +4 -0
  9. package/esm/node/module.js.map +1 -0
  10. package/esm/node/test/fixtures.d.ts +3 -0
  11. package/esm/node/test/fixtures.js +51 -0
  12. package/esm/node/test/fixtures.js.map +1 -0
  13. package/esm/node/wechat-pay-client.d.ts +53 -0
  14. package/esm/node/wechat-pay-client.js +274 -0
  15. package/esm/node/wechat-pay-client.js.map +1 -0
  16. package/esm/node/wechat-pay-error.d.ts +29 -0
  17. package/esm/node/wechat-pay-error.js +21 -0
  18. package/esm/node/wechat-pay-error.js.map +1 -0
  19. package/esm/node/wechat-pay-notification-middleware.d.ts +25 -0
  20. package/esm/node/wechat-pay-notification-middleware.js +108 -0
  21. package/esm/node/wechat-pay-notification-middleware.js.map +1 -0
  22. package/esm/node/wechat-pay-protocol.d.ts +286 -0
  23. package/esm/node/wechat-pay-protocol.js +14 -0
  24. package/esm/node/wechat-pay-protocol.js.map +1 -0
  25. package/esm/node/wechat-pay-util.d.ts +45 -0
  26. package/esm/node/wechat-pay-util.js +123 -0
  27. package/esm/node/wechat-pay-util.js.map +1 -0
  28. package/esm/package.json +3 -0
  29. package/lib/node/index.d.ts +6 -0
  30. package/lib/node/index.d.ts.map +1 -0
  31. package/lib/node/index.js +22 -0
  32. package/lib/node/index.js.map +1 -0
  33. package/lib/node/module.d.ts +4 -0
  34. package/lib/node/module.d.ts.map +1 -0
  35. package/lib/node/module.js +6 -0
  36. package/lib/node/module.js.map +1 -0
  37. package/lib/node/test/fixtures.d.ts +4 -0
  38. package/lib/node/test/fixtures.d.ts.map +1 -0
  39. package/lib/node/test/fixtures.js +54 -0
  40. package/lib/node/test/fixtures.js.map +1 -0
  41. package/lib/node/wechat-pay-client.d.ts +54 -0
  42. package/lib/node/wechat-pay-client.d.ts.map +1 -0
  43. package/lib/node/wechat-pay-client.js +277 -0
  44. package/lib/node/wechat-pay-client.js.map +1 -0
  45. package/lib/node/wechat-pay-error.d.ts +30 -0
  46. package/lib/node/wechat-pay-error.d.ts.map +1 -0
  47. package/lib/node/wechat-pay-error.js +25 -0
  48. package/lib/node/wechat-pay-error.js.map +1 -0
  49. package/lib/node/wechat-pay-notification-middleware.d.ts +26 -0
  50. package/lib/node/wechat-pay-notification-middleware.d.ts.map +1 -0
  51. package/lib/node/wechat-pay-notification-middleware.js +111 -0
  52. package/lib/node/wechat-pay-notification-middleware.js.map +1 -0
  53. package/lib/node/wechat-pay-protocol.d.ts +287 -0
  54. package/lib/node/wechat-pay-protocol.d.ts.map +1 -0
  55. package/lib/node/wechat-pay-protocol.js +18 -0
  56. package/lib/node/wechat-pay-protocol.js.map +1 -0
  57. package/lib/node/wechat-pay-util.d.ts +46 -0
  58. package/lib/node/wechat-pay-util.d.ts.map +1 -0
  59. package/lib/node/wechat-pay-util.js +126 -0
  60. package/lib/node/wechat-pay-util.js.map +1 -0
  61. package/lib/node/wechat-pay-util.spec.d.ts +2 -0
  62. package/lib/node/wechat-pay-util.spec.d.ts.map +1 -0
  63. package/lib/node/wechat-pay-util.spec.js +82 -0
  64. package/lib/node/wechat-pay-util.spec.js.map +1 -0
  65. package/lib/node/wechat-pay.spec.d.ts +8 -0
  66. package/lib/node/wechat-pay.spec.d.ts.map +1 -0
  67. package/lib/node/wechat-pay.spec.js +318 -0
  68. package/lib/node/wechat-pay.spec.js.map +1 -0
  69. package/lib/package.spec.d.ts +2 -0
  70. package/lib/package.spec.d.ts.map +1 -0
  71. package/lib/package.spec.js +7 -0
  72. package/lib/package.spec.js.map +1 -0
  73. package/package.json +70 -4
  74. package/src/node/index.ts +5 -0
  75. package/src/node/module.ts +4 -0
  76. package/src/node/test/fixtures.ts +51 -0
  77. package/src/node/wechat-pay-client.ts +298 -0
  78. package/src/node/wechat-pay-error.ts +35 -0
  79. package/src/node/wechat-pay-notification-middleware.ts +97 -0
  80. package/src/node/wechat-pay-protocol.ts +265 -0
  81. package/src/node/wechat-pay-util.spec.ts +87 -0
  82. package/src/node/wechat-pay-util.ts +123 -0
  83. package/src/node/wechat-pay.spec.ts +340 -0
  84. package/src/package.spec.ts +5 -0
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # Cell - WeChat Pay Component
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Add `@celljs/wechat-pay` to the dependencies to take payments with [WeChat Pay API v3](https://pay.weixin.qq.com/doc/v3/merchant/4012062524) (微信支付): an injectable `WechatPayClient` signs the requests and verifies the signatures of the answers, and a notification endpoint verifies, decrypts and hands payment and refund notifications to your handlers. It uses Node's `crypto` and `fetch`, with no third-party dependency.
4
+
5
+ ```yaml
6
+ # cell.yml: configuration is server-only unless a schema marks it public; take credentials from the environment
7
+ wechatPay:
8
+ mchId: ${env.WECHAT_PAY_MCH_ID} # 商户号
9
+ appId: ${env.WECHAT_PAY_APP_ID} # 公众号 / 小程序 / App 的 AppID
10
+ serialNo: ${env.WECHAT_PAY_SERIAL_NO} # 商户 API 证书序列号
11
+ privateKey: ${env.WECHAT_PAY_PRIVATE_KEY} # apiclient_key.pem: its PEM text or its path
12
+ apiV3Key: ${env.WECHAT_PAY_API_V3_KEY} # APIv3 密钥
13
+ publicKeyId: ${env.WECHAT_PAY_PUBLIC_KEY_ID} # 微信支付公钥 ID: PUB_KEY_ID_...
14
+ publicKey: ${env.WECHAT_PAY_PUBLIC_KEY} # 微信支付公钥, PEM
15
+ notifyUrl: https://shop.example.com/wechat-pay/notify
16
+ ```
17
+
18
+ ```ts
19
+ import { Autowired } from '@celljs/core';
20
+ import { Body, Controller, Post } from '@celljs/mvc/lib/node';
21
+ import { WechatPayClient, WechatPayNotification, WechatPayNotificationHandler, WechatPayTransaction } from '@celljs/wechat-pay';
22
+
23
+ @Controller('orders')
24
+ export class OrderController {
25
+ @Autowired(WechatPayClient)
26
+ protected readonly wechatPay: WechatPayClient;
27
+
28
+ @Post('native') // 扫码支付: show code_url as a QR code
29
+ async native(@Body() order: { id: string }) {
30
+ return this.wechatPay.createNativeOrder({ description: 'Cell T-shirt', out_trade_no: order.id, amount: { total: 100 } }); // in fen: 1 yuan
31
+ }
32
+
33
+ @Post('jsapi') // 小程序 / 公众号: the page calls wx.requestPayment(params)
34
+ async jsapi(@Body() order: { id: string; openid: string }) {
35
+ const { prepay_id } = await this.wechatPay.createJsapiOrder({ description: 'Cell T-shirt', out_trade_no: order.id, amount: { total: 100 }, payer: { openid: order.openid } });
36
+ return this.wechatPay.jsapiParams(prepay_id);
37
+ }
38
+ }
39
+
40
+ @WechatPayNotificationHandler('TRANSACTION.SUCCESS')
41
+ export class PaidHandler implements WechatPayNotificationHandler<WechatPayTransaction> {
42
+ async handle({ resource }: WechatPayNotification<WechatPayTransaction>) {
43
+ // resource is decrypted: out_trade_no, transaction_id, trade_state, amount.total...
44
+ // Mark the order paid once: the same notification can come again.
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## Client
50
+
51
+ The payloads use the field names of WeChat Pay's documentation (snake_case), so its pages apply as they are. `appid`, `mchid` and `notify_url` default to the configuration.
52
+
53
+ | Method | API |
54
+ | --- | --- |
55
+ | `createJsapiOrder(order)` → `{ prepay_id }` | JSAPI / 小程序下单; then `jsapiParams(prepayId, appId?)` for `wx.requestPayment` / `getBrandWCPayRequest` |
56
+ | `createAppOrder(order)` → `{ prepay_id }` | App 下单; then `appParams(prepayId, appId?)` for the App SDK |
57
+ | `createNativeOrder(order)` → `{ code_url }` | Native 扫码下单 |
58
+ | `createH5Order(order)` → `{ h5_url }` | H5 下单 (`scene_info.h5_info` required) |
59
+ | `queryOrder({ out_trade_no } \| { transaction_id })` | 查询订单 |
60
+ | `closeOrder(outTradeNo)` | 关闭订单 |
61
+ | `refund(request)` / `queryRefund(outRefundNo)` | 申请退款 / 查询单笔退款 |
62
+ | `tradeBill(query)` / `fundFlowBill(query)`, then `download(download_url)` | 交易账单 / 资金账单 |
63
+ | `request(method, path, body?, { query, headers })` | Any other API, signed and verified |
64
+ | `parseNotification(headers, rawBody)` | Verifies and decrypts a notification received on a route of your own |
65
+
66
+ `WechatPayUtil` has the primitives: `signMessage`, `verifyMessage`, `decrypt` (AEAD_AES_256_GCM), `encrypt` (RSA-OAEP for sensitive fields; send the key's serial as `Wechatpay-Serial` in `headers`).
67
+
68
+ ## Notifications
69
+
70
+ The endpoint is `POST /wechat-pay/notify` (`wechatPay.notification.url`, under `server.path`); set its absolute URL as `notifyUrl`. It runs before the body parser and authentication, reads the body as sent, checks the signature and that the timestamp is within `tolerance` seconds (300), decrypts the resource and runs the `@WechatPayNotificationHandler` components of the event type (`TRANSACTION.SUCCESS`, `REFUND.SUCCESS`, `REFUND.ABNORMAL`, `REFUND.CLOSED`), then those declared without types, one after the other. It answers:
71
+
72
+ - 204 when they all succeed (or when no handler takes the event type: logged as a warning);
73
+ - 401 `{"code":"FAIL"}` when the signature or the timestamp is wrong;
74
+ - 500 `{"code":"FAIL"}` when a handler throws: WeChat Pay sends the notification again later, so handlers must be idempotent.
75
+
76
+ Notifications only say what happened: for amounts that matter, check `resource.amount.total` against the order, or call `queryOrder`.
77
+
78
+ ## Keys that verify WeChat Pay
79
+
80
+ Merchants created since 2024 have a **WeChat Pay public key** (`publicKeyId` + `publicKey`). Older merchants verify with **platform certificates** (平台证书): leave `publicKey` out and the client downloads them from `/v3/certificates` when a signature names a serial it does not know (at most once a minute), or give them as `platformCertificates` (PEM, one or a list). Both can be set during a migration: the serial in `Wechatpay-Serial` selects the key.
81
+
82
+ ## Configuration
83
+
84
+ ```yaml
85
+ wechatPay:
86
+ baseUrl: https://api.mch.weixin.qq.com
87
+ timeout: 10000 # milliseconds per request
88
+ notification:
89
+ enabled: true
90
+ url: /wechat-pay/notify
91
+ tolerance: 300 # seconds
92
+ ```
93
+
94
+ ## Errors
95
+
96
+ Failures are `WechatPayError`s with a stable `code` and a `hint`:
97
+
98
+ | Code | When |
99
+ | --- | --- |
100
+ | `CELL_WECHAT_PAY_NOT_CONFIGURED` | `mchId`, `serialNo`, `privateKey`, `apiV3Key` or the AppID is missing |
101
+ | `CELL_WECHAT_PAY_API_ERROR` | WeChat Pay answered an error: `status` and `detail.code` (`ORDER_NOT_EXIST`, `PARAM_ERROR`...) |
102
+ | `CELL_WECHAT_PAY_SIGNATURE_INVALID` | An answer or a notification is not signed by WeChat Pay |
103
+ | `CELL_WECHAT_PAY_TIMESTAMP_EXPIRED` | A notification's timestamp is outside `tolerance` |
104
+ | `CELL_WECHAT_PAY_UNKNOWN_SERIAL` | No public key or platform certificate has the serial of a signature |
105
+ | `CELL_WECHAT_PAY_DECRYPT_FAILED` | The resource cannot be decrypted: wrong `apiV3Key` |
106
+
107
+ WeChat Pay API v3 has no sandbox: test with a real merchant and small amounts, and expose the notification endpoint with a tunnel during development.
@@ -0,0 +1,73 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "wechatPay": {
5
+ "type": "object",
6
+ "description": "WeChat Pay.",
7
+ "properties": {
8
+ "mchId": {
9
+ "type": "string"
10
+ },
11
+ "appId": {
12
+ "type": "string"
13
+ },
14
+ "serialNo": {
15
+ "type": "string"
16
+ },
17
+ "privateKey": {
18
+ "type": "string",
19
+ "description": "From the environment: ${env.WECHAT_PAY_PRIVATE_KEY}."
20
+ },
21
+ "publicKey": {
22
+ "type": "string"
23
+ },
24
+ "publicKeyId": {
25
+ "type": "string"
26
+ },
27
+ "platformCertificates": {
28
+ "anyOf": [
29
+ {
30
+ "type": "string"
31
+ },
32
+ {
33
+ "type": "array",
34
+ "items": {
35
+ "type": "string"
36
+ }
37
+ }
38
+ ]
39
+ },
40
+ "apiV3Key": {
41
+ "type": "string"
42
+ },
43
+ "notifyUrl": {
44
+ "type": "string",
45
+ "description": "Absolute URL of the notification endpoint."
46
+ },
47
+ "baseUrl": {
48
+ "type": "string"
49
+ },
50
+ "timeout": {
51
+ "type": "integer",
52
+ "description": "Milliseconds a request may take."
53
+ },
54
+ "notification": {
55
+ "type": "object",
56
+ "properties": {
57
+ "enabled": {
58
+ "type": "boolean"
59
+ },
60
+ "url": {
61
+ "type": "string",
62
+ "description": "POST endpoint that receives the notifications."
63
+ },
64
+ "tolerance": {
65
+ "type": "integer",
66
+ "description": "Seconds a signature stays valid."
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
package/cell.yml ADDED
@@ -0,0 +1,10 @@
1
+ wechatPay:
2
+ # Credentials (mchId, appId, serialNo, privateKey, apiV3Key, publicKeyId, publicKey) go here too,
3
+ # from the environment: privateKey: ${env.WECHAT_PAY_PRIVATE_KEY}
4
+ baseUrl: https://api.mch.weixin.qq.com
5
+ timeout: 10000 # ms
6
+ notification:
7
+ # POST endpoint that receives the payment and refund notifications; give its absolute URL as notifyUrl.
8
+ enabled: true
9
+ url: /wechat-pay/notify
10
+ tolerance: 300
@@ -0,0 +1,5 @@
1
+ export * from './wechat-pay-client.js';
2
+ export * from './wechat-pay-error.js';
3
+ export * from './wechat-pay-notification-middleware.js';
4
+ export * from './wechat-pay-protocol.js';
5
+ export * from './wechat-pay-util.js';
@@ -0,0 +1,6 @@
1
+ export * from './wechat-pay-client.js';
2
+ export * from './wechat-pay-error.js';
3
+ export * from './wechat-pay-notification-middleware.js';
4
+ export * from './wechat-pay-protocol.js';
5
+ export * from './wechat-pay-util.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import './index.js';
2
+ declare const _default: import("@celljs/core").ContainerModule;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { autoBind } from '@celljs/core';
2
+ import './index.js';
3
+ export default autoBind();
4
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** A platform certificate and its key for the tests, made with openssl; they sign nothing outside them. */
2
+ export declare const PLATFORM_CERTIFICATE = "-----BEGIN CERTIFICATE-----\nMIIDaTCCAlGgAwIBAgIJAJJ0ELbwtQzBMA0GCSqGSIb3DQEBCwUAMF8xCzAJBgNV\nBAYTAkNOMRIwEAYDVQQKDAlDZWxsIFRlc3QxIDAeBgNVBAsMF0NlcnRpZmljYXRp\nb24gQXV0aG9yaXR5MRowGAYDVQQDDBFDZWxsIFRlc3QgUm9vdCBDQTAgFw0yNjEx\nMDkwNjE2MDVaGA8yMTI2MTAxNjA2MTYwNVowQzELMAkGA1UEBhMCQ04xEjAQBgNV\nBAoMCUNlbGwgVGVzdDEPMA0GA1UECwwGd2VjaGF0MQ8wDQYDVQQDDAZ3ZWNoYXQw\nggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCweANQTvdi0EhyWasZI2+s\nuhUJG24G30hes8UbQDtcU3/6KpYe+wfR7aCqM7kAH083d3GJ8R8XMAHFL2GC49X8\nxWriduolvctqM0lJYQCrz9yHCKjf5qawp+LA42SVhcyoCQG3PxNYeWShEACOoxZr\nYVnDgjJ7APNQmfJf3dJ8gkixHC3LYoRCqS20E9AUE4Tid4b2dyw+mlwpwLGsp/Om\na5/gn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jFDcS3sRnicCgYEA3QHr8iqE/J6F6xHKnUuD\nO6nXMGWgwN7vRwINMWMjir9wGoYddA9nrvQWxs5ciuATHMgT3Cly4Vtm3dl1D/e2\njdjCMPszQ0AP8l4IYrh7BBgU9x3zsYvH9R9w3+rWZUTAEb02iWyyR8WjpAZUp3ND\ni0AMxj1J3Z3VswvKu9OYJJc=\n-----END PRIVATE KEY-----";
@@ -0,0 +1,51 @@
1
+ /** A platform certificate and its key for the tests, made with openssl; they sign nothing outside them. */
2
+ export const PLATFORM_CERTIFICATE = `-----BEGIN CERTIFICATE-----
3
+ MIIDaTCCAlGgAwIBAgIJAJJ0ELbwtQzBMA0GCSqGSIb3DQEBCwUAMF8xCzAJBgNV
4
+ BAYTAkNOMRIwEAYDVQQKDAlDZWxsIFRlc3QxIDAeBgNVBAsMF0NlcnRpZmljYXRp
5
+ b24gQXV0aG9yaXR5MRowGAYDVQQDDBFDZWxsIFRlc3QgUm9vdCBDQTAgFw0yNjEx
6
+ MDkwNjE2MDVaGA8yMTI2MTAxNjA2MTYwNVowQzELMAkGA1UEBhMCQ04xEjAQBgNV
7
+ BAoMCUNlbGwgVGVzdDEPMA0GA1UECwwGd2VjaGF0MQ8wDQYDVQQDDAZ3ZWNoYXQw
8
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCweANQTvdi0EhyWasZI2+s
9
+ uhUJG24G30hes8UbQDtcU3/6KpYe+wfR7aCqM7kAH083d3GJ8R8XMAHFL2GC49X8
10
+ xWriduolvctqM0lJYQCrz9yHCKjf5qawp+LA42SVhcyoCQG3PxNYeWShEACOoxZr
11
+ YVnDgjJ7APNQmfJf3dJ8gkixHC3LYoRCqS20E9AUE4Tid4b2dyw+mlwpwLGsp/Om
12
+ a5/gn62pCB+dN+GWCxwlBUcp230iPHS/EcqVUoDOHkQEE/qVRN07AbjW7IFwEQzt
13
+ Kmt5pDgVy2pPuZMO/hmYKx7DzVVcaH3AFax1p4BxUXeY6T4dOmPjWvqZHDNXi6rF
14
+ AgMBAAGjQjBAMB0GA1UdDgQWBBQZ6Aieelx5f9GA4GUWPbCkpJ2CozAfBgNVHSME
15
+ GDAWgBTGHMPQNDhffsTHiKE5jnLmbj4ebDANBgkqhkiG9w0BAQsFAAOCAQEAO30n
16
+ lxZnBwB5L06Xajr83WfNmESZtqRXu7P6H8qihjkGh9LsoQc4X+k8RWsUrGd3jrDk
17
+ A54iFIHiLD7Ub8TKDcSwHYjJc5jqehi1JTVQ8br/sh6XiJE8OtO1qjWDne/ilaKm
18
+ Eu2Br7bL6G/G8PQd3fa2puRPn/Y7nM6YU9zpsPNnkBhKgkqj24nwbhGKtWD0eLmL
19
+ As2a+Vsz0w2zl90Iymaedpqa4XWiI58DzAUe8SJvNhMhbeplGjazBeYPvEtuQ6kV
20
+ kt1gdgyxK+M7wAvqs7txGygUKf+80ACF5sUgqTWImW30LC8rL4Bw/9+9ip0voPzQ
21
+ NqLhDaZSQO3YdQQkgA==
22
+ -----END CERTIFICATE-----`;
23
+ export const PLATFORM_PRIVATE_KEY = `-----BEGIN PRIVATE KEY-----
24
+ MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCweANQTvdi0Ehy
25
+ WasZI2+suhUJG24G30hes8UbQDtcU3/6KpYe+wfR7aCqM7kAH083d3GJ8R8XMAHF
26
+ L2GC49X8xWriduolvctqM0lJYQCrz9yHCKjf5qawp+LA42SVhcyoCQG3PxNYeWSh
27
+ EACOoxZrYVnDgjJ7APNQmfJf3dJ8gkixHC3LYoRCqS20E9AUE4Tid4b2dyw+mlwp
28
+ wLGsp/Oma5/gn62pCB+dN+GWCxwlBUcp230iPHS/EcqVUoDOHkQEE/qVRN07AbjW
29
+ 7IFwEQztKmt5pDgVy2pPuZMO/hmYKx7DzVVcaH3AFax1p4BxUXeY6T4dOmPjWvqZ
30
+ HDNXi6rFAgMBAAECggEACvHzb3bpkraaB7c82XsZ+uIy885zuir9iuiNGe39875q
31
+ FAYYKy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icCgYEA3QHr8iqE/J6F6xHKnUuD
47
+ O6nXMGWgwN7vRwINMWMjir9wGoYddA9nrvQWxs5ciuATHMgT3Cly4Vtm3dl1D/e2
48
+ jdjCMPszQ0AP8l4IYrh7BBgU9x3zsYvH9R9w3+rWZUTAEb02iWyyR8WjpAZUp3ND
49
+ i0AMxj1J3Z3VswvKu9OYJJc=
50
+ -----END PRIVATE KEY-----`;
51
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/node/test/fixtures.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;0BAoBV,CAAC;AAE3B,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA2BV,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { type KeyObject } from 'node:crypto';
2
+ import { WechatPayError } from './wechat-pay-error.js';
3
+ import { type WechatPayAppParams, type WechatPayBill, WechatPayClient, type WechatPayFundFlowBillQuery, type WechatPayH5Order, type WechatPayHeaders, type WechatPayHttpMethod, type WechatPayJsapiOrder, type WechatPayJsapiParams, type WechatPayNotification, type WechatPayOptions, type WechatPayOrder, type WechatPayRefund, type WechatPayRefundRequest, type WechatPayRequestOptions, type WechatPayTradeBillQuery, type WechatPayTransaction } from './wechat-pay-protocol.js';
4
+ export declare class WechatPayClientImpl implements WechatPayClient {
5
+ protected readonly options?: WechatPayOptions;
6
+ protected privateKey?: KeyObject;
7
+ /** Keys that verify WeChat Pay's signatures, by serial number or public key ID. */
8
+ protected verifyKeys?: Map<string, KeyObject>;
9
+ protected downloadedAt: number;
10
+ protected downloading?: Promise<void>;
11
+ request<T = any>(method: WechatPayHttpMethod, path: string, body?: object, options?: WechatPayRequestOptions): Promise<T>;
12
+ createJsapiOrder(order: WechatPayJsapiOrder): Promise<{
13
+ prepay_id: string;
14
+ }>;
15
+ createAppOrder(order: WechatPayOrder): Promise<{
16
+ prepay_id: string;
17
+ }>;
18
+ createNativeOrder(order: WechatPayOrder): Promise<{
19
+ code_url: string;
20
+ }>;
21
+ createH5Order(order: WechatPayH5Order): Promise<{
22
+ h5_url: string;
23
+ }>;
24
+ jsapiParams(prepayId: string, appId?: string): WechatPayJsapiParams;
25
+ appParams(prepayId: string, appId?: string): WechatPayAppParams;
26
+ queryOrder(query: {
27
+ transaction_id: string;
28
+ } | {
29
+ out_trade_no: string;
30
+ }): Promise<WechatPayTransaction>;
31
+ closeOrder(outTradeNo: string): Promise<void>;
32
+ refund(request: WechatPayRefundRequest): Promise<WechatPayRefund>;
33
+ queryRefund(outRefundNo: string): Promise<WechatPayRefund>;
34
+ tradeBill(query: WechatPayTradeBillQuery): Promise<WechatPayBill>;
35
+ fundFlowBill(query: WechatPayFundFlowBillQuery): Promise<WechatPayBill>;
36
+ download(url: string): Promise<Uint8Array>;
37
+ parseNotification<T = any>(headers: WechatPayHeaders, body: string | Uint8Array): Promise<WechatPayNotification<T>>;
38
+ /** The configuration; throws when the merchant is not configured. */
39
+ protected config(): WechatPayOptions;
40
+ protected key(): KeyObject;
41
+ protected appId(appId?: string): string;
42
+ protected order<T extends WechatPayOrder>(order: T): T;
43
+ protected send(url: URL, method: string, body: string, headers: Record<string, string>): Promise<Response>;
44
+ protected apiError(method: string, url: URL, status: number, answer: string): WechatPayError;
45
+ /** Checks `Wechatpay-Signature` over timestamp, nonce and body with the key `Wechatpay-Serial` names. */
46
+ protected verify(headers: WechatPayHeaders, body: string, notification: boolean): Promise<void>;
47
+ protected invalidSignature(message: string): WechatPayError;
48
+ protected verifyKey(serial: string): Promise<KeyObject>;
49
+ protected keys(): Map<string, KeyObject>;
50
+ protected addCertificate(pem: string): void;
51
+ /** Downloads the platform certificates; their own response is verified with the certificates it brings. */
52
+ protected downloadCertificates(): Promise<void>;
53
+ }
@@ -0,0 +1,274 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { X509Certificate } from 'node:crypto';
11
+ import { Component, Value } from '@celljs/core';
12
+ import { WechatPayError } from './wechat-pay-error.js';
13
+ import { WechatPayClient, } from './wechat-pay-protocol.js';
14
+ import { WechatPayUtil } from './wechat-pay-util.js';
15
+ const PUBLIC_KEY_PREFIX = 'PUB_KEY_ID_';
16
+ /** Platform certificates are downloaded at most this often when a signature names an unknown one. */
17
+ const DOWNLOAD_INTERVAL = 60000;
18
+ let WechatPayClientImpl = class WechatPayClientImpl {
19
+ constructor() {
20
+ this.downloadedAt = 0;
21
+ }
22
+ async request(method, path, body, options = {}) {
23
+ var _a, _b;
24
+ const config = this.config();
25
+ const url = new URL(path, (_a = config.baseUrl) !== null && _a !== void 0 ? _a : 'https://api.mch.weixin.qq.com');
26
+ for (const [key, value] of Object.entries((_b = options.query) !== null && _b !== void 0 ? _b : {})) {
27
+ if (value !== undefined) {
28
+ url.searchParams.set(key, String(value));
29
+ }
30
+ }
31
+ const text = body === undefined ? '' : JSON.stringify(body);
32
+ const response = await this.send(url, method, text, { ...(text ? { 'Content-Type': 'application/json' } : {}), ...options.headers });
33
+ const answer = await response.text();
34
+ if (!response.ok) {
35
+ throw this.apiError(method, url, response.status, answer);
36
+ }
37
+ await this.verify(response.headers, answer, false);
38
+ return (answer ? JSON.parse(answer) : undefined);
39
+ }
40
+ async createJsapiOrder(order) {
41
+ return this.request('POST', '/v3/pay/transactions/jsapi', this.order(order));
42
+ }
43
+ async createAppOrder(order) {
44
+ return this.request('POST', '/v3/pay/transactions/app', this.order(order));
45
+ }
46
+ async createNativeOrder(order) {
47
+ return this.request('POST', '/v3/pay/transactions/native', this.order(order));
48
+ }
49
+ async createH5Order(order) {
50
+ return this.request('POST', '/v3/pay/transactions/h5', this.order(order));
51
+ }
52
+ jsapiParams(prepayId, appId) {
53
+ const id = this.appId(appId);
54
+ const timeStamp = WechatPayUtil.timestamp();
55
+ const nonceStr = WechatPayUtil.nonce();
56
+ const pkg = `prepay_id=${prepayId}`;
57
+ const paySign = WechatPayUtil.signMessage(WechatPayUtil.message(id, timeStamp, nonceStr, pkg), this.key());
58
+ return { appId: id, timeStamp, nonceStr, package: pkg, signType: 'RSA', paySign };
59
+ }
60
+ appParams(prepayId, appId) {
61
+ const id = this.appId(appId);
62
+ const timestamp = WechatPayUtil.timestamp();
63
+ const noncestr = WechatPayUtil.nonce();
64
+ const sign = WechatPayUtil.signMessage(WechatPayUtil.message(id, timestamp, noncestr, prepayId), this.key());
65
+ return { appid: id, partnerid: this.config().mchId, prepayid: prepayId, package: 'Sign=WXPay', noncestr, timestamp, sign };
66
+ }
67
+ async queryOrder(query) {
68
+ const path = 'transaction_id' in query
69
+ ? `/v3/pay/transactions/id/${encodeURIComponent(query.transaction_id)}`
70
+ : `/v3/pay/transactions/out-trade-no/${encodeURIComponent(query.out_trade_no)}`;
71
+ return this.request('GET', path, undefined, { query: { mchid: this.config().mchId } });
72
+ }
73
+ async closeOrder(outTradeNo) {
74
+ await this.request('POST', `/v3/pay/transactions/out-trade-no/${encodeURIComponent(outTradeNo)}/close`, { mchid: this.config().mchId });
75
+ }
76
+ async refund(request) {
77
+ var _a;
78
+ var _b;
79
+ const notifyUrl = (_b = request.notify_url) !== null && _b !== void 0 ? _b : (_a = this.options) === null || _a === void 0 ? void 0 : _a.notifyUrl;
80
+ return this.request('POST', '/v3/refund/domestic/refunds', notifyUrl ? { ...request, notify_url: notifyUrl } : request);
81
+ }
82
+ async queryRefund(outRefundNo) {
83
+ return this.request('GET', `/v3/refund/domestic/refunds/${encodeURIComponent(outRefundNo)}`);
84
+ }
85
+ async tradeBill(query) {
86
+ return this.request('GET', '/v3/bill/tradebill', undefined, { query: { ...query } });
87
+ }
88
+ async fundFlowBill(query) {
89
+ return this.request('GET', '/v3/bill/fundflowbill', undefined, { query: { ...query } });
90
+ }
91
+ async download(url) {
92
+ const target = new URL(url);
93
+ const response = await this.send(target, 'GET', '', {});
94
+ if (!response.ok) {
95
+ throw this.apiError('GET', target, response.status, await response.text());
96
+ }
97
+ return new Uint8Array(await response.arrayBuffer());
98
+ }
99
+ async parseNotification(headers, body) {
100
+ var _a;
101
+ var _b;
102
+ const config = this.config();
103
+ const text = typeof body === 'string' ? body : Buffer.from(body).toString('utf8');
104
+ const time = Number(WechatPayUtil.header(headers, 'Wechatpay-Timestamp'));
105
+ const tolerance = (_b = (_a = config.notification) === null || _a === void 0 ? void 0 : _a.tolerance) !== null && _b !== void 0 ? _b : 300;
106
+ if (!Number.isFinite(time) || Math.abs(Date.now() / 1000 - time) > tolerance) {
107
+ throw new WechatPayError({
108
+ code: 'CELL_WECHAT_PAY_TIMESTAMP_EXPIRED',
109
+ message: `The timestamp of the notification (${WechatPayUtil.header(headers, 'Wechatpay-Timestamp')}) is more than ${tolerance} s away from the clock.`,
110
+ hint: 'Synchronize the clock of the server (NTP); a replayed notification is refused on purpose. wechatPay.notification.tolerance sets the window.',
111
+ });
112
+ }
113
+ await this.verify(headers, text, true);
114
+ const notification = JSON.parse(text);
115
+ return { ...notification, resource: JSON.parse(WechatPayUtil.decrypt(notification.resource, config.apiV3Key)) };
116
+ }
117
+ /** The configuration; throws when the merchant is not configured. */
118
+ config() {
119
+ const options = this.options;
120
+ const missing = ['mchId', 'serialNo', 'privateKey', 'apiV3Key'].filter(key => !(options === null || options === void 0 ? void 0 : options[key]));
121
+ if (missing.length) {
122
+ throw new WechatPayError({
123
+ code: 'CELL_WECHAT_PAY_NOT_CONFIGURED',
124
+ message: `wechatPay is missing ${missing.join(', ')}.`,
125
+ hint: 'Set them under wechatPay in cell.yml, from the environment: privateKey: ${env.WECHAT_PAY_PRIVATE_KEY}.',
126
+ });
127
+ }
128
+ return options;
129
+ }
130
+ key() {
131
+ var _a;
132
+ (_a = this.privateKey) !== null && _a !== void 0 ? _a : (this.privateKey = WechatPayUtil.privateKey(this.config().privateKey));
133
+ return this.privateKey;
134
+ }
135
+ appId(appId) {
136
+ var _a;
137
+ const id = appId !== null && appId !== void 0 ? appId : (_a = this.options) === null || _a === void 0 ? void 0 : _a.appId;
138
+ if (!id) {
139
+ throw new WechatPayError({
140
+ code: 'CELL_WECHAT_PAY_NOT_CONFIGURED',
141
+ message: 'No AppID for the payment.',
142
+ hint: 'Set wechatPay.appId, or pass the AppID of the order.',
143
+ });
144
+ }
145
+ return id;
146
+ }
147
+ order(order) {
148
+ var _a, _b, _c;
149
+ const config = this.config();
150
+ return { ...order, appid: (_a = order.appid) !== null && _a !== void 0 ? _a : this.appId(), mchid: (_b = order.mchid) !== null && _b !== void 0 ? _b : config.mchId, notify_url: (_c = order.notify_url) !== null && _c !== void 0 ? _c : config.notifyUrl };
151
+ }
152
+ send(url, method, body, headers) {
153
+ var _a;
154
+ const config = this.config();
155
+ const authorization = WechatPayUtil.authorization({
156
+ mchId: config.mchId,
157
+ serialNo: config.serialNo,
158
+ privateKey: this.key(),
159
+ method,
160
+ url: url.pathname + url.search,
161
+ body,
162
+ });
163
+ return fetch(url, {
164
+ method,
165
+ body: body || undefined,
166
+ headers: { Accept: 'application/json', 'User-Agent': 'celljs-wechat-pay', Authorization: authorization, ...headers },
167
+ signal: AbortSignal.timeout((_a = config.timeout) !== null && _a !== void 0 ? _a : 10000),
168
+ });
169
+ }
170
+ apiError(method, url, status, answer) {
171
+ var _a, _b;
172
+ let detail;
173
+ try {
174
+ detail = JSON.parse(answer);
175
+ }
176
+ catch (_c) {
177
+ detail = { message: answer };
178
+ }
179
+ return new WechatPayError({
180
+ code: 'CELL_WECHAT_PAY_API_ERROR',
181
+ message: `WeChat Pay answered ${status} to ${method} ${url.pathname}: ${(_a = detail === null || detail === void 0 ? void 0 : detail.code) !== null && _a !== void 0 ? _a : ''} ${(_b = detail === null || detail === void 0 ? void 0 : detail.message) !== null && _b !== void 0 ? _b : ''}`.trim(),
182
+ hint: "detail.code is WeChat Pay's error code; look it up in the documentation of the API (pay.weixin.qq.com/doc/v3).",
183
+ status,
184
+ detail,
185
+ });
186
+ }
187
+ /** Checks `Wechatpay-Signature` over timestamp, nonce and body with the key `Wechatpay-Serial` names. */
188
+ async verify(headers, body, notification) {
189
+ const signature = WechatPayUtil.header(headers, 'Wechatpay-Signature');
190
+ const serial = WechatPayUtil.header(headers, 'Wechatpay-Serial');
191
+ const time = WechatPayUtil.header(headers, 'Wechatpay-Timestamp');
192
+ const nonce = WechatPayUtil.header(headers, 'Wechatpay-Nonce');
193
+ if (!signature || !serial || !time || !nonce) {
194
+ throw this.invalidSignature(`The ${notification ? 'notification' : 'response'} has no Wechatpay-Signature, -Serial, -Timestamp or -Nonce header.`);
195
+ }
196
+ const key = await this.verifyKey(serial);
197
+ if (!WechatPayUtil.verifyMessage(WechatPayUtil.message(time, nonce, body), signature, key)) {
198
+ throw this.invalidSignature(`The signature of the ${notification ? 'notification' : 'response'} does not match (serial ${serial}).`);
199
+ }
200
+ }
201
+ invalidSignature(message) {
202
+ return new WechatPayError({
203
+ code: 'CELL_WECHAT_PAY_SIGNATURE_INVALID',
204
+ message,
205
+ hint: 'Check wechatPay.publicKey (or the platform certificates); a request that does not come from WeChat Pay is refused on purpose.',
206
+ });
207
+ }
208
+ async verifyKey(serial) {
209
+ var _a, _b;
210
+ const keys = this.keys();
211
+ let key = (_a = keys.get(serial)) !== null && _a !== void 0 ? _a : keys.get(serial.toUpperCase());
212
+ if (!key && !serial.startsWith(PUBLIC_KEY_PREFIX) && Date.now() - this.downloadedAt > DOWNLOAD_INTERVAL) {
213
+ (_b = this.downloading) !== null && _b !== void 0 ? _b : (this.downloading = this.downloadCertificates().finally(() => {
214
+ this.downloading = undefined;
215
+ }));
216
+ await this.downloading;
217
+ key = keys.get(serial.toUpperCase());
218
+ }
219
+ if (!key) {
220
+ throw new WechatPayError({
221
+ code: 'CELL_WECHAT_PAY_UNKNOWN_SERIAL',
222
+ message: `No WeChat Pay public key or platform certificate with the serial ${serial}.`,
223
+ hint: serial.startsWith(PUBLIC_KEY_PREFIX)
224
+ ? 'Set wechatPay.publicKeyId and publicKey to the WeChat Pay public key (商户平台 > 账户中心 > API 安全 > 微信支付公钥).'
225
+ : "Set wechatPay.publicKey / publicKeyId, or check that the platform certificates can be downloaded with the merchant's credentials.",
226
+ });
227
+ }
228
+ return key;
229
+ }
230
+ keys() {
231
+ var _a;
232
+ if (!this.verifyKeys) {
233
+ const config = this.config();
234
+ this.verifyKeys = new Map();
235
+ if (config.publicKey) {
236
+ this.verifyKeys.set((_a = config.publicKeyId) !== null && _a !== void 0 ? _a : PUBLIC_KEY_PREFIX, WechatPayUtil.publicKey(config.publicKey));
237
+ }
238
+ const certificates = config.platformCertificates;
239
+ for (const pem of certificates === undefined ? [] : Array.isArray(certificates) ? certificates : [certificates]) {
240
+ this.addCertificate(pem);
241
+ }
242
+ }
243
+ return this.verifyKeys;
244
+ }
245
+ addCertificate(pem) {
246
+ const certificate = new X509Certificate(WechatPayUtil.content(pem));
247
+ this.keys().set(certificate.serialNumber.toUpperCase(), certificate.publicKey);
248
+ }
249
+ /** Downloads the platform certificates; their own response is verified with the certificates it brings. */
250
+ async downloadCertificates() {
251
+ var _a;
252
+ this.downloadedAt = Date.now();
253
+ const url = new URL('/v3/certificates', (_a = this.config().baseUrl) !== null && _a !== void 0 ? _a : 'https://api.mch.weixin.qq.com');
254
+ const response = await this.send(url, 'GET', '', {});
255
+ const answer = await response.text();
256
+ if (!response.ok) {
257
+ throw this.apiError('GET', url, response.status, answer);
258
+ }
259
+ const { data } = JSON.parse(answer);
260
+ for (const item of data) {
261
+ this.addCertificate(WechatPayUtil.decrypt(item.encrypt_certificate, this.config().apiV3Key));
262
+ }
263
+ await this.verify(response.headers, answer, false);
264
+ }
265
+ };
266
+ __decorate([
267
+ Value('wechatPay'),
268
+ __metadata("design:type", Object)
269
+ ], WechatPayClientImpl.prototype, "options", void 0);
270
+ WechatPayClientImpl = __decorate([
271
+ Component(WechatPayClient)
272
+ ], WechatPayClientImpl);
273
+ export { WechatPayClientImpl };
274
+ //# sourceMappingURL=wechat-pay-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wechat-pay-client.js","sourceRoot":"","sources":["../../src/node/wechat-pay-client.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAGH,eAAe,GAelB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,iBAAiB,GAAG,aAAa,CAAC;AACxC,qGAAqG;AACrG,MAAM,iBAAiB,GAAG,KAAM,CAAC;AAG1B,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QAOO,iBAAY,GAAG,CAAC,CAAC;IAqQ/B,CAAC;IAlQG,KAAK,CAAC,OAAO,CAAU,MAA2B,EAAE,IAAY,EAAE,IAAa,EAAE,OAAO,GAA4B,EAAE;;QAClH,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,QAAE,MAAM,CAAC,OAAO,mCAAI,+BAA+B,CAAC,CAAC;QAC7E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,O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