@vobs/payment 0.3.0 → 1.2.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 (178) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +182 -0
  3. package/dist/alipay/client.cjs +112 -0
  4. package/dist/alipay/client.cjs.map +1 -0
  5. package/dist/alipay/client.d.cts +36 -0
  6. package/dist/alipay/client.d.ts +36 -0
  7. package/dist/alipay/client.js +110 -0
  8. package/dist/alipay/client.js.map +1 -0
  9. package/dist/alipay/config.cjs +67 -0
  10. package/dist/alipay/config.cjs.map +1 -0
  11. package/dist/alipay/config.d.cts +30 -0
  12. package/dist/alipay/config.d.ts +30 -0
  13. package/dist/alipay/config.js +65 -0
  14. package/dist/alipay/config.js.map +1 -0
  15. package/dist/alipay/index.cjs +592 -0
  16. package/dist/alipay/index.cjs.map +1 -0
  17. package/dist/alipay/index.d.cts +12 -0
  18. package/dist/alipay/index.d.ts +12 -0
  19. package/dist/alipay/index.js +580 -0
  20. package/dist/alipay/index.js.map +1 -0
  21. package/dist/alipay/notify.cjs +70 -0
  22. package/dist/alipay/notify.cjs.map +1 -0
  23. package/dist/alipay/notify.d.cts +52 -0
  24. package/dist/alipay/notify.d.ts +52 -0
  25. package/dist/alipay/notify.js +68 -0
  26. package/dist/alipay/notify.js.map +1 -0
  27. package/dist/alipay/payment.cjs +49 -0
  28. package/dist/alipay/payment.cjs.map +1 -0
  29. package/dist/alipay/payment.d.cts +24 -0
  30. package/dist/alipay/payment.d.ts +24 -0
  31. package/dist/alipay/payment.js +47 -0
  32. package/dist/alipay/payment.js.map +1 -0
  33. package/dist/alipay/plugin.cjs +300 -0
  34. package/dist/alipay/plugin.cjs.map +1 -0
  35. package/dist/alipay/plugin.d.cts +43 -0
  36. package/dist/alipay/plugin.d.ts +43 -0
  37. package/dist/alipay/plugin.js +296 -0
  38. package/dist/alipay/plugin.js.map +1 -0
  39. package/dist/alipay/query.cjs +80 -0
  40. package/dist/alipay/query.cjs.map +1 -0
  41. package/dist/alipay/query.d.cts +26 -0
  42. package/dist/alipay/query.d.ts +26 -0
  43. package/dist/alipay/query.js +78 -0
  44. package/dist/alipay/query.js.map +1 -0
  45. package/dist/alipay/refund.cjs +104 -0
  46. package/dist/alipay/refund.cjs.map +1 -0
  47. package/dist/alipay/refund.d.cts +32 -0
  48. package/dist/alipay/refund.d.ts +32 -0
  49. package/dist/alipay/refund.js +102 -0
  50. package/dist/alipay/refund.js.map +1 -0
  51. package/dist/alipay/response.cjs +38 -0
  52. package/dist/alipay/response.cjs.map +1 -0
  53. package/dist/alipay/response.d.cts +19 -0
  54. package/dist/alipay/response.d.ts +19 -0
  55. package/dist/alipay/response.js +35 -0
  56. package/dist/alipay/response.js.map +1 -0
  57. package/dist/alipay/types.cjs +4 -0
  58. package/dist/alipay/types.cjs.map +1 -0
  59. package/dist/alipay/types.d.cts +242 -0
  60. package/dist/alipay/types.d.ts +242 -0
  61. package/dist/alipay/types.js +3 -0
  62. package/dist/alipay/types.js.map +1 -0
  63. package/dist/alipay/wap.cjs +50 -0
  64. package/dist/alipay/wap.cjs.map +1 -0
  65. package/dist/alipay/wap.d.cts +24 -0
  66. package/dist/alipay/wap.d.ts +24 -0
  67. package/dist/alipay/wap.js +48 -0
  68. package/dist/alipay/wap.js.map +1 -0
  69. package/dist/index-B1aUR7Vt.d.ts +49 -0
  70. package/dist/index-B8pzZxGq.d.cts +44 -0
  71. package/dist/index-BWnIrwRi.d.ts +44 -0
  72. package/dist/index-Dyrkl86r.d.cts +49 -0
  73. package/dist/index.cjs +1071 -0
  74. package/dist/index.cjs.map +1 -0
  75. package/dist/index.d.cts +23 -0
  76. package/dist/index.d.ts +23 -37
  77. package/dist/index.js +1052 -37
  78. package/dist/index.js.map +1 -0
  79. package/dist/wechat/client.cjs +119 -0
  80. package/dist/wechat/client.cjs.map +1 -0
  81. package/dist/wechat/client.d.cts +39 -0
  82. package/dist/wechat/client.d.ts +39 -0
  83. package/dist/wechat/client.js +117 -0
  84. package/dist/wechat/client.js.map +1 -0
  85. package/dist/wechat/config.cjs +76 -0
  86. package/dist/wechat/config.cjs.map +1 -0
  87. package/dist/wechat/config.d.cts +29 -0
  88. package/dist/wechat/config.d.ts +29 -0
  89. package/dist/wechat/config.js +74 -0
  90. package/dist/wechat/config.js.map +1 -0
  91. package/dist/wechat/index.cjs +612 -0
  92. package/dist/wechat/index.cjs.map +1 -0
  93. package/dist/wechat/index.d.cts +10 -0
  94. package/dist/wechat/index.d.ts +10 -0
  95. package/dist/wechat/index.js +602 -0
  96. package/dist/wechat/index.js.map +1 -0
  97. package/dist/wechat/notify.cjs +73 -0
  98. package/dist/wechat/notify.cjs.map +1 -0
  99. package/dist/wechat/notify.d.cts +53 -0
  100. package/dist/wechat/notify.d.ts +53 -0
  101. package/dist/wechat/notify.js +71 -0
  102. package/dist/wechat/notify.js.map +1 -0
  103. package/dist/wechat/payment.cjs +186 -0
  104. package/dist/wechat/payment.cjs.map +1 -0
  105. package/dist/wechat/payment.d.cts +50 -0
  106. package/dist/wechat/payment.d.ts +50 -0
  107. package/dist/wechat/payment.js +184 -0
  108. package/dist/wechat/payment.js.map +1 -0
  109. package/dist/wechat/plugin.cjs +305 -0
  110. package/dist/wechat/plugin.cjs.map +1 -0
  111. package/dist/wechat/plugin.d.cts +40 -0
  112. package/dist/wechat/plugin.d.ts +40 -0
  113. package/dist/wechat/plugin.js +301 -0
  114. package/dist/wechat/plugin.js.map +1 -0
  115. package/dist/wechat/refund.cjs +112 -0
  116. package/dist/wechat/refund.cjs.map +1 -0
  117. package/dist/wechat/refund.d.cts +26 -0
  118. package/dist/wechat/refund.d.ts +26 -0
  119. package/dist/wechat/refund.js +110 -0
  120. package/dist/wechat/refund.js.map +1 -0
  121. package/dist/wechat/response.cjs +50 -0
  122. package/dist/wechat/response.cjs.map +1 -0
  123. package/dist/wechat/response.d.cts +20 -0
  124. package/dist/wechat/response.d.ts +20 -0
  125. package/dist/wechat/response.js +46 -0
  126. package/dist/wechat/response.js.map +1 -0
  127. package/dist/wechat/types.cjs +4 -0
  128. package/dist/wechat/types.cjs.map +1 -0
  129. package/dist/wechat/types.d.cts +200 -0
  130. package/dist/wechat/types.d.ts +200 -0
  131. package/dist/wechat/types.js +3 -0
  132. package/dist/wechat/types.js.map +1 -0
  133. package/package.json +37 -28
  134. package/src/alipay/alipay.test.ts +231 -0
  135. package/src/alipay/client.ts +67 -0
  136. package/src/alipay/config.ts +72 -0
  137. package/src/alipay/index.ts +32 -0
  138. package/src/alipay/notify.ts +92 -0
  139. package/src/alipay/payment.ts +60 -0
  140. package/src/alipay/plugin.ts +64 -0
  141. package/src/alipay/query.ts +52 -0
  142. package/src/alipay/refund.ts +85 -0
  143. package/src/alipay/response.ts +40 -0
  144. package/src/alipay/types.ts +271 -0
  145. package/src/alipay/wap.ts +55 -0
  146. package/src/index.ts +78 -0
  147. package/src/wechat/client.ts +68 -0
  148. package/src/wechat/config.ts +81 -0
  149. package/src/wechat/index.ts +30 -0
  150. package/src/wechat/notify.ts +93 -0
  151. package/src/wechat/payment.ts +177 -0
  152. package/src/wechat/plugin.ts +59 -0
  153. package/src/wechat/refund.ts +80 -0
  154. package/src/wechat/response.ts +54 -0
  155. package/src/wechat/types.ts +223 -0
  156. package/src/wechat/wechat.test.ts +393 -0
  157. package/dist/alipay-official.d.ts +0 -34
  158. package/dist/alipay-official.js +0 -206
  159. package/dist/handlers.d.ts +0 -45
  160. package/dist/handlers.js +0 -105
  161. package/dist/jeepay.d.ts +0 -39
  162. package/dist/jeepay.js +0 -206
  163. package/dist/lakala.d.ts +0 -41
  164. package/dist/lakala.js +0 -243
  165. package/dist/manager.d.ts +0 -67
  166. package/dist/manager.js +0 -538
  167. package/dist/mock-driver.d.ts +0 -22
  168. package/dist/mock-driver.js +0 -59
  169. package/dist/state-machine.d.ts +0 -41
  170. package/dist/state-machine.js +0 -60
  171. package/dist/store.d.ts +0 -33
  172. package/dist/store.js +0 -76
  173. package/dist/types.d.ts +0 -168
  174. package/dist/types.js +0 -11
  175. package/dist/verify.d.ts +0 -34
  176. package/dist/verify.js +0 -55
  177. package/dist/wechat-official.d.ts +0 -40
  178. package/dist/wechat-official.js +0 -208
