@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
@@ -0,0 +1,580 @@
1
+ import { AlipaySdk } from 'alipay-sdk';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+
6
+ // packages/payment/src/alipay/config.ts
7
+ var _AlipayConfig = class _AlipayConfig {
8
+ constructor(options) {
9
+ this.validate(options);
10
+ this._options = { ...options };
11
+ }
12
+ /** 获取完整配置 */
13
+ get options() {
14
+ return this._options;
15
+ }
16
+ /** 应用 ID */
17
+ get appId() {
18
+ return this._options.appId;
19
+ }
20
+ /** 网关地址 */
21
+ get gateway() {
22
+ return this._options.gateway ?? "https://openapi.alipay.com/gateway.do";
23
+ }
24
+ /** 异步通知地址 */
25
+ get notifyUrl() {
26
+ return this._options.notifyUrl;
27
+ }
28
+ /** 同步跳转地址 */
29
+ get returnUrl() {
30
+ return this._options.returnUrl;
31
+ }
32
+ /** 更新配置(部分更新) */
33
+ update(patch) {
34
+ const merged = { ...this._options, ...patch };
35
+ this.validate(merged);
36
+ this._options = merged;
37
+ }
38
+ /** 替换配置 */
39
+ replace(options) {
40
+ this.validate(options);
41
+ this._options = { ...options };
42
+ }
43
+ /** 创建沙箱配置的快捷方法 */
44
+ static forSandbox(options) {
45
+ return new _AlipayConfig({
46
+ ...options,
47
+ gateway: "https://openapi-sandbox.dl.alipaydev.com/gateway.do"
48
+ });
49
+ }
50
+ validate(options) {
51
+ if (!options.appId) {
52
+ throw new Error("AlipayConfig: appId \u4E0D\u80FD\u4E3A\u7A7A");
53
+ }
54
+ if (!options.privateKey) {
55
+ throw new Error("AlipayConfig: privateKey \u4E0D\u80FD\u4E3A\u7A7A");
56
+ }
57
+ if (!options.alipayPublicKey) {
58
+ throw new Error("AlipayConfig: alipayPublicKey \u4E0D\u80FD\u4E3A\u7A7A");
59
+ }
60
+ }
61
+ };
62
+ __name(_AlipayConfig, "AlipayConfig");
63
+ var AlipayConfig = _AlipayConfig;
64
+
65
+ // packages/payment/src/alipay/client.ts
66
+ var _AlipayClient = class _AlipayClient {
67
+ constructor(options) {
68
+ this._disposed = false;
69
+ this.config = new AlipayConfig(options);
70
+ this._sdk = this.createSdk(options);
71
+ }
72
+ /** 获取底层 AlipaySdk 实例 */
73
+ get sdk() {
74
+ this.ensureActive();
75
+ return this._sdk;
76
+ }
77
+ /** 更新配置并重建 SDK 实例 */
78
+ updateConfig(patch) {
79
+ this.ensureActive();
80
+ this.config.update(patch);
81
+ this._sdk = this.createSdk(this.config.options);
82
+ }
83
+ /** 销毁客户端 */
84
+ dispose() {
85
+ this._disposed = true;
86
+ this._sdk = null;
87
+ }
88
+ createSdk(options) {
89
+ return new AlipaySdk({
90
+ appId: options.appId,
91
+ privateKey: options.privateKey,
92
+ alipayPublicKey: options.alipayPublicKey,
93
+ signType: options.signType ?? "RSA2",
94
+ gateway: options.gateway,
95
+ timeout: options.timeout ?? 5e3,
96
+ keyType: options.keyType ?? "PKCS1"
97
+ });
98
+ }
99
+ ensureActive() {
100
+ if (this._disposed) {
101
+ throw new Error("AlipayClient: \u5BA2\u6237\u7AEF\u5DF2\u9500\u6BC1");
102
+ }
103
+ }
104
+ };
105
+ __name(_AlipayClient, "AlipayClient");
106
+ var AlipayClient = _AlipayClient;
107
+
108
+ // packages/payment/src/alipay/response.ts
109
+ var _AlipayApiError = class _AlipayApiError extends Error {
110
+ constructor(apiName, code, subCode, subMsg, msg) {
111
+ super(`\u652F\u4ED8\u5B9D\u63A5\u53E3 ${apiName} \u8C03\u7528\u5931\u8D25: ${subMsg ?? msg ?? "\u672A\u77E5\u9519\u8BEF"} (code=${code}${subCode ? `, sub_code=${subCode}` : ""})`);
112
+ this.name = "AlipayApiError";
113
+ this.code = code;
114
+ this.subCode = subCode;
115
+ this.subMsg = subMsg;
116
+ }
117
+ };
118
+ __name(_AlipayApiError, "AlipayApiError");
119
+ var AlipayApiError = _AlipayApiError;
120
+ function toResponseKey(apiName) {
121
+ return `${apiName.replace(/\./g, "_")}_response`;
122
+ }
123
+ __name(toResponseKey, "toResponseKey");
124
+ function unwrapResponse(raw, apiName) {
125
+ const outer = raw;
126
+ const body = (outer && outer[toResponseKey(apiName)]) ?? outer;
127
+ if (!body || typeof body !== "object") {
128
+ throw new AlipayApiError(apiName, "INVALID_RESPONSE", void 0, void 0, "\u54CD\u5E94\u4F53\u683C\u5F0F\u5F02\u5E38");
129
+ }
130
+ if (body.code !== "10000") {
131
+ throw new AlipayApiError(apiName, body.code, body.sub_code, body.sub_msg, body.msg);
132
+ }
133
+ return body;
134
+ }
135
+ __name(unwrapResponse, "unwrapResponse");
136
+
137
+ // packages/payment/src/alipay/payment.ts
138
+ function createPagePay(client) {
139
+ return {
140
+ /**
141
+ * 发起电脑网站支付
142
+ * @param config 支付配置
143
+ * @returns 支付表单 HTML
144
+ */
145
+ async pay(config) {
146
+ const { outTradeNo, totalAmount, subject, body, passbackParams } = config;
147
+ const bizParams = {
148
+ outTradeNo,
149
+ totalAmount,
150
+ subject,
151
+ productCode: "FAST_INSTANT_TRADE_PAY",
152
+ body,
153
+ passbackParams,
154
+ returnUrl: client.config.returnUrl,
155
+ notifyUrl: client.config.notifyUrl
156
+ };
157
+ const formHtml = client.sdk.pageExecute(
158
+ "alipay.trade.page.pay",
159
+ "POST",
160
+ { bizContent: sanitizeParams(bizParams) }
161
+ );
162
+ return { formHtml };
163
+ }
164
+ };
165
+ }
166
+ __name(createPagePay, "createPagePay");
167
+ function sanitizeParams(params) {
168
+ const result = {};
169
+ for (const [key, value] of Object.entries(params)) {
170
+ if (value !== void 0 && value !== null) {
171
+ result[key] = value;
172
+ }
173
+ }
174
+ return result;
175
+ }
176
+ __name(sanitizeParams, "sanitizeParams");
177
+
178
+ // packages/payment/src/alipay/wap.ts
179
+ function createWapPay(client) {
180
+ return {
181
+ /**
182
+ * 发起手机网站支付
183
+ * @param config 支付配置
184
+ * @returns 支付表单 HTML
185
+ */
186
+ async pay(config) {
187
+ const { outTradeNo, totalAmount, subject, body, passbackParams, quitUrl } = config;
188
+ const bizParams = {
189
+ outTradeNo,
190
+ totalAmount,
191
+ subject,
192
+ productCode: "QUICK_WAP_WAY",
193
+ body,
194
+ passbackParams,
195
+ quitUrl,
196
+ returnUrl: client.config.returnUrl,
197
+ notifyUrl: client.config.notifyUrl
198
+ };
199
+ const formHtml = client.sdk.pageExecute(
200
+ "alipay.trade.wap.pay",
201
+ "POST",
202
+ { bizContent: sanitizeParams2(bizParams) }
203
+ );
204
+ return { formHtml };
205
+ }
206
+ };
207
+ }
208
+ __name(createWapPay, "createWapPay");
209
+ function sanitizeParams2(params) {
210
+ const result = {};
211
+ for (const [key, value] of Object.entries(params)) {
212
+ if (value !== void 0 && value !== null) {
213
+ result[key] = value;
214
+ }
215
+ }
216
+ return result;
217
+ }
218
+ __name(sanitizeParams2, "sanitizeParams");
219
+
220
+ // packages/payment/src/alipay/query.ts
221
+ function createQuery(client) {
222
+ return {
223
+ /**
224
+ * 查询交易状态
225
+ * @param params 查询参数(outTradeNo 和 tradeNo 至少传一个)
226
+ * @throws {AlipayApiError} 业务失败(如 ACQ.TRADE_NOT_EXIST)时抛出
227
+ */
228
+ async query(params) {
229
+ const alipayResponse = unwrapResponse(
230
+ await client.sdk.exec("alipay.trade.query", {
231
+ bizContent: params
232
+ }),
233
+ "alipay.trade.query"
234
+ );
235
+ return {
236
+ tradeNo: alipayResponse.trade_no,
237
+ outTradeNo: alipayResponse.out_trade_no,
238
+ buyerLogonId: alipayResponse.buyer_logon_id,
239
+ tradeStatus: alipayResponse.trade_status,
240
+ totalAmount: alipayResponse.total_amount,
241
+ receiptAmount: alipayResponse.receipt_amount ?? "0.00",
242
+ buyerPayAmount: alipayResponse.buyer_pay_amount ?? "0.00",
243
+ sendPayDate: alipayResponse.send_pay_date ?? "",
244
+ gmtPayment: alipayResponse.gmt_payment ?? null,
245
+ gmtClose: alipayResponse.gmt_close ?? null,
246
+ refundAmount: alipayResponse.refund_amount ?? "0.00",
247
+ subject: alipayResponse.subject ?? "",
248
+ passbackParams: alipayResponse.passback_params ?? null,
249
+ fundChannel: alipayResponse.fund_channel ?? null
250
+ };
251
+ },
252
+ /**
253
+ * 判断交易是否支付成功
254
+ * 只有 TRADE_SUCCESS 或 TRADE_FINISHED 才表示支付成功
255
+ */
256
+ isSuccessful(status) {
257
+ return status === "TRADE_SUCCESS" || status === "TRADE_FINISHED";
258
+ }
259
+ };
260
+ }
261
+ __name(createQuery, "createQuery");
262
+
263
+ // packages/payment/src/alipay/refund.ts
264
+ function createRefund(client) {
265
+ return {
266
+ /**
267
+ * 交易退款 (alipay.trade.refund)
268
+ * 交易发生后 12 个月内可退款,退款资金原路返回。
269
+ * @throws {AlipayApiError} 业务失败时抛出
270
+ */
271
+ async refund(params) {
272
+ const alipayResponse = unwrapResponse(
273
+ await client.sdk.exec("alipay.trade.refund", {
274
+ bizContent: params
275
+ }),
276
+ "alipay.trade.refund"
277
+ );
278
+ return {
279
+ tradeNo: alipayResponse.trade_no,
280
+ outTradeNo: alipayResponse.out_trade_no,
281
+ buyerLogonId: alipayResponse.buyer_logon_id,
282
+ refundAmount: alipayResponse.refund_fee,
283
+ fundChange: alipayResponse.fund_change ?? "N",
284
+ gmtRefundPay: alipayResponse.gmt_refund_pay ?? "",
285
+ refundDetailItemList: alipayResponse.refund_detail_item_list ?? null
286
+ };
287
+ },
288
+ /**
289
+ * 退款查询 (alipay.trade.fastpay.refund.query)
290
+ * 查询退款状态,确认退款是否成功。
291
+ * @throws {AlipayApiError} 业务失败时抛出
292
+ */
293
+ async queryRefund(params) {
294
+ const alipayResponse = unwrapResponse(
295
+ await client.sdk.exec("alipay.trade.fastpay.refund.query", {
296
+ bizContent: params
297
+ }),
298
+ "alipay.trade.fastpay.refund.query"
299
+ );
300
+ return {
301
+ tradeNo: alipayResponse.trade_no,
302
+ outTradeNo: alipayResponse.out_trade_no,
303
+ refundAmount: alipayResponse.refund_amount,
304
+ refundStatus: alipayResponse.refund_status,
305
+ outRequestNo: alipayResponse.out_request_no,
306
+ refundReason: alipayResponse.refund_reason ?? ""
307
+ };
308
+ },
309
+ /**
310
+ * 关闭交易 (alipay.trade.close)
311
+ * 关闭未支付的订单。
312
+ * @throws {AlipayApiError} 业务失败时抛出
313
+ */
314
+ async close(params) {
315
+ const alipayResponse = unwrapResponse(
316
+ await client.sdk.exec("alipay.trade.close", {
317
+ bizContent: params
318
+ }),
319
+ "alipay.trade.close"
320
+ );
321
+ return {
322
+ tradeNo: alipayResponse.trade_no,
323
+ outTradeNo: alipayResponse.out_trade_no
324
+ };
325
+ }
326
+ };
327
+ }
328
+ __name(createRefund, "createRefund");
329
+
330
+ // packages/payment/src/alipay/notify.ts
331
+ function createNotifyHandler(client) {
332
+ return {
333
+ /**
334
+ * 验签异步通知
335
+ * @param params 异步通知参数(支付宝 POST 过来的原始参数)
336
+ * @param raw 使用原始报文验签(推荐:v4.15+ 支持,规避 encodeURIComponent 差异导致的验签失败)
337
+ * @returns 验签是否通过
338
+ */
339
+ verify(params, raw = false) {
340
+ try {
341
+ return client.sdk.checkNotifySign(params, raw);
342
+ } catch {
343
+ return false;
344
+ }
345
+ },
346
+ /**
347
+ * 校验异步通知的业务字段
348
+ *
349
+ * 验签只保证通知确实来自支付宝,不保证通知与你系统中的订单一致;
350
+ * 因此除了 app_id,还应传入商户侧的期望值(outTradeNo / totalAmount)进行比对。
351
+ * @param params 异步通知参数
352
+ * @param expected 商户侧期望值:outTradeNo 订单号、totalAmount 订单金额(单位元)
353
+ */
354
+ validate(params, expected) {
355
+ const errors = [];
356
+ if (params.appId !== client.config.appId) {
357
+ errors.push(`app_id \u4E0D\u5339\u914D: \u671F\u671B ${client.config.appId}\uFF0C\u6536\u5230 ${params.appId}`);
358
+ }
359
+ if (expected?.outTradeNo && params.outTradeNo !== expected.outTradeNo) {
360
+ errors.push(`out_trade_no \u4E0D\u5339\u914D: \u671F\u671B ${expected.outTradeNo}\uFF0C\u6536\u5230 ${params.outTradeNo}`);
361
+ }
362
+ if (expected?.totalAmount && Number(params.totalAmount) !== Number(expected.totalAmount)) {
363
+ errors.push(`total_amount \u4E0D\u5339\u914D: \u671F\u671B ${expected.totalAmount}\uFF0C\u6536\u5230 ${params.totalAmount}`);
364
+ }
365
+ const validStatuses = ["TRADE_SUCCESS", "TRADE_FINISHED"];
366
+ if (!validStatuses.includes(params.tradeStatus)) {
367
+ errors.push(`trade_status \u975E\u7EC8\u6001: ${params.tradeStatus}`);
368
+ }
369
+ return {
370
+ valid: errors.length === 0,
371
+ errors
372
+ };
373
+ },
374
+ /**
375
+ * 生成支付宝异步通知的成功响应
376
+ * 处理完成后必须返回字符串 "success"
377
+ */
378
+ successResponse() {
379
+ return "success";
380
+ },
381
+ /**
382
+ * 生成支付宝异步通知的失败响应
383
+ * 返回空字符串或非 success 内容,支付宝会重试通知
384
+ */
385
+ failResponse() {
386
+ return "fail";
387
+ }
388
+ };
389
+ }
390
+ __name(createNotifyHandler, "createNotifyHandler");
391
+
392
+ // packages/reactivity/src/debug.ts
393
+ var activeDebugHooks = null;
394
+ function hasDebugHooks() {
395
+ return activeDebugHooks !== null;
396
+ }
397
+ __name(hasDebugHooks, "hasDebugHooks");
398
+ function invokeDebug(name, ...args) {
399
+ return;
400
+ }
401
+ __name(invokeDebug, "invokeDebug");
402
+
403
+ // packages/reactivity/src/owner.ts
404
+ var currentOwner = null;
405
+ function getCurrentOwner() {
406
+ return currentOwner;
407
+ }
408
+ __name(getCurrentOwner, "getCurrentOwner");
409
+
410
+ // packages/reactivity/src/scheduler.ts
411
+ var _Scheduler = class _Scheduler {
412
+ constructor() {
413
+ this.dirtyEffects = /* @__PURE__ */ new Set();
414
+ this.lowPriorityEffects = /* @__PURE__ */ new Set();
415
+ // flush 不可重入(flushing 标志保证),缓冲数组可在轮次间安全复用,避免每轮分配。
416
+ this.normalBuffer = [];
417
+ this.lowBuffer = [];
418
+ this.flushing = false;
419
+ this.scheduled = false;
420
+ this.batchDepth = 0;
421
+ }
422
+ schedule(effect2) {
423
+ if (effect2.disposed) return;
424
+ this.dirtyEffects.add(effect2);
425
+ this.lowPriorityEffects.delete(effect2);
426
+ this.ensureScheduled();
427
+ }
428
+ /** Queue an effect behind normal updates while preserving deterministic order. */
429
+ scheduleLow(effect2) {
430
+ if (effect2.disposed) return;
431
+ if (!this.dirtyEffects.has(effect2)) this.lowPriorityEffects.add(effect2);
432
+ this.ensureScheduled();
433
+ }
434
+ ensureScheduled() {
435
+ if (this.batchDepth === 0 && !this.flushing && !this.scheduled) {
436
+ this.scheduled = true;
437
+ queueMicrotask(() => {
438
+ this.scheduled = false;
439
+ this.flush();
440
+ });
441
+ }
442
+ }
443
+ remove(effect2) {
444
+ this.dirtyEffects.delete(effect2);
445
+ this.lowPriorityEffects.delete(effect2);
446
+ }
447
+ batch(fn) {
448
+ this.batchDepth++;
449
+ try {
450
+ return fn();
451
+ } finally {
452
+ this.batchDepth--;
453
+ if (this.batchDepth === 0) this.flush();
454
+ }
455
+ }
456
+ flush() {
457
+ if (this.flushing || this.batchDepth > 0) return;
458
+ this.flushing = true;
459
+ let rounds = 0;
460
+ let firstError;
461
+ let hasError = false;
462
+ try {
463
+ while (this.dirtyEffects.size > 0 || this.lowPriorityEffects.size > 0) {
464
+ if (++rounds > 100) {
465
+ this.dirtyEffects.clear();
466
+ this.lowPriorityEffects.clear();
467
+ throw new Error("Vobs: \u54CD\u5E94\u5F0F\u66F4\u65B0\u8D85\u8FC7 100 \u8F6E\uFF0C\u53EF\u80FD\u5B58\u5728\u5FAA\u73AF\u4F9D\u8D56");
468
+ }
469
+ this.collectRunnable(this.dirtyEffects, this.normalBuffer);
470
+ this.collectRunnable(this.lowPriorityEffects, this.lowBuffer);
471
+ sortEffects(this.normalBuffer);
472
+ sortEffects(this.lowBuffer);
473
+ for (const effect2 of this.normalBuffer) {
474
+ try {
475
+ effect2.run();
476
+ } catch (error) {
477
+ if (!hasError) {
478
+ firstError = error;
479
+ hasError = true;
480
+ }
481
+ }
482
+ }
483
+ for (const effect2 of this.lowBuffer) {
484
+ try {
485
+ effect2.run();
486
+ } catch (error) {
487
+ if (!hasError) {
488
+ firstError = error;
489
+ hasError = true;
490
+ }
491
+ }
492
+ }
493
+ this.normalBuffer.length = 0;
494
+ this.lowBuffer.length = 0;
495
+ }
496
+ } finally {
497
+ this.normalBuffer.length = 0;
498
+ this.lowBuffer.length = 0;
499
+ this.flushing = false;
500
+ }
501
+ if (hasError) throw firstError;
502
+ }
503
+ /** 收集未 disposed 的 effect 并清空源集合;run() 期间新调度的 effect 留给下一轮。 */
504
+ collectRunnable(source, target) {
505
+ for (const effect2 of source) {
506
+ if (!effect2.disposed) target.push(effect2);
507
+ }
508
+ source.clear();
509
+ }
510
+ };
511
+ __name(_Scheduler, "Scheduler");
512
+ function sortEffects(effects) {
513
+ if (effects.length > 1) {
514
+ effects.sort((a, b) => b.depth - a.depth || a.order - b.order);
515
+ }
516
+ }
517
+ __name(sortEffects, "sortEffects");
518
+
519
+ // packages/runtime/src/hmr.ts
520
+ var globalTarget = globalThis;
521
+ var hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: /* @__PURE__ */ new Map() };
522
+ globalTarget.__VOBS_HMR__ = hmrGlobal;
523
+
524
+ // packages/vobs/src/context.ts
525
+ var ownerProviders = /* @__PURE__ */ new WeakMap();
526
+ function inject(key, fallback) {
527
+ const owner = getCurrentOwner();
528
+ const value = owner ? injectFromOwner(owner, key) : void 0;
529
+ return value === void 0 ? fallback : value;
530
+ }
531
+ __name(inject, "inject");
532
+ function injectFromOwner(owner, key) {
533
+ let current = owner;
534
+ while (current) {
535
+ const providers = ownerProviders.get(current);
536
+ if (providers?.has(key)) return providers.get(key);
537
+ current = current.parent;
538
+ }
539
+ return void 0;
540
+ }
541
+ __name(injectFromOwner, "injectFromOwner");
542
+
543
+ // packages/vobs/src/app.ts
544
+ function createInjectionKey(description) {
545
+ return Symbol(description);
546
+ }
547
+ __name(createInjectionKey, "createInjectionKey");
548
+
549
+ // packages/payment/src/alipay/plugin.ts
550
+ var ALIPAY_KEY = createInjectionKey("vobs.payment.alipay");
551
+ function alipayPlugin(options) {
552
+ return {
553
+ name: "@vobs/payment/alipay",
554
+ version: "0.1.0",
555
+ install(context) {
556
+ if (!options.client && !options.config) {
557
+ throw new Error("Vobs Payment: alipayPlugin \u9700\u8981\u63D0\u4F9B config \u6216 client \u4E4B\u4E00");
558
+ }
559
+ const ownClient = !options.client;
560
+ const client = options.client ?? new AlipayClient(options.config);
561
+ context.provide(ALIPAY_KEY, client);
562
+ return ownClient ? () => client.dispose() : void 0;
563
+ }
564
+ };
565
+ }
566
+ __name(alipayPlugin, "alipayPlugin");
567
+ function useAlipay() {
568
+ const client = inject(ALIPAY_KEY);
569
+ if (!client) {
570
+ throw new Error(
571
+ "Vobs Payment: \u627E\u4E0D\u5230 AlipayClient\uFF0C\u8BF7\u5B89\u88C5 alipayPlugin"
572
+ );
573
+ }
574
+ return client;
575
+ }
576
+ __name(useAlipay, "useAlipay");
577
+
578
+ export { ALIPAY_KEY, AlipayApiError, AlipayClient, AlipayConfig, alipayPlugin, createNotifyHandler, createPagePay, createQuery, createRefund, createWapPay, useAlipay };
579
+ //# sourceMappingURL=index.js.map
580
+ //# sourceMappingURL=index.js.map