@h-ai/payment 0.1.0-alpha.67 → 0.1.0-alpha.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +125 -41
- package/README.ja.md +125 -41
- package/README.md +139 -42
- package/dist/chunk-YQD4KPT5.js +103 -0
- package/dist/chunk-YQD4KPT5.js.map +1 -0
- package/dist/client/index.d.ts +26 -25
- package/dist/client/index.js +61 -60
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +17 -19
- package/dist/index.js +646 -170
- package/dist/index.js.map +1 -1
- package/dist/payment-types-D02t-Pc9.d.ts +500 -0
- package/package.json +5 -3
- package/dist/chunk-4IUARFWH.js +0 -67
- package/dist/chunk-4IUARFWH.js.map +0 -1
- package/dist/payment-types-Cf3kF6Tn.d.ts +0 -211
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import * as _h_ai_core from '@h-ai/core';
|
|
2
|
-
import { HaiResult } from '@h-ai/core';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @h-ai/payment — 错误码 + 配置 Schema
|
|
7
|
-
*
|
|
8
|
-
* 支付模块的错误码、Zod 配置 Schema 与配置类型。
|
|
9
|
-
* @module payment-config
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/** 微信支付配置 Schema */
|
|
13
|
-
declare const WechatPayConfigSchema: z.ZodObject<{
|
|
14
|
-
mchId: z.ZodString;
|
|
15
|
-
apiV3Key: z.ZodString;
|
|
16
|
-
serialNo: z.ZodString;
|
|
17
|
-
privateKey: z.ZodString;
|
|
18
|
-
platformCert: z.ZodOptional<z.ZodString>;
|
|
19
|
-
appId: z.ZodString;
|
|
20
|
-
}, z.core.$strip>;
|
|
21
|
-
/** 支付宝配置 Schema */
|
|
22
|
-
declare const AlipayConfigSchema: z.ZodObject<{
|
|
23
|
-
appId: z.ZodString;
|
|
24
|
-
privateKey: z.ZodString;
|
|
25
|
-
alipayPublicKey: z.ZodString;
|
|
26
|
-
signType: z.ZodDefault<z.ZodEnum<{
|
|
27
|
-
RSA2: "RSA2";
|
|
28
|
-
RSA: "RSA";
|
|
29
|
-
}>>;
|
|
30
|
-
sandbox: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
-
}, z.core.$strip>;
|
|
32
|
-
/** Stripe 配置 Schema */
|
|
33
|
-
declare const StripeConfigSchema: z.ZodObject<{
|
|
34
|
-
secretKey: z.ZodString;
|
|
35
|
-
webhookSecret: z.ZodString;
|
|
36
|
-
webhookToleranceSeconds: z.ZodDefault<z.ZodNumber>;
|
|
37
|
-
}, z.core.$strip>;
|
|
38
|
-
/** 支付模块配置 Schema */
|
|
39
|
-
declare const PaymentConfigSchema: z.ZodObject<{
|
|
40
|
-
wechat: z.ZodOptional<z.ZodObject<{
|
|
41
|
-
mchId: z.ZodString;
|
|
42
|
-
apiV3Key: z.ZodString;
|
|
43
|
-
serialNo: z.ZodString;
|
|
44
|
-
privateKey: z.ZodString;
|
|
45
|
-
platformCert: z.ZodOptional<z.ZodString>;
|
|
46
|
-
appId: z.ZodString;
|
|
47
|
-
}, z.core.$strip>>;
|
|
48
|
-
alipay: z.ZodOptional<z.ZodObject<{
|
|
49
|
-
appId: z.ZodString;
|
|
50
|
-
privateKey: z.ZodString;
|
|
51
|
-
alipayPublicKey: z.ZodString;
|
|
52
|
-
signType: z.ZodDefault<z.ZodEnum<{
|
|
53
|
-
RSA2: "RSA2";
|
|
54
|
-
RSA: "RSA";
|
|
55
|
-
}>>;
|
|
56
|
-
sandbox: z.ZodDefault<z.ZodBoolean>;
|
|
57
|
-
}, z.core.$strip>>;
|
|
58
|
-
stripe: z.ZodOptional<z.ZodObject<{
|
|
59
|
-
secretKey: z.ZodString;
|
|
60
|
-
webhookSecret: z.ZodString;
|
|
61
|
-
webhookToleranceSeconds: z.ZodDefault<z.ZodNumber>;
|
|
62
|
-
}, z.core.$strip>>;
|
|
63
|
-
}, z.core.$strip>;
|
|
64
|
-
type PaymentConfig = z.infer<typeof PaymentConfigSchema>;
|
|
65
|
-
type PaymentConfigInput = z.input<typeof PaymentConfigSchema>;
|
|
66
|
-
type WechatPayConfig = z.infer<typeof WechatPayConfigSchema>;
|
|
67
|
-
type AlipayConfig = z.infer<typeof AlipayConfigSchema>;
|
|
68
|
-
type StripeConfig = z.infer<typeof StripeConfigSchema>;
|
|
69
|
-
|
|
70
|
-
declare const HaiPaymentError: {
|
|
71
|
-
readonly CREATE_ORDER_FAILED: _h_ai_core.HaiErrorDef;
|
|
72
|
-
readonly QUERY_ORDER_FAILED: _h_ai_core.HaiErrorDef;
|
|
73
|
-
readonly REFUND_FAILED: _h_ai_core.HaiErrorDef;
|
|
74
|
-
readonly CLOSE_ORDER_FAILED: _h_ai_core.HaiErrorDef;
|
|
75
|
-
readonly NOT_INITIALIZED: _h_ai_core.HaiErrorDef;
|
|
76
|
-
readonly SIGN_FAILED: _h_ai_core.HaiErrorDef;
|
|
77
|
-
readonly PROVIDER_NOT_FOUND: _h_ai_core.HaiErrorDef;
|
|
78
|
-
readonly INVALID_AMOUNT: _h_ai_core.HaiErrorDef;
|
|
79
|
-
readonly NOTIFY_VERIFY_FAILED: _h_ai_core.HaiErrorDef;
|
|
80
|
-
readonly NOTIFY_PARSE_FAILED: _h_ai_core.HaiErrorDef;
|
|
81
|
-
readonly INVOKE_WEB_FAILED: _h_ai_core.HaiErrorDef;
|
|
82
|
-
readonly INVOKE_APP_FAILED: _h_ai_core.HaiErrorDef;
|
|
83
|
-
readonly CONFIG_ERROR: _h_ai_core.HaiErrorDef;
|
|
84
|
-
};
|
|
85
|
-
/** 支付场景(tradeType) */
|
|
86
|
-
type TradeType = 'jsapi' | 'h5' | 'app' | 'native' | 'mini_program';
|
|
87
|
-
/** 订单状态 */
|
|
88
|
-
type OrderStatusValue = 'pending' | 'paid' | 'closed' | 'refunded' | 'failed';
|
|
89
|
-
/** 创建订单入参 */
|
|
90
|
-
interface CreateOrderInput {
|
|
91
|
-
/** 商户订单号 */
|
|
92
|
-
orderNo: string;
|
|
93
|
-
/** 金额(分) */
|
|
94
|
-
amount: number;
|
|
95
|
-
/** 币种(默认 CNY) */
|
|
96
|
-
currency?: string;
|
|
97
|
-
/** 商品描述 */
|
|
98
|
-
description: string;
|
|
99
|
-
/** 支付场景 */
|
|
100
|
-
tradeType: TradeType;
|
|
101
|
-
/** 用户标识(微信 openid 等,jsapi 必填) */
|
|
102
|
-
userId?: string;
|
|
103
|
-
/** 异步通知 URL */
|
|
104
|
-
notifyUrl: string;
|
|
105
|
-
/** 附加数据(透传) */
|
|
106
|
-
metadata?: Record<string, string>;
|
|
107
|
-
}
|
|
108
|
-
/** 支付订单(返回给客户端调起支付) */
|
|
109
|
-
interface PaymentOrder {
|
|
110
|
-
/** Provider 名称 */
|
|
111
|
-
provider: string;
|
|
112
|
-
/** 支付场景 */
|
|
113
|
-
tradeType: TradeType;
|
|
114
|
-
/** 客户端调起参数(各平台差异) */
|
|
115
|
-
clientParams: Record<string, unknown>;
|
|
116
|
-
/** 预支付 ID(如微信 prepay_id) */
|
|
117
|
-
prepayId?: string;
|
|
118
|
-
}
|
|
119
|
-
/** 回调请求(原始 HTTP 数据) */
|
|
120
|
-
interface PaymentNotifyRequest {
|
|
121
|
-
/** 请求 body */
|
|
122
|
-
body: string;
|
|
123
|
-
/** 请求 headers */
|
|
124
|
-
headers: Record<string, string>;
|
|
125
|
-
}
|
|
126
|
-
/** 回调解析结果 */
|
|
127
|
-
interface PaymentNotifyResult {
|
|
128
|
-
/** 商户订单号 */
|
|
129
|
-
orderNo: string;
|
|
130
|
-
/** 支付渠道交易号 */
|
|
131
|
-
transactionId: string;
|
|
132
|
-
/** 支付金额(分) */
|
|
133
|
-
amount: number;
|
|
134
|
-
/** 支付状态 */
|
|
135
|
-
status: OrderStatusValue;
|
|
136
|
-
/** 支付时间 */
|
|
137
|
-
paidAt?: Date;
|
|
138
|
-
/** 原始数据 */
|
|
139
|
-
raw?: Record<string, unknown>;
|
|
140
|
-
}
|
|
141
|
-
/** 订单状态查询结果 */
|
|
142
|
-
interface OrderStatus {
|
|
143
|
-
/** 商户订单号 */
|
|
144
|
-
orderNo: string;
|
|
145
|
-
/** 渠道交易号 */
|
|
146
|
-
transactionId?: string;
|
|
147
|
-
/** 订单状态 */
|
|
148
|
-
status: OrderStatusValue;
|
|
149
|
-
/** 金额(分) */
|
|
150
|
-
amount: number;
|
|
151
|
-
/** 支付时间 */
|
|
152
|
-
paidAt?: Date;
|
|
153
|
-
}
|
|
154
|
-
/** 退款入参 */
|
|
155
|
-
interface RefundInput {
|
|
156
|
-
/** 商户订单号 */
|
|
157
|
-
orderNo: string;
|
|
158
|
-
/** 退款单号 */
|
|
159
|
-
refundNo: string;
|
|
160
|
-
/** 退款金额(分) */
|
|
161
|
-
amount: number;
|
|
162
|
-
/** 订单总金额(分),微信退款必填 */
|
|
163
|
-
totalAmount?: number;
|
|
164
|
-
/** 退款原因 */
|
|
165
|
-
reason?: string;
|
|
166
|
-
}
|
|
167
|
-
/** 退款结果 */
|
|
168
|
-
interface RefundResult {
|
|
169
|
-
/** 退款单号 */
|
|
170
|
-
refundNo: string;
|
|
171
|
-
/** 渠道退款 ID */
|
|
172
|
-
refundId: string;
|
|
173
|
-
/** 退款状态 */
|
|
174
|
-
status: 'processing' | 'success' | 'failed';
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 支付 Provider 接口
|
|
178
|
-
*
|
|
179
|
-
* 各支付渠道(微信/支付宝/Stripe)实现此接口,
|
|
180
|
-
* 由 payment 模块统一调度。
|
|
181
|
-
*/
|
|
182
|
-
interface PaymentProvider {
|
|
183
|
-
/** Provider 名称(如 'wechat', 'alipay', 'stripe') */
|
|
184
|
-
readonly name: string;
|
|
185
|
-
/** 创建支付订单 */
|
|
186
|
-
createOrder: (input: CreateOrderInput) => Promise<HaiResult<PaymentOrder>>;
|
|
187
|
-
/** 处理异步通知回调(验签 + 解析) */
|
|
188
|
-
handleNotify: (request: PaymentNotifyRequest) => Promise<HaiResult<PaymentNotifyResult>>;
|
|
189
|
-
/** 查询订单状态 */
|
|
190
|
-
queryOrder: (orderNo: string) => Promise<HaiResult<OrderStatus>>;
|
|
191
|
-
/** 申请退款 */
|
|
192
|
-
refund: (input: RefundInput) => Promise<HaiResult<RefundResult>>;
|
|
193
|
-
/** 关闭订单 */
|
|
194
|
-
closeOrder: (orderNo: string) => Promise<HaiResult<void>>;
|
|
195
|
-
}
|
|
196
|
-
/** 支付模块函数接口 */
|
|
197
|
-
interface PaymentFunctions {
|
|
198
|
-
init: (config: PaymentConfigInput) => Promise<HaiResult<void>>;
|
|
199
|
-
close: () => Promise<void>;
|
|
200
|
-
readonly config: PaymentConfig | null;
|
|
201
|
-
readonly isInitialized: boolean;
|
|
202
|
-
createOrder: (providerName: string, input: CreateOrderInput) => Promise<HaiResult<PaymentOrder>>;
|
|
203
|
-
handleNotify: (providerName: string, request: PaymentNotifyRequest) => Promise<HaiResult<PaymentNotifyResult>>;
|
|
204
|
-
queryOrder: (providerName: string, orderNo: string) => Promise<HaiResult<OrderStatus>>;
|
|
205
|
-
refund: (providerName: string, input: RefundInput) => Promise<HaiResult<RefundResult>>;
|
|
206
|
-
closeOrder: (providerName: string, orderNo: string) => Promise<HaiResult<void>>;
|
|
207
|
-
getProvider: (name: string) => PaymentProvider | undefined;
|
|
208
|
-
registerProvider: (provider: PaymentProvider) => void;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export { type AlipayConfig as A, type CreateOrderInput as C, HaiPaymentError as H, type OrderStatus as O, type PaymentOrder as P, type RefundInput as R, type StripeConfig as S, type TradeType as T, type WechatPayConfig as W, type PaymentFunctions as a, AlipayConfigSchema as b, type OrderStatusValue as c, type PaymentConfig as d, type PaymentConfigInput as e, PaymentConfigSchema as f, type PaymentNotifyRequest as g, type PaymentNotifyResult as h, type PaymentProvider as i, type RefundResult as j, StripeConfigSchema as k, WechatPayConfigSchema as l };
|