package/dist/index.cjs ADDED
@@ -0,0 +1,1071 @@
1
+ 'use strict';
2
+
3
+ var alipaySdk = require('alipay-sdk');
4
+ var wechatpayAxiosPlugin = require('wechatpay-axios-plugin');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+
13
+ // packages/payment/src/alipay/index.ts
14
+ var alipay_exports = {};
15
+ __export(alipay_exports, {
16
+ ALIPAY_KEY: () => ALIPAY_KEY,
17
+ AlipayApiError: () => AlipayApiError,
18
+ AlipayClient: () => AlipayClient,
19
+ AlipayConfig: () => AlipayConfig,
20
+ alipayPlugin: () => alipayPlugin,
21
+ createNotifyHandler: () => createNotifyHandler,
22
+ createPagePay: () => createPagePay,
23
+ createQuery: () => createQuery,
24
+ createRefund: () => createRefund,
25
+ createWapPay: () => createWapPay,
26
+ useAlipay: () => useAlipay
27
+ });
28
+
29
+ // packages/payment/src/alipay/config.ts
30
+ var _AlipayConfig = class _AlipayConfig {
31
+ constructor(options) {
32
+ this.validate(options);
33
+ this._options = { ...options };
34
+ }
35
+ /** 获取完整配置 */
36
+ get options() {
37
+ return this._options;
38
+ }
39
+ /** 应用 ID */
40
+ get appId() {
41
+ return this._options.appId;
42
+ }
43
+ /** 网关地址 */
44
+ get gateway() {
45
+ return this._options.gateway ?? "https://openapi.alipay.com/gateway.do";
46
+ }
47
+ /** 异步通知地址 */
48
+ get notifyUrl() {
49
+ return this._options.notifyUrl;
50
+ }
51
+ /** 同步跳转地址 */
52
+ get returnUrl() {
53
+ return this._options.returnUrl;
54
+ }
55
+ /** 更新配置(部分更新) */
56
+ update(patch) {
57
+ const merged = { ...this._options, ...patch };
58
+ this.validate(merged);
59
+ this._options = merged;
60
+ }
61
+ /** 替换配置 */
62
+ replace(options) {
63
+ this.validate(options);
64
+ this._options = { ...options };
65
+ }
66
+ /** 创建沙箱配置的快捷方法 */
67
+ static forSandbox(options) {
68
+ return new _AlipayConfig({
69
+ ...options,
70
+ gateway: "https://openapi-sandbox.dl.alipaydev.com/gateway.do"
71
+ });
72
+ }
73
+ validate(options) {
74
+ if (!options.appId) {
75
+ throw new Error("AlipayConfig: appId \u4E0D\u80FD\u4E3A\u7A7A");
76
+ }
77
+ if (!options.privateKey) {
78
+ throw new Error("AlipayConfig: privateKey \u4E0D\u80FD\u4E3A\u7A7A");
79
+ }
80
+ if (!options.alipayPublicKey) {
81
+ throw new Error("AlipayConfig: alipayPublicKey \u4E0D\u80FD\u4E3A\u7A7A");
82
+ }
83
+ }
84
+ };
85
+ __name(_AlipayConfig, "AlipayConfig");
86
+ var AlipayConfig = _AlipayConfig;
87
+
88
+ // packages/payment/src/alipay/client.ts
89
+ var _AlipayClient = class _AlipayClient {
90
+ constructor(options) {
91
+ this._disposed = false;
92
+ this.config = new AlipayConfig(options);
93
+ this._sdk = this.createSdk(options);
94
+ }
95
+ /** 获取底层 AlipaySdk 实例 */
96
+ get sdk() {
97
+ this.ensureActive();
98
+ return this._sdk;
99
+ }
100
+ /** 更新配置并重建 SDK 实例 */
101
+ updateConfig(patch) {
102
+ this.ensureActive();
103
+ this.config.update(patch);
104
+ this._sdk = this.createSdk(this.config.options);
105
+ }
106
+ /** 销毁客户端 */
107
+ dispose() {
108
+ this._disposed = true;
109
+ this._sdk = null;
110
+ }
111
+ createSdk(options) {
112
+ return new alipaySdk.AlipaySdk({
113
+ appId: options.appId,
114
+ privateKey: options.privateKey,
115
+ alipayPublicKey: options.alipayPublicKey,
116
+ signType: options.signType ?? "RSA2",
117
+ gateway: options.gateway,
118
+ timeout: options.timeout ?? 5e3,
119
+ keyType: options.keyType ?? "PKCS1"
120
+ });
121
+ }
122
+ ensureActive() {
123
+ if (this._disposed) {
124
+ throw new Error("AlipayClient: \u5BA2\u6237\u7AEF\u5DF2\u9500\u6BC1");
125
+ }
126
+ }
127
+ };
128
+ __name(_AlipayClient, "AlipayClient");
129
+ var AlipayClient = _AlipayClient;
130
+
131
+ // packages/payment/src/alipay/response.ts
132
+ var _AlipayApiError = class _AlipayApiError extends Error {
133
+ constructor(apiName, code, subCode, subMsg, msg) {
134
+ super(`\u652F\u4ED8\u5B9D\u63A5\u53E3 ${apiName} \u8C03\u7528\u5931\u8D25: ${subMsg ?? msg ?? "\u672A\u77E5\u9519\u8BEF"} (code=${code}${subCode ? `, sub_code=${subCode}` : ""})`);
135
+ this.name = "AlipayApiError";
136
+ this.code = code;
137
+ this.subCode = subCode;
138
+ this.subMsg = subMsg;
139
+ }
140
+ };
141
+ __name(_AlipayApiError, "AlipayApiError");
142
+ var AlipayApiError = _AlipayApiError;
143
+ function toResponseKey(apiName) {
144
+ return `${apiName.replace(/\./g, "_")}_response`;
145
+ }
146
+ __name(toResponseKey, "toResponseKey");
147
+ function unwrapResponse(raw, apiName) {
148
+ const outer = raw;
149
+ const body = (outer && outer[toResponseKey(apiName)]) ?? outer;
150
+ if (!body || typeof body !== "object") {
151
+ throw new AlipayApiError(apiName, "INVALID_RESPONSE", void 0, void 0, "\u54CD\u5E94\u4F53\u683C\u5F0F\u5F02\u5E38");
152
+ }
153
+ if (body.code !== "10000") {
154
+ throw new AlipayApiError(apiName, body.code, body.sub_code, body.sub_msg, body.msg);
155
+ }
156
+ return body;
157
+ }
158
+ __name(unwrapResponse, "unwrapResponse");
159
+
160
+ // packages/payment/src/alipay/payment.ts
161
+ function createPagePay(client) {
162
+ return {
163
+ /**
164
+ * 发起电脑网站支付
165
+ * @param config 支付配置
166
+ * @returns 支付表单 HTML
167
+ */
168
+ async pay(config) {
169
+ const { outTradeNo, totalAmount, subject, body, passbackParams } = config;
170
+ const bizParams = {
171
+ outTradeNo,
172
+ totalAmount,
173
+ subject,
174
+ productCode: "FAST_INSTANT_TRADE_PAY",
175
+ body,
176
+ passbackParams,
177
+ returnUrl: client.config.returnUrl,
178
+ notifyUrl: client.config.notifyUrl
179
+ };
180
+ const formHtml = client.sdk.pageExecute(
181
+ "alipay.trade.page.pay",
182
+ "POST",
183
+ { bizContent: sanitizeParams(bizParams) }
184
+ );
185
+ return { formHtml };
186
+ }
187
+ };
188
+ }
189
+ __name(createPagePay, "createPagePay");
190
+ function sanitizeParams(params) {
191
+ const result = {};
192
+ for (const [key, value] of Object.entries(params)) {
193
+ if (value !== void 0 && value !== null) {
194
+ result[key] = value;
195
+ }
196
+ }
197
+ return result;
198
+ }
199
+ __name(sanitizeParams, "sanitizeParams");
200
+
201
+ // packages/payment/src/alipay/wap.ts
202
+ function createWapPay(client) {
203
+ return {
204
+ /**
205
+ * 发起手机网站支付
206
+ * @param config 支付配置
207
+ * @returns 支付表单 HTML
208
+ */
209
+ async pay(config) {
210
+ const { outTradeNo, totalAmount, subject, body, passbackParams, quitUrl } = config;
211
+ const bizParams = {
212
+ outTradeNo,
213
+ totalAmount,
214
+ subject,
215
+ productCode: "QUICK_WAP_WAY",
216
+ body,
217
+ passbackParams,
218
+ quitUrl,
219
+ returnUrl: client.config.returnUrl,
220
+ notifyUrl: client.config.notifyUrl
221
+ };
222
+ const formHtml = client.sdk.pageExecute(
223
+ "alipay.trade.wap.pay",
224
+ "POST",
225
+ { bizContent: sanitizeParams2(bizParams) }
226
+ );
227
+ return { formHtml };
228
+ }
229
+ };
230
+ }
231
+ __name(createWapPay, "createWapPay");
232
+ function sanitizeParams2(params) {
233
+ const result = {};
234
+ for (const [key, value] of Object.entries(params)) {
235
+ if (value !== void 0 && value !== null) {
236
+ result[key] = value;
237
+ }
238
+ }
239
+ return result;
240
+ }
241
+ __name(sanitizeParams2, "sanitizeParams");
242
+
243
+ // packages/payment/src/alipay/query.ts
244
+ function createQuery(client) {
245
+ return {
246
+ /**
247
+ * 查询交易状态
248
+ * @param params 查询参数(outTradeNo 和 tradeNo 至少传一个)
249
+ * @throws {AlipayApiError} 业务失败(如 ACQ.TRADE_NOT_EXIST)时抛出
250
+ */
251
+ async query(params) {
252
+ const alipayResponse = unwrapResponse(
253
+ await client.sdk.exec("alipay.trade.query", {
254
+ bizContent: params
255
+ }),
256
+ "alipay.trade.query"
257
+ );
258
+ return {
259
+ tradeNo: alipayResponse.trade_no,
260
+ outTradeNo: alipayResponse.out_trade_no,
261
+ buyerLogonId: alipayResponse.buyer_logon_id,
262
+ tradeStatus: alipayResponse.trade_status,
263
+ totalAmount: alipayResponse.total_amount,
264
+ receiptAmount: alipayResponse.receipt_amount ?? "0.00",
265
+ buyerPayAmount: alipayResponse.buyer_pay_amount ?? "0.00",
266
+ sendPayDate: alipayResponse.send_pay_date ?? "",
267
+ gmtPayment: alipayResponse.gmt_payment ?? null,
268
+ gmtClose: alipayResponse.gmt_close ?? null,
269
+ refundAmount: alipayResponse.refund_amount ?? "0.00",
270
+ subject: alipayResponse.subject ?? "",
271
+ passbackParams: alipayResponse.passback_params ?? null,
272
+ fundChannel: alipayResponse.fund_channel ?? null
273
+ };
274
+ },
275
+ /**
276
+ * 判断交易是否支付成功
277
+ * 只有 TRADE_SUCCESS 或 TRADE_FINISHED 才表示支付成功
278
+ */
279
+ isSuccessful(status) {
280
+ return status === "TRADE_SUCCESS" || status === "TRADE_FINISHED";
281
+ }
282
+ };
283
+ }
284
+ __name(createQuery, "createQuery");
285
+
286
+ // packages/payment/src/alipay/refund.ts
287
+ function createRefund(client) {
288
+ return {
289
+ /**
290
+ * 交易退款 (alipay.trade.refund)
291
+ * 交易发生后 12 个月内可退款,退款资金原路返回。
292
+ * @throws {AlipayApiError} 业务失败时抛出
293
+ */
294
+ async refund(params) {
295
+ const alipayResponse = unwrapResponse(
296
+ await client.sdk.exec("alipay.trade.refund", {
297
+ bizContent: params
298
+ }),
299
+ "alipay.trade.refund"
300
+ );
301
+ return {
302
+ tradeNo: alipayResponse.trade_no,
303
+ outTradeNo: alipayResponse.out_trade_no,
304
+ buyerLogonId: alipayResponse.buyer_logon_id,
305
+ refundAmount: alipayResponse.refund_fee,
306
+ fundChange: alipayResponse.fund_change ?? "N",
307
+ gmtRefundPay: alipayResponse.gmt_refund_pay ?? "",
308
+ refundDetailItemList: alipayResponse.refund_detail_item_list ?? null
309
+ };
310
+ },
311
+ /**
312
+ * 退款查询 (alipay.trade.fastpay.refund.query)
313
+ * 查询退款状态,确认退款是否成功。
314
+ * @throws {AlipayApiError} 业务失败时抛出
315
+ */
316
+ async queryRefund(params) {
317
+ const alipayResponse = unwrapResponse(
318
+ await client.sdk.exec("alipay.trade.fastpay.refund.query", {
319
+ bizContent: params
320
+ }),
321
+ "alipay.trade.fastpay.refund.query"
322
+ );
323
+ return {
324
+ tradeNo: alipayResponse.trade_no,
325
+ outTradeNo: alipayResponse.out_trade_no,
326
+ refundAmount: alipayResponse.refund_amount,
327
+ refundStatus: alipayResponse.refund_status,
328
+ outRequestNo: alipayResponse.out_request_no,
329
+ refundReason: alipayResponse.refund_reason ?? ""
330
+ };
331
+ },
332
+ /**
333
+ * 关闭交易 (alipay.trade.close)
334
+ * 关闭未支付的订单。
335
+ * @throws {AlipayApiError} 业务失败时抛出
336
+ */
337
+ async close(params) {
338
+ const alipayResponse = unwrapResponse(
339
+ await client.sdk.exec("alipay.trade.close", {
340
+ bizContent: params
341
+ }),
342
+ "alipay.trade.close"
343
+ );
344
+ return {
345
+ tradeNo: alipayResponse.trade_no,
346
+ outTradeNo: alipayResponse.out_trade_no
347
+ };
348
+ }
349
+ };
350
+ }
351
+ __name(createRefund, "createRefund");
352
+
353
+ // packages/payment/src/alipay/notify.ts
354
+ function createNotifyHandler(client) {
355
+ return {
356
+ /**
357
+ * 验签异步通知
358
+ * @param params 异步通知参数(支付宝 POST 过来的原始参数)
359
+ * @param raw 使用原始报文验签(推荐:v4.15+ 支持,规避 encodeURIComponent 差异导致的验签失败)
360
+ * @returns 验签是否通过
361
+ */
362
+ verify(params, raw = false) {
363
+ try {
364
+ return client.sdk.checkNotifySign(params, raw);
365
+ } catch {
366
+ return false;
367
+ }
368
+ },
369
+ /**
370
+ * 校验异步通知的业务字段
371
+ *
372
+ * 验签只保证通知确实来自支付宝,不保证通知与你系统中的订单一致;
373
+ * 因此除了 app_id,还应传入商户侧的期望值(outTradeNo / totalAmount)进行比对。
374
+ * @param params 异步通知参数
375
+ * @param expected 商户侧期望值:outTradeNo 订单号、totalAmount 订单金额(单位元)
376
+ */
377
+ validate(params, expected) {
378
+ const errors = [];
379
+ if (params.appId !== client.config.appId) {
380
+ errors.push(`app_id \u4E0D\u5339\u914D: \u671F\u671B ${client.config.appId}\uFF0C\u6536\u5230 ${params.appId}`);
381
+ }
382
+ if (expected?.outTradeNo && params.outTradeNo !== expected.outTradeNo) {
383
+ errors.push(`out_trade_no \u4E0D\u5339\u914D: \u671F\u671B ${expected.outTradeNo}\uFF0C\u6536\u5230 ${params.outTradeNo}`);
384
+ }
385
+ if (expected?.totalAmount && Number(params.totalAmount) !== Number(expected.totalAmount)) {
386
+ errors.push(`total_amount \u4E0D\u5339\u914D: \u671F\u671B ${expected.totalAmount}\uFF0C\u6536\u5230 ${params.totalAmount}`);
387
+ }
388
+ const validStatuses = ["TRADE_SUCCESS", "TRADE_FINISHED"];
389
+ if (!validStatuses.includes(params.tradeStatus)) {
390
+ errors.push(`trade_status \u975E\u7EC8\u6001: ${params.tradeStatus}`);
391
+ }
392
+ return {
393
+ valid: errors.length === 0,
394
+ errors
395
+ };
396
+ },
397
+ /**
398
+ * 生成支付宝异步通知的成功响应
399
+ * 处理完成后必须返回字符串 "success"
400
+ */
401
+ successResponse() {
402
+ return "success";
403
+ },
404
+ /**
405
+ * 生成支付宝异步通知的失败响应
406
+ * 返回空字符串或非 success 内容,支付宝会重试通知
407
+ */
408
+ failResponse() {
409
+ return "fail";
410
+ }
411
+ };
412
+ }
413
+ __name(createNotifyHandler, "createNotifyHandler");
414
+
415
+ // packages/reactivity/src/debug.ts
416
+ var activeDebugHooks = null;
417
+ function hasDebugHooks() {
418
+ return activeDebugHooks !== null;
419
+ }
420
+ __name(hasDebugHooks, "hasDebugHooks");
421
+ function invokeDebug(name, ...args) {
422
+ return;
423
+ }
424
+ __name(invokeDebug, "invokeDebug");
425
+
426
+ // packages/reactivity/src/owner.ts
427
+ var currentOwner = null;
428
+ function getCurrentOwner() {
429
+ return currentOwner;
430
+ }
431
+ __name(getCurrentOwner, "getCurrentOwner");
432
+
433
+ // packages/reactivity/src/scheduler.ts
434
+ var _Scheduler = class _Scheduler {
435
+ constructor() {
436
+ this.dirtyEffects = /* @__PURE__ */ new Set();
437
+ this.lowPriorityEffects = /* @__PURE__ */ new Set();
438
+ // flush 不可重入(flushing 标志保证),缓冲数组可在轮次间安全复用,避免每轮分配。
439
+ this.normalBuffer = [];
440
+ this.lowBuffer = [];
441
+ this.flushing = false;
442
+ this.scheduled = false;
443
+ this.batchDepth = 0;
444
+ }
445
+ schedule(effect2) {
446
+ if (effect2.disposed) return;
447
+ this.dirtyEffects.add(effect2);
448
+ this.lowPriorityEffects.delete(effect2);
449
+ this.ensureScheduled();
450
+ }
451
+ /** Queue an effect behind normal updates while preserving deterministic order. */
452
+ scheduleLow(effect2) {
453
+ if (effect2.disposed) return;
454
+ if (!this.dirtyEffects.has(effect2)) this.lowPriorityEffects.add(effect2);
455
+ this.ensureScheduled();
456
+ }
457
+ ensureScheduled() {
458
+ if (this.batchDepth === 0 && !this.flushing && !this.scheduled) {
459
+ this.scheduled = true;
460
+ queueMicrotask(() => {
461
+ this.scheduled = false;
462
+ this.flush();
463
+ });
464
+ }
465
+ }
466
+ remove(effect2) {
467
+ this.dirtyEffects.delete(effect2);
468
+ this.lowPriorityEffects.delete(effect2);
469
+ }
470
+ batch(fn) {
471
+ this.batchDepth++;
472
+ try {
473
+ return fn();
474
+ } finally {
475
+ this.batchDepth--;
476
+ if (this.batchDepth === 0) this.flush();
477
+ }
478
+ }
479
+ flush() {
480
+ if (this.flushing || this.batchDepth > 0) return;
481
+ this.flushing = true;
482
+ let rounds = 0;
483
+ let firstError;
484
+ let hasError = false;
485
+ try {
486
+ while (this.dirtyEffects.size > 0 || this.lowPriorityEffects.size > 0) {
487
+ if (++rounds > 100) {
488
+ this.dirtyEffects.clear();
489
+ this.lowPriorityEffects.clear();
490
+ throw new Error("Vobs: \u54CD\u5E94\u5F0F\u66F4\u65B0\u8D85\u8FC7 100 \u8F6E\uFF0C\u53EF\u80FD\u5B58\u5728\u5FAA\u73AF\u4F9D\u8D56");
491
+ }
492
+ this.collectRunnable(this.dirtyEffects, this.normalBuffer);
493
+ this.collectRunnable(this.lowPriorityEffects, this.lowBuffer);
494
+ sortEffects(this.normalBuffer);
495
+ sortEffects(this.lowBuffer);
496
+ for (const effect2 of this.normalBuffer) {
497
+ try {
498
+ effect2.run();
499
+ } catch (error) {
500
+ if (!hasError) {
501
+ firstError = error;
502
+ hasError = true;
503
+ }
504
+ }
505
+ }
506
+ for (const effect2 of this.lowBuffer) {
507
+ try {
508
+ effect2.run();
509
+ } catch (error) {
510
+ if (!hasError) {
511
+ firstError = error;
512
+ hasError = true;
513
+ }
514
+ }
515
+ }
516
+ this.normalBuffer.length = 0;
517
+ this.lowBuffer.length = 0;
518
+ }
519
+ } finally {
520
+ this.normalBuffer.length = 0;
521
+ this.lowBuffer.length = 0;
522
+ this.flushing = false;
523
+ }
524
+ if (hasError) throw firstError;
525
+ }
526
+ /** 收集未 disposed 的 effect 并清空源集合;run() 期间新调度的 effect 留给下一轮。 */
527
+ collectRunnable(source, target) {
528
+ for (const effect2 of source) {
529
+ if (!effect2.disposed) target.push(effect2);
530
+ }
531
+ source.clear();
532
+ }
533
+ };
534
+ __name(_Scheduler, "Scheduler");
535
+ function sortEffects(effects) {
536
+ if (effects.length > 1) {
537
+ effects.sort((a, b) => b.depth - a.depth || a.order - b.order);
538
+ }
539
+ }
540
+ __name(sortEffects, "sortEffects");
541
+
542
+ // packages/runtime/src/hmr.ts
543
+ var globalTarget = globalThis;
544
+ var hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: /* @__PURE__ */ new Map() };
545
+ globalTarget.__VOBS_HMR__ = hmrGlobal;
546
+
547
+ // packages/vobs/src/context.ts
548
+ var ownerProviders = /* @__PURE__ */ new WeakMap();
549
+ function inject(key, fallback) {
550
+ const owner = getCurrentOwner();
551
+ const value = owner ? injectFromOwner(owner, key) : void 0;
552
+ return value === void 0 ? fallback : value;
553
+ }
554
+ __name(inject, "inject");
555
+ function injectFromOwner(owner, key) {
556
+ let current = owner;
557
+ while (current) {
558
+ const providers = ownerProviders.get(current);
559
+ if (providers?.has(key)) return providers.get(key);
560
+ current = current.parent;
561
+ }
562
+ return void 0;
563
+ }
564
+ __name(injectFromOwner, "injectFromOwner");
565
+
566
+ // packages/vobs/src/app.ts
567
+ function createInjectionKey(description) {
568
+ return Symbol(description);
569
+ }
570
+ __name(createInjectionKey, "createInjectionKey");
571
+
572
+ // packages/payment/src/alipay/plugin.ts
573
+ var ALIPAY_KEY = createInjectionKey("vobs.payment.alipay");
574
+ function alipayPlugin(options) {
575
+ return {
576
+ name: "@vobs/payment/alipay",
577
+ version: "0.1.0",
578
+ install(context) {
579
+ if (!options.client && !options.config) {
580
+ throw new Error("Vobs Payment: alipayPlugin \u9700\u8981\u63D0\u4F9B config \u6216 client \u4E4B\u4E00");
581
+ }
582
+ const ownClient = !options.client;
583
+ const client = options.client ?? new AlipayClient(options.config);
584
+ context.provide(ALIPAY_KEY, client);
585
+ return ownClient ? () => client.dispose() : void 0;
586
+ }
587
+ };
588
+ }
589
+ __name(alipayPlugin, "alipayPlugin");
590
+ function useAlipay() {
591
+ const client = inject(ALIPAY_KEY);
592
+ if (!client) {
593
+ throw new Error(
594
+ "Vobs Payment: \u627E\u4E0D\u5230 AlipayClient\uFF0C\u8BF7\u5B89\u88C5 alipayPlugin"
595
+ );
596
+ }
597
+ return client;
598
+ }
599
+ __name(useAlipay, "useAlipay");
600
+
601
+ // packages/payment/src/wechat/index.ts
602
+ var wechat_exports = {};
603
+ __export(wechat_exports, {
604
+ WECHAT_KEY: () => WECHAT_KEY,
605
+ WechatApiError: () => WechatApiError,
606
+ WechatClient: () => WechatClient,
607
+ WechatConfig: () => WechatConfig,
608
+ createNotifyHandler: () => createNotifyHandler2,
609
+ createPayment: () => createPayment,
610
+ createRefund: () => createRefund2,
611
+ useWechat: () => useWechat,
612
+ wechatPlugin: () => wechatPlugin
613
+ });
614
+
615
+ // packages/payment/src/wechat/config.ts
616
+ var _WechatConfig = class _WechatConfig {
617
+ constructor(options) {
618
+ this.validate(options);
619
+ this._options = { ...options };
620
+ }
621
+ /** 获取完整配置 */
622
+ get options() {
623
+ return this._options;
624
+ }
625
+ /** 商户号 */
626
+ get mchid() {
627
+ return this._options.mchid;
628
+ }
629
+ /** 应用 ID(公众号 / 小程序 / APP) */
630
+ get appid() {
631
+ return this._options.appid;
632
+ }
633
+ /** 商户 API 证书序列号 */
634
+ get serial() {
635
+ return this._options.serial;
636
+ }
637
+ /** APIv3 密钥(回调解密用) */
638
+ get apiv3Key() {
639
+ return this._options.apiv3Key;
640
+ }
641
+ /** 异步通知地址 */
642
+ get notifyUrl() {
643
+ return this._options.notifyUrl;
644
+ }
645
+ /** 更新配置(部分更新) */
646
+ update(patch) {
647
+ const merged = { ...this._options, ...patch };
648
+ this.validate(merged);
649
+ this._options = merged;
650
+ }
651
+ /** 替换配置 */
652
+ replace(options) {
653
+ this.validate(options);
654
+ this._options = { ...options };
655
+ }
656
+ validate(options) {
657
+ if (!options.mchid) {
658
+ throw new Error("WechatConfig: mchid \u4E0D\u80FD\u4E3A\u7A7A");
659
+ }
660
+ if (!options.serial) {
661
+ throw new Error("WechatConfig: serial\uFF08\u5546\u6237 API \u8BC1\u4E66\u5E8F\u5217\u53F7\uFF09\u4E0D\u80FD\u4E3A\u7A7A");
662
+ }
663
+ if (!options.privateKey) {
664
+ throw new Error("WechatConfig: privateKey\uFF08\u5546\u6237 API \u79C1\u94A5 PEM\uFF09\u4E0D\u80FD\u4E3A\u7A7A");
665
+ }
666
+ if (!options.certs || Object.keys(options.certs).length === 0) {
667
+ throw new Error("WechatConfig: certs\uFF08\u5E73\u53F0\u8BC1\u4E66/\u5FAE\u4FE1\u652F\u4ED8\u516C\u94A5 {\u5E8F\u5217\u53F7: PEM}\uFF09\u4E0D\u80FD\u4E3A\u7A7A");
668
+ }
669
+ if (!options.appid) {
670
+ throw new Error("WechatConfig: appid \u4E0D\u80FD\u4E3A\u7A7A");
671
+ }
672
+ if (!options.apiv3Key) {
673
+ throw new Error("WechatConfig: apiv3Key \u4E0D\u80FD\u4E3A\u7A7A");
674
+ }
675
+ if (options.apiv3Key.length !== 32) {
676
+ throw new Error("WechatConfig: apiv3Key \u5FC5\u987B\u4E3A 32 \u5B57\u8282\u5B57\u7B26\u4E32");
677
+ }
678
+ }
679
+ };
680
+ __name(_WechatConfig, "WechatConfig");
681
+ var WechatConfig = _WechatConfig;
682
+
683
+ // packages/payment/src/wechat/client.ts
684
+ var _WechatClient = class _WechatClient {
685
+ constructor(options) {
686
+ this._disposed = false;
687
+ this.config = new WechatConfig(options);
688
+ this._sdk = this.createSdk(options);
689
+ }
690
+ /** 获取底层 Wechatpay 实例(链式 API:client.sdk.v3.pay.transactions.jsapi.post(...)) */
691
+ get sdk() {
692
+ this.ensureActive();
693
+ return this._sdk;
694
+ }
695
+ /** 更新配置并重建 SDK 实例 */
696
+ updateConfig(patch) {
697
+ this.ensureActive();
698
+ this.config.update(patch);
699
+ this._sdk = this.createSdk(this.config.options);
700
+ }
701
+ /** 销毁客户端 */
702
+ dispose() {
703
+ this._disposed = true;
704
+ this._sdk = null;
705
+ }
706
+ createSdk(options) {
707
+ return new wechatpayAxiosPlugin.Wechatpay({
708
+ mchid: options.mchid,
709
+ serial: options.serial,
710
+ privateKey: options.privateKey,
711
+ certs: options.certs,
712
+ timeout: options.timeout ?? 5e3
713
+ });
714
+ }
715
+ ensureActive() {
716
+ if (this._disposed) {
717
+ throw new Error("WechatClient: \u5BA2\u6237\u7AEF\u5DF2\u9500\u6BC1");
718
+ }
719
+ }
720
+ };
721
+ __name(_WechatClient, "WechatClient");
722
+ var WechatClient = _WechatClient;
723
+
724
+ // packages/payment/src/wechat/response.ts
725
+ var _WechatApiError = class _WechatApiError extends Error {
726
+ constructor(message, status, code) {
727
+ super(message);
728
+ this.name = "WechatApiError";
729
+ this.status = status;
730
+ this.code = code;
731
+ }
732
+ };
733
+ __name(_WechatApiError, "WechatApiError");
734
+ var WechatApiError = _WechatApiError;
735
+ function toWechatApiError(error) {
736
+ if (error instanceof WechatApiError) return error;
737
+ const axiosError = error;
738
+ const status = axiosError?.response?.status;
739
+ const bizCode = axiosError?.response?.data?.code;
740
+ const bizMessage = axiosError?.response?.data?.message;
741
+ if (status !== void 0) {
742
+ return new WechatApiError(
743
+ `\u5FAE\u4FE1\u652F\u4ED8\u63A5\u53E3\u8C03\u7528\u5931\u8D25: ${bizMessage ?? axiosError?.message ?? "\u672A\u77E5\u9519\u8BEF"} (${status}${bizCode ? `, ${bizCode}` : ""})`,
744
+ status,
745
+ bizCode ?? String(status)
746
+ );
747
+ }
748
+ return new WechatApiError(
749
+ `\u5FAE\u4FE1\u652F\u4ED8\u8BF7\u6C42\u5931\u8D25: ${axiosError?.message ?? "\u672A\u77E5\u9519\u8BEF"}${axiosError?.code ? ` (${axiosError.code})` : ""}`,
750
+ void 0,
751
+ axiosError?.code ?? "NETWORK_ERROR"
752
+ );
753
+ }
754
+ __name(toWechatApiError, "toWechatApiError");
755
+ async function unwrapV3(promise) {
756
+ try {
757
+ return await promise;
758
+ } catch (error) {
759
+ throw toWechatApiError(error);
760
+ }
761
+ }
762
+ __name(unwrapV3, "unwrapV3");
763
+ function createPayment(client) {
764
+ return {
765
+ /**
766
+ * 公众号 / 小程序支付下单(POST /v3/pay/transactions/jsapi)
767
+ * @param params 下单参数,openid 必填
768
+ * @returns 调起 wx.requestPayment 所需的签名参数
769
+ */
770
+ async jsapiPay(params) {
771
+ const { data } = await postTransaction(client, "jsapi", params);
772
+ return buildInvokeParams(client, data.prepay_id ?? "");
773
+ },
774
+ /**
775
+ * APP 支付下单(POST /v3/pay/transactions/app)
776
+ * @param params 下单参数
777
+ * @returns 传给客户端 SDK 调起微信支付的签名参数
778
+ */
779
+ async appPay(params) {
780
+ const { data } = await postTransaction(client, "app", params);
781
+ return buildInvokeParams(client, data.prepay_id ?? "");
782
+ },
783
+ /**
784
+ * Native 扫码支付下单(POST /v3/pay/transactions/native)
785
+ * @returns 二维码链接(前端渲染二维码,用户扫码支付)
786
+ */
787
+ async nativePay(params) {
788
+ const { data } = await postTransaction(client, "native", params);
789
+ if (!data.code_url) {
790
+ throw new Error("WechatClient: \u4E0B\u5355\u54CD\u5E94\u7F3A\u5C11 code_url");
791
+ }
792
+ return { codeUrl: data.code_url };
793
+ },
794
+ /**
795
+ * H5 支付下单(POST /v3/pay/transactions/h5)
796
+ * @param params 下单参数,payerClientIp 必填
797
+ * @returns 收银台跳转链接(302 重定向即可拉起微信支付)
798
+ */
799
+ async h5Pay(params) {
800
+ const body = buildTransactionBody(client, params);
801
+ body.scene_info = {
802
+ payer_client_ip: params.payerClientIp,
803
+ ...params.sceneInfo?.deviceType ? { device_type: params.sceneInfo.deviceType } : {}
804
+ };
805
+ const { data } = await unwrapV3(client.sdk.v3.pay.transactions.h5.post(body));
806
+ return { h5Url: data.h5_url };
807
+ },
808
+ /**
809
+ * 交易查询(GET /v3/pay/transactions/out-trade-no/{no} 或 .../id/{id})
810
+ * @throws {WechatApiError} 订单不存在等失败(RESOURCE_NOT_EXISTS)
811
+ */
812
+ async query(params) {
813
+ const mchid = client.config.mchid;
814
+ const response = params.transactionId ? await unwrapV3(
815
+ client.sdk.client.request(
816
+ `/v3/pay/transactions/id/${encodeURIComponent(params.transactionId)}`,
817
+ "GET",
818
+ void 0,
819
+ { params: { mchid } }
820
+ )
821
+ ) : await unwrapV3(
822
+ client.sdk.client.request(
823
+ `/v3/pay/transactions/out-trade-no/${encodeURIComponent(params.outTradeNo ?? "")}`,
824
+ "GET",
825
+ void 0,
826
+ { params: { mchid } }
827
+ )
828
+ );
829
+ return mapTransaction(response.data);
830
+ }
831
+ };
832
+ }
833
+ __name(createPayment, "createPayment");
834
+ async function postTransaction(client, chain, params) {
835
+ const body = buildTransactionBody(client, params);
836
+ return unwrapV3(client.sdk.v3.pay.transactions[chain].post(body));
837
+ }
838
+ __name(postTransaction, "postTransaction");
839
+ function buildTransactionBody(client, params) {
840
+ const body = {
841
+ appid: client.config.appid,
842
+ mchid: client.config.mchid,
843
+ description: params.description,
844
+ out_trade_no: params.outTradeNo,
845
+ time_expire: params.timeExpire,
846
+ attach: params.attach,
847
+ goods_tag: params.goodsTag,
848
+ notify_url: client.config.notifyUrl,
849
+ amount: {
850
+ total: params.amount.total,
851
+ currency: params.amount.currency ?? "CNY"
852
+ }
853
+ };
854
+ if (params.openid) {
855
+ body.payer = { openid: params.openid };
856
+ }
857
+ for (const key of Object.keys(body)) {
858
+ if (body[key] === void 0) delete body[key];
859
+ }
860
+ return body;
861
+ }
862
+ __name(buildTransactionBody, "buildTransactionBody");
863
+ function buildInvokeParams(client, prepayId) {
864
+ if (!prepayId) {
865
+ throw new Error("WechatClient: \u4E0B\u5355\u54CD\u5E94\u7F3A\u5C11 prepay_id");
866
+ }
867
+ const appId = client.config.appid;
868
+ const timeStamp = `${wechatpayAxiosPlugin.Formatter.timestamp()}`;
869
+ const nonceStr = wechatpayAxiosPlugin.Formatter.nonce(32);
870
+ const pkg = `prepay_id=${prepayId}`;
871
+ const message = `${appId}
872
+ ${timeStamp}
873
+ ${nonceStr}
874
+ ${pkg}
875
+ `;
876
+ const paySign = wechatpayAxiosPlugin.Rsa.sign(message, client.config.options.privateKey);
877
+ return { appId, timeStamp, nonceStr, package: pkg, signType: "RSA", paySign };
878
+ }
879
+ __name(buildInvokeParams, "buildInvokeParams");
880
+ function mapTransaction(data) {
881
+ return {
882
+ appid: data.appid,
883
+ mchid: data.mchid,
884
+ outTradeNo: data.out_trade_no,
885
+ transactionId: data.transaction_id,
886
+ tradeType: data.trade_type,
887
+ tradeState: data.trade_state,
888
+ tradeStateDesc: data.trade_state_desc,
889
+ bankType: data.bank_type,
890
+ attach: data.attach,
891
+ successTime: data.success_time,
892
+ total: data.amount?.total,
893
+ payerTotal: data.amount?.payer_total
894
+ };
895
+ }
896
+ __name(mapTransaction, "mapTransaction");
897
+ function createNotifyHandler2(client) {
898
+ return {
899
+ /**
900
+ * 验签异步通知
901
+ * @param headers 微信支付回调的 Wechatpay-* 系列 HTTP 头
902
+ * @param body 原始请求体字符串(必须是未解析的原文,不可先 JSON.parse 再序列化)
903
+ * @returns 验签是否通过
904
+ */
905
+ verify(headers, body) {
906
+ const publicKey = client.config.options.certs[headers.serial];
907
+ if (!publicKey) {
908
+ return false;
909
+ }
910
+ try {
911
+ const message = wechatpayAxiosPlugin.Formatter.response(headers.timestamp, headers.nonce, body);
912
+ return wechatpayAxiosPlugin.Rsa.verify(message, headers.signature, publicKey);
913
+ } catch {
914
+ return false;
915
+ }
916
+ },
917
+ /**
918
+ * 解密通知 resource 字段(AES-256-GCM,apiv3Key)
919
+ * @param resource 回调 JSON 中的 resource 字段
920
+ */
921
+ decrypt(resource) {
922
+ const plaintext = wechatpayAxiosPlugin.Aes.AesGcm.decrypt(
923
+ resource.ciphertext,
924
+ client.config.apiv3Key,
925
+ resource.nonce,
926
+ resource.associatedData ?? ""
927
+ );
928
+ return JSON.parse(plaintext);
929
+ },
930
+ /**
931
+ * 校验解密后的通知与商户侧订单是否一致。
932
+ * 验签只保证通知来自微信支付,不保证与你的订单一致。
933
+ * @param payload 解密后的通知数据
934
+ * @param expected 商户侧期望值:outTradeNo 订单号、total 订单金额(分)
935
+ */
936
+ validate(payload, expected) {
937
+ const errors = [];
938
+ if (payload.mchid !== client.config.mchid) {
939
+ errors.push(`mchid \u4E0D\u5339\u914D: \u671F\u671B ${client.config.mchid}\uFF0C\u6536\u5230 ${payload.mchid}`);
940
+ }
941
+ if (expected?.outTradeNo && payload.outTradeNo !== expected.outTradeNo) {
942
+ errors.push(`out_trade_no \u4E0D\u5339\u914D: \u671F\u671B ${expected.outTradeNo}\uFF0C\u6536\u5230 ${payload.outTradeNo}`);
943
+ }
944
+ if (expected?.total !== void 0 && payload.amount?.total !== expected.total) {
945
+ errors.push(`amount.total \u4E0D\u5339\u914D: \u671F\u671B ${expected.total}\uFF0C\u6536\u5230 ${payload.amount?.total}`);
946
+ }
947
+ return { valid: errors.length === 0, errors };
948
+ },
949
+ /** 通知处理成功应答(HTTP 200/201,body 恰为 {"code":"SUCCESS"}) */
950
+ successResponse() {
951
+ return { code: "SUCCESS" };
952
+ },
953
+ /** 通知处理失败应答(微信会按衰减频率重发通知) */
954
+ failResponse(message) {
955
+ return { code: "FAIL", message: message ?? "\u5904\u7406\u5931\u8D25" };
956
+ }
957
+ };
958
+ }
959
+ __name(createNotifyHandler2, "createNotifyHandler");
960
+
961
+ // packages/payment/src/wechat/refund.ts
962
+ function createRefund2(client) {
963
+ return {
964
+ /**
965
+ * 申请退款(POST /v3/refund/domestic/refunds)
966
+ * @param params 退款参数(outTradeNo 与 transactionId 二选一)
967
+ * @throws {WechatApiError} 参数错误、余额不足、订单不可退等失败
968
+ */
969
+ async refund(params) {
970
+ const body = {
971
+ out_trade_no: params.outTradeNo,
972
+ transaction_id: params.transactionId,
973
+ out_refund_no: params.outRefundNo,
974
+ reason: params.reason,
975
+ notify_url: params.notifyUrl ?? client.config.notifyUrl,
976
+ funds_account: params.fundsAccount,
977
+ amount: {
978
+ refund: params.amount.refund,
979
+ total: params.amount.total,
980
+ currency: params.amount.currency ?? "CNY"
981
+ }
982
+ };
983
+ for (const key of Object.keys(body)) {
984
+ if (body[key] === void 0) delete body[key];
985
+ }
986
+ for (const key of Object.keys(body.amount)) {
987
+ if (body.amount[key] === void 0) delete body.amount[key];
988
+ }
989
+ const { data } = await unwrapV3(client.sdk.v3.refund.domestic.refunds.post(body));
990
+ return mapRefund(data);
991
+ },
992
+ /**
993
+ * 查询退款(GET /v3/refund/domestic/refunds/{out_refund_no | refund_id})
994
+ * @throws {WechatApiError} 退款单不存在等失败
995
+ */
996
+ async queryRefund(params) {
997
+ const id = params.refundId ?? params.outRefundNo;
998
+ if (!id) {
999
+ throw new Error("WechatClient: queryRefund \u9700\u8981 outRefundNo \u6216 refundId");
1000
+ }
1001
+ const { data } = await unwrapV3(
1002
+ client.sdk.client.request(`/v3/refund/domestic/refunds/${encodeURIComponent(id)}`, "GET")
1003
+ );
1004
+ return mapRefund(data);
1005
+ }
1006
+ };
1007
+ }
1008
+ __name(createRefund2, "createRefund");
1009
+ function mapRefund(data) {
1010
+ return {
1011
+ refundId: data.refund_id,
1012
+ outRefundNo: data.out_refund_no,
1013
+ outTradeNo: data.out_trade_no,
1014
+ transactionId: data.transaction_id,
1015
+ status: data.status,
1016
+ refundAmount: data.amount?.refund,
1017
+ total: data.amount?.total,
1018
+ userReceivedAmount: data.amount?.user_received_amount,
1019
+ successTime: data.success_time,
1020
+ reason: data.reason
1021
+ };
1022
+ }
1023
+ __name(mapRefund, "mapRefund");
1024
+
1025
+ // packages/payment/src/wechat/plugin.ts
1026
+ var WECHAT_KEY = createInjectionKey("vobs.payment.wechat");
1027
+ function useWechat() {
1028
+ const client = inject(WECHAT_KEY);
1029
+ if (!client) {
1030
+ throw new Error("Vobs Payment: \u627E\u4E0D\u5230 WechatClient\uFF0C\u8BF7\u5B89\u88C5 wechatPlugin");
1031
+ }
1032
+ return client;
1033
+ }
1034
+ __name(useWechat, "useWechat");
1035
+ function wechatPlugin(options) {
1036
+ return {
1037
+ name: "@vobs/payment/wechat",
1038
+ version: "0.1.0",
1039
+ install(context) {
1040
+ if (!options.client && !options.config) {
1041
+ throw new Error("Vobs Payment: wechatPlugin \u9700\u8981\u63D0\u4F9B config \u6216 client \u4E4B\u4E00");
1042
+ }
1043
+ const ownClient = !options.client;
1044
+ const client = options.client ?? new WechatClient(options.config);
1045
+ context.provide(WECHAT_KEY, client);
1046
+ return ownClient ? () => client.dispose() : void 0;
1047
+ }
1048
+ };
1049
+ }
1050
+ __name(wechatPlugin, "wechatPlugin");
1051
+
1052
+ exports.ALIPAY_KEY = ALIPAY_KEY;
1053
+ exports.AlipayApiError = AlipayApiError;
1054
+ exports.AlipayClient = AlipayClient;
1055
+ exports.AlipayConfig = AlipayConfig;
1056
+ exports.WECHAT_KEY = WECHAT_KEY;
1057
+ exports.WechatApiError = WechatApiError;
1058
+ exports.WechatClient = WechatClient;
1059
+ exports.WechatConfig = WechatConfig;
1060
+ exports.alipay = alipay_exports;
1061
+ exports.alipayPlugin = alipayPlugin;
1062
+ exports.createPagePay = createPagePay;
1063
+ exports.createPayment = createPayment;
1064
+ exports.createQuery = createQuery;
1065
+ exports.createWapPay = createWapPay;
1066
+ exports.useAlipay = useAlipay;
1067
+ exports.useWechat = useWechat;
1068
+ exports.wechat = wechat_exports;
1069
+ exports.wechatPlugin = wechatPlugin;
1070
+ //# sourceMappingURL=index.cjs.map
1071
+ //# sourceMappingURL=index.cjs.map