@payclave/sdk-server 0.1.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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/index.cjs +814 -0
- package/dist/index.d.cts +212 -0
- package/dist/index.d.ts +212 -0
- package/dist/index.js +802 -0
- package/package.json +60 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
|
|
3
|
+
type PayclaveMode = "test" | "live" | (string & {});
|
|
4
|
+
type PayclaveInvoiceStatus = "pending" | "processing" | "paid" | "underpaid" | "overpaid" | "expired" | "failed" | "cancelled" | (string & {});
|
|
5
|
+
type PayclavePaymentStatus = "detected" | "validating" | "confirmed" | "failed" | "duplicate" | "underpaid" | "overpaid" | (string & {});
|
|
6
|
+
declare const PAYCLAVE_WEBHOOK_EVENT_TYPES: readonly ["invoice.paid", "invoice.expired", "payment.failed", "payment.underpaid", "payment.overpaid"];
|
|
7
|
+
type PayclaveWebhookEventType = (typeof PAYCLAVE_WEBHOOK_EVENT_TYPES)[number];
|
|
8
|
+
type PayclaveWebhookDeliveryStatus = "pending" | "delivering" | "delivered" | "retry_scheduled" | "failed" | (string & {});
|
|
9
|
+
type PayclaveMetadata = Record<string, unknown>;
|
|
10
|
+
type PayclaveFetcher = (input: string, init: RequestInit) => Promise<Response>;
|
|
11
|
+
type PayclaveServerClientOptions = {
|
|
12
|
+
secretKey: string;
|
|
13
|
+
apiBaseUrl?: string;
|
|
14
|
+
fetcher?: PayclaveFetcher;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
};
|
|
17
|
+
type PayclaveRequestOptions = {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
type CreateCheckoutSessionInput = PayclaveRequestOptions & {
|
|
21
|
+
amount: string;
|
|
22
|
+
customerEmail?: string;
|
|
23
|
+
externalReference?: string;
|
|
24
|
+
successUrl?: string;
|
|
25
|
+
cancelUrl?: string;
|
|
26
|
+
metadata?: PayclaveMetadata;
|
|
27
|
+
expiresInMinutes?: number;
|
|
28
|
+
idempotencyKey?: string;
|
|
29
|
+
};
|
|
30
|
+
type CreateInvoiceInput = PayclaveRequestOptions & {
|
|
31
|
+
amount: string;
|
|
32
|
+
externalReference?: string;
|
|
33
|
+
metadata?: PayclaveMetadata;
|
|
34
|
+
expiresInMinutes?: number;
|
|
35
|
+
idempotencyKey?: string;
|
|
36
|
+
};
|
|
37
|
+
type CreateWebhookEndpointInput = PayclaveRequestOptions & {
|
|
38
|
+
url: string;
|
|
39
|
+
eventTypes?: PayclaveWebhookEventType[];
|
|
40
|
+
};
|
|
41
|
+
type CreateTestWebhookInput = PayclaveRequestOptions & {
|
|
42
|
+
endpointId: string;
|
|
43
|
+
eventType?: PayclaveWebhookEventType;
|
|
44
|
+
};
|
|
45
|
+
type ListWebhookDeliveriesInput = PayclaveRequestOptions & {
|
|
46
|
+
limit?: number;
|
|
47
|
+
};
|
|
48
|
+
type PayclaveCreatedCheckoutSession = {
|
|
49
|
+
id: string;
|
|
50
|
+
checkoutId: string;
|
|
51
|
+
object: "checkout_session";
|
|
52
|
+
mode: PayclaveMode;
|
|
53
|
+
status: "pending";
|
|
54
|
+
invoiceId: string;
|
|
55
|
+
invoiceNumber: string;
|
|
56
|
+
amountDue: string;
|
|
57
|
+
currencyCode: string;
|
|
58
|
+
chainId: number;
|
|
59
|
+
tokenSymbol: string;
|
|
60
|
+
tokenContract: string;
|
|
61
|
+
settlementWalletAddress: string;
|
|
62
|
+
externalReference: string | null;
|
|
63
|
+
customerEmail: string | null;
|
|
64
|
+
metadata: PayclaveMetadata;
|
|
65
|
+
checkoutUrl: string;
|
|
66
|
+
expiresAt: string;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
};
|
|
69
|
+
type PayclaveCheckoutSession = {
|
|
70
|
+
id: string;
|
|
71
|
+
checkoutId: string;
|
|
72
|
+
object: "checkout_session";
|
|
73
|
+
mode: PayclaveMode;
|
|
74
|
+
status: PayclaveInvoiceStatus;
|
|
75
|
+
invoiceId: string | null;
|
|
76
|
+
invoiceNumber: string | null;
|
|
77
|
+
externalReference: string | null;
|
|
78
|
+
customerEmail: string | null;
|
|
79
|
+
metadata: PayclaveMetadata;
|
|
80
|
+
checkoutUrl: string;
|
|
81
|
+
expiresAt: string;
|
|
82
|
+
completedAt: string | null;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
};
|
|
85
|
+
type PayclaveInvoice = {
|
|
86
|
+
id: string;
|
|
87
|
+
invoiceNumber: string;
|
|
88
|
+
object: "invoice";
|
|
89
|
+
mode: PayclaveMode;
|
|
90
|
+
status: PayclaveInvoiceStatus;
|
|
91
|
+
amountDue: string;
|
|
92
|
+
amountReceived: string;
|
|
93
|
+
currencyCode: string;
|
|
94
|
+
chainId: number;
|
|
95
|
+
tokenContract: string;
|
|
96
|
+
settlementWalletAddress: string;
|
|
97
|
+
externalReference: string | null;
|
|
98
|
+
metadata: PayclaveMetadata;
|
|
99
|
+
expiresAt: string;
|
|
100
|
+
paidAt: string | null;
|
|
101
|
+
cancelledAt: string | null;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
};
|
|
104
|
+
type PayclavePayment = {
|
|
105
|
+
id: string;
|
|
106
|
+
object: "payment";
|
|
107
|
+
invoiceId: string;
|
|
108
|
+
invoiceNumber: string;
|
|
109
|
+
transactionId: string | null;
|
|
110
|
+
mode: PayclaveMode;
|
|
111
|
+
status: PayclavePaymentStatus;
|
|
112
|
+
amountExpected: string;
|
|
113
|
+
amountReceived: string;
|
|
114
|
+
chainId: number;
|
|
115
|
+
settlementWalletAddress: string;
|
|
116
|
+
failureReason: string | null;
|
|
117
|
+
confirmedAt: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
};
|
|
120
|
+
type PayclaveWebhookEndpoint = {
|
|
121
|
+
id: string;
|
|
122
|
+
object: "webhook_endpoint";
|
|
123
|
+
mode: PayclaveMode;
|
|
124
|
+
url: string;
|
|
125
|
+
enabled: boolean;
|
|
126
|
+
eventTypes: PayclaveWebhookEventType[];
|
|
127
|
+
signingSecret: string;
|
|
128
|
+
createdAt: string;
|
|
129
|
+
};
|
|
130
|
+
type PayclaveWebhookDeliveryAttemptSummary = {
|
|
131
|
+
responseStatusCode: number | null;
|
|
132
|
+
errorMessage: string | null;
|
|
133
|
+
attemptedAt: string;
|
|
134
|
+
};
|
|
135
|
+
type PayclaveWebhookDelivery = {
|
|
136
|
+
id: string;
|
|
137
|
+
object: "webhook_delivery";
|
|
138
|
+
endpointId: string;
|
|
139
|
+
invoiceId: string | null;
|
|
140
|
+
eventType: PayclaveWebhookEventType | (string & {});
|
|
141
|
+
status: PayclaveWebhookDeliveryStatus;
|
|
142
|
+
idempotencyKey: string;
|
|
143
|
+
payload: PayclaveWebhookEvent;
|
|
144
|
+
nextAttemptAt: string;
|
|
145
|
+
deliveredAt: string | null;
|
|
146
|
+
attemptCount: number;
|
|
147
|
+
latestAttempt: PayclaveWebhookDeliveryAttemptSummary | null;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
};
|
|
150
|
+
type PayclaveWebhookData = Record<string, unknown>;
|
|
151
|
+
type PayclaveWebhookEvent<TData = PayclaveWebhookData> = {
|
|
152
|
+
id: string;
|
|
153
|
+
object: "event";
|
|
154
|
+
type: PayclaveWebhookEventType | (string & {});
|
|
155
|
+
mode: PayclaveMode;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
data: TData;
|
|
158
|
+
};
|
|
159
|
+
declare const PAYCLAVE_API_ERROR_CODES: readonly ["API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "AUTH_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
160
|
+
type PayclaveApiErrorCode = (typeof PAYCLAVE_API_ERROR_CODES)[number];
|
|
161
|
+
declare const PAYCLAVE_SERVER_SDK_ERROR_CODES: readonly ["INVALID_SECRET_KEY", "INVALID_API_BASE_URL", "INVALID_TIMEOUT", "INVALID_ID", "INVALID_AMOUNT", "INVALID_EXPIRY", "INVALID_METADATA", "INVALID_IDEMPOTENCY_KEY", "INVALID_LIMIT", "INVALID_WEBHOOK_URL", "INVALID_REQUEST_BODY", "INVALID_RESPONSE", "NETWORK_ERROR", "TIMEOUT", "ABORTED"];
|
|
162
|
+
type PayclaveServerSdkErrorCode = (typeof PAYCLAVE_SERVER_SDK_ERROR_CODES)[number];
|
|
163
|
+
declare const PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES: readonly ["WEBHOOK_SIGNATURE_INVALID", "WEBHOOK_TIMESTAMP_INVALID", "WEBHOOK_TIMESTAMP_OUTSIDE_TOLERANCE", "WEBHOOK_TOLERANCE_INVALID", "WEBHOOK_PAYLOAD_INVALID"];
|
|
164
|
+
type PayclaveWebhookVerificationErrorCode = (typeof PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES)[number];
|
|
165
|
+
type PayclaveErrorCode = PayclaveApiErrorCode | PayclaveServerSdkErrorCode | PayclaveWebhookVerificationErrorCode | (string & {});
|
|
166
|
+
type VerifyWebhookSignatureInput = {
|
|
167
|
+
payload: string | Buffer | Uint8Array;
|
|
168
|
+
signature: string;
|
|
169
|
+
secret: string;
|
|
170
|
+
toleranceSeconds?: number;
|
|
171
|
+
now?: Date | number;
|
|
172
|
+
};
|
|
173
|
+
declare class PayclaveError extends Error {
|
|
174
|
+
code: PayclaveErrorCode;
|
|
175
|
+
status: number;
|
|
176
|
+
requestId: string | null;
|
|
177
|
+
details: unknown;
|
|
178
|
+
constructor({ message, code, status, requestId, details, cause, }: {
|
|
179
|
+
message: string;
|
|
180
|
+
code: PayclaveErrorCode;
|
|
181
|
+
status: number;
|
|
182
|
+
requestId?: string | null;
|
|
183
|
+
details?: unknown;
|
|
184
|
+
cause?: unknown;
|
|
185
|
+
});
|
|
186
|
+
toJSON(): {
|
|
187
|
+
name: string;
|
|
188
|
+
message: string;
|
|
189
|
+
code: PayclaveErrorCode;
|
|
190
|
+
status: number;
|
|
191
|
+
requestId: string | null;
|
|
192
|
+
details: unknown;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
declare const PAYCLAVE_SERVER_SDK_NAME = "payclave-sdk-server";
|
|
196
|
+
declare const PAYCLAVE_SERVER_SDK_VERSION = "0.1.0";
|
|
197
|
+
declare function assertPayclaveWebhookSignature({ payload, signature, secret, toleranceSeconds, now, }: VerifyWebhookSignatureInput): void;
|
|
198
|
+
declare function verifyPayclaveWebhookSignature(input: VerifyWebhookSignatureInput): boolean;
|
|
199
|
+
declare function constructPayclaveWebhookEvent<TData extends PayclaveWebhookData = PayclaveWebhookData>(input: VerifyWebhookSignatureInput): PayclaveWebhookEvent<TData>;
|
|
200
|
+
declare function createPayclaveServerClient({ secretKey, apiBaseUrl, fetcher, timeoutMs, }: PayclaveServerClientOptions): {
|
|
201
|
+
createCheckoutSession: (input: CreateCheckoutSessionInput) => Promise<PayclaveCreatedCheckoutSession>;
|
|
202
|
+
getCheckoutSession: (id: string, options?: PayclaveRequestOptions) => Promise<PayclaveCheckoutSession>;
|
|
203
|
+
createInvoice: (input: CreateInvoiceInput) => Promise<PayclaveInvoice>;
|
|
204
|
+
getInvoice: (id: string, options?: PayclaveRequestOptions) => Promise<PayclaveInvoice>;
|
|
205
|
+
getPayment: (id: string, options?: PayclaveRequestOptions) => Promise<PayclavePayment>;
|
|
206
|
+
createWebhookEndpoint: (input: CreateWebhookEndpointInput) => Promise<PayclaveWebhookEndpoint>;
|
|
207
|
+
createTestWebhook: (input: CreateTestWebhookInput) => Promise<PayclaveWebhookDelivery>;
|
|
208
|
+
listWebhookDeliveries: (input?: ListWebhookDeliveriesInput) => Promise<PayclaveWebhookDelivery[]>;
|
|
209
|
+
};
|
|
210
|
+
type PayclaveServerClient = ReturnType<typeof createPayclaveServerClient>;
|
|
211
|
+
|
|
212
|
+
export { type CreateCheckoutSessionInput, type CreateInvoiceInput, type CreateTestWebhookInput, type CreateWebhookEndpointInput, type ListWebhookDeliveriesInput, PAYCLAVE_API_ERROR_CODES, PAYCLAVE_SERVER_SDK_ERROR_CODES, PAYCLAVE_SERVER_SDK_NAME, PAYCLAVE_SERVER_SDK_VERSION, PAYCLAVE_WEBHOOK_EVENT_TYPES, PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES, type PayclaveApiErrorCode, type PayclaveCheckoutSession, type PayclaveCreatedCheckoutSession, PayclaveError, type PayclaveErrorCode, type PayclaveFetcher, type PayclaveInvoice, type PayclaveInvoiceStatus, type PayclaveMetadata, type PayclaveMode, type PayclavePayment, type PayclavePaymentStatus, type PayclaveRequestOptions, type PayclaveServerClient, type PayclaveServerClientOptions, type PayclaveServerSdkErrorCode, type PayclaveWebhookData, type PayclaveWebhookDelivery, type PayclaveWebhookDeliveryAttemptSummary, type PayclaveWebhookDeliveryStatus, type PayclaveWebhookEndpoint, type PayclaveWebhookEvent, type PayclaveWebhookEventType, type PayclaveWebhookVerificationErrorCode, type VerifyWebhookSignatureInput, assertPayclaveWebhookSignature, constructPayclaveWebhookEvent, createPayclaveServerClient, verifyPayclaveWebhookSignature };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
|
|
3
|
+
type PayclaveMode = "test" | "live" | (string & {});
|
|
4
|
+
type PayclaveInvoiceStatus = "pending" | "processing" | "paid" | "underpaid" | "overpaid" | "expired" | "failed" | "cancelled" | (string & {});
|
|
5
|
+
type PayclavePaymentStatus = "detected" | "validating" | "confirmed" | "failed" | "duplicate" | "underpaid" | "overpaid" | (string & {});
|
|
6
|
+
declare const PAYCLAVE_WEBHOOK_EVENT_TYPES: readonly ["invoice.paid", "invoice.expired", "payment.failed", "payment.underpaid", "payment.overpaid"];
|
|
7
|
+
type PayclaveWebhookEventType = (typeof PAYCLAVE_WEBHOOK_EVENT_TYPES)[number];
|
|
8
|
+
type PayclaveWebhookDeliveryStatus = "pending" | "delivering" | "delivered" | "retry_scheduled" | "failed" | (string & {});
|
|
9
|
+
type PayclaveMetadata = Record<string, unknown>;
|
|
10
|
+
type PayclaveFetcher = (input: string, init: RequestInit) => Promise<Response>;
|
|
11
|
+
type PayclaveServerClientOptions = {
|
|
12
|
+
secretKey: string;
|
|
13
|
+
apiBaseUrl?: string;
|
|
14
|
+
fetcher?: PayclaveFetcher;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
};
|
|
17
|
+
type PayclaveRequestOptions = {
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
};
|
|
20
|
+
type CreateCheckoutSessionInput = PayclaveRequestOptions & {
|
|
21
|
+
amount: string;
|
|
22
|
+
customerEmail?: string;
|
|
23
|
+
externalReference?: string;
|
|
24
|
+
successUrl?: string;
|
|
25
|
+
cancelUrl?: string;
|
|
26
|
+
metadata?: PayclaveMetadata;
|
|
27
|
+
expiresInMinutes?: number;
|
|
28
|
+
idempotencyKey?: string;
|
|
29
|
+
};
|
|
30
|
+
type CreateInvoiceInput = PayclaveRequestOptions & {
|
|
31
|
+
amount: string;
|
|
32
|
+
externalReference?: string;
|
|
33
|
+
metadata?: PayclaveMetadata;
|
|
34
|
+
expiresInMinutes?: number;
|
|
35
|
+
idempotencyKey?: string;
|
|
36
|
+
};
|
|
37
|
+
type CreateWebhookEndpointInput = PayclaveRequestOptions & {
|
|
38
|
+
url: string;
|
|
39
|
+
eventTypes?: PayclaveWebhookEventType[];
|
|
40
|
+
};
|
|
41
|
+
type CreateTestWebhookInput = PayclaveRequestOptions & {
|
|
42
|
+
endpointId: string;
|
|
43
|
+
eventType?: PayclaveWebhookEventType;
|
|
44
|
+
};
|
|
45
|
+
type ListWebhookDeliveriesInput = PayclaveRequestOptions & {
|
|
46
|
+
limit?: number;
|
|
47
|
+
};
|
|
48
|
+
type PayclaveCreatedCheckoutSession = {
|
|
49
|
+
id: string;
|
|
50
|
+
checkoutId: string;
|
|
51
|
+
object: "checkout_session";
|
|
52
|
+
mode: PayclaveMode;
|
|
53
|
+
status: "pending";
|
|
54
|
+
invoiceId: string;
|
|
55
|
+
invoiceNumber: string;
|
|
56
|
+
amountDue: string;
|
|
57
|
+
currencyCode: string;
|
|
58
|
+
chainId: number;
|
|
59
|
+
tokenSymbol: string;
|
|
60
|
+
tokenContract: string;
|
|
61
|
+
settlementWalletAddress: string;
|
|
62
|
+
externalReference: string | null;
|
|
63
|
+
customerEmail: string | null;
|
|
64
|
+
metadata: PayclaveMetadata;
|
|
65
|
+
checkoutUrl: string;
|
|
66
|
+
expiresAt: string;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
};
|
|
69
|
+
type PayclaveCheckoutSession = {
|
|
70
|
+
id: string;
|
|
71
|
+
checkoutId: string;
|
|
72
|
+
object: "checkout_session";
|
|
73
|
+
mode: PayclaveMode;
|
|
74
|
+
status: PayclaveInvoiceStatus;
|
|
75
|
+
invoiceId: string | null;
|
|
76
|
+
invoiceNumber: string | null;
|
|
77
|
+
externalReference: string | null;
|
|
78
|
+
customerEmail: string | null;
|
|
79
|
+
metadata: PayclaveMetadata;
|
|
80
|
+
checkoutUrl: string;
|
|
81
|
+
expiresAt: string;
|
|
82
|
+
completedAt: string | null;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
};
|
|
85
|
+
type PayclaveInvoice = {
|
|
86
|
+
id: string;
|
|
87
|
+
invoiceNumber: string;
|
|
88
|
+
object: "invoice";
|
|
89
|
+
mode: PayclaveMode;
|
|
90
|
+
status: PayclaveInvoiceStatus;
|
|
91
|
+
amountDue: string;
|
|
92
|
+
amountReceived: string;
|
|
93
|
+
currencyCode: string;
|
|
94
|
+
chainId: number;
|
|
95
|
+
tokenContract: string;
|
|
96
|
+
settlementWalletAddress: string;
|
|
97
|
+
externalReference: string | null;
|
|
98
|
+
metadata: PayclaveMetadata;
|
|
99
|
+
expiresAt: string;
|
|
100
|
+
paidAt: string | null;
|
|
101
|
+
cancelledAt: string | null;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
};
|
|
104
|
+
type PayclavePayment = {
|
|
105
|
+
id: string;
|
|
106
|
+
object: "payment";
|
|
107
|
+
invoiceId: string;
|
|
108
|
+
invoiceNumber: string;
|
|
109
|
+
transactionId: string | null;
|
|
110
|
+
mode: PayclaveMode;
|
|
111
|
+
status: PayclavePaymentStatus;
|
|
112
|
+
amountExpected: string;
|
|
113
|
+
amountReceived: string;
|
|
114
|
+
chainId: number;
|
|
115
|
+
settlementWalletAddress: string;
|
|
116
|
+
failureReason: string | null;
|
|
117
|
+
confirmedAt: string | null;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
};
|
|
120
|
+
type PayclaveWebhookEndpoint = {
|
|
121
|
+
id: string;
|
|
122
|
+
object: "webhook_endpoint";
|
|
123
|
+
mode: PayclaveMode;
|
|
124
|
+
url: string;
|
|
125
|
+
enabled: boolean;
|
|
126
|
+
eventTypes: PayclaveWebhookEventType[];
|
|
127
|
+
signingSecret: string;
|
|
128
|
+
createdAt: string;
|
|
129
|
+
};
|
|
130
|
+
type PayclaveWebhookDeliveryAttemptSummary = {
|
|
131
|
+
responseStatusCode: number | null;
|
|
132
|
+
errorMessage: string | null;
|
|
133
|
+
attemptedAt: string;
|
|
134
|
+
};
|
|
135
|
+
type PayclaveWebhookDelivery = {
|
|
136
|
+
id: string;
|
|
137
|
+
object: "webhook_delivery";
|
|
138
|
+
endpointId: string;
|
|
139
|
+
invoiceId: string | null;
|
|
140
|
+
eventType: PayclaveWebhookEventType | (string & {});
|
|
141
|
+
status: PayclaveWebhookDeliveryStatus;
|
|
142
|
+
idempotencyKey: string;
|
|
143
|
+
payload: PayclaveWebhookEvent;
|
|
144
|
+
nextAttemptAt: string;
|
|
145
|
+
deliveredAt: string | null;
|
|
146
|
+
attemptCount: number;
|
|
147
|
+
latestAttempt: PayclaveWebhookDeliveryAttemptSummary | null;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
};
|
|
150
|
+
type PayclaveWebhookData = Record<string, unknown>;
|
|
151
|
+
type PayclaveWebhookEvent<TData = PayclaveWebhookData> = {
|
|
152
|
+
id: string;
|
|
153
|
+
object: "event";
|
|
154
|
+
type: PayclaveWebhookEventType | (string & {});
|
|
155
|
+
mode: PayclaveMode;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
data: TData;
|
|
158
|
+
};
|
|
159
|
+
declare const PAYCLAVE_API_ERROR_CODES: readonly ["API_KEY_FORBIDDEN", "API_KEY_REQUIRED", "AUTH_FORBIDDEN", "AUTH_REQUIRED", "DEFAULT_WALLET_REQUIRED", "INTERNAL_JOB_UNAUTHORIZED", "INTERNAL_SERVER_ERROR", "INVALID_AMOUNT", "INVALID_API_KEY", "INVALID_EXPIRY", "INVALID_IDEMPOTENCY_KEY", "INVALID_DEPOSIT_NETWORK", "INVALID_WALLET_PAYMENT_ATTEMPT", "INVALID_TX_HASH", "INVALID_WALLET_ADDRESS", "NOT_FOUND", "RATE_LIMIT_EXCEEDED", "REQUEST_ERROR", "SCAN_OR_COPY_UNAVAILABLE", "WALLET_PAYMENTS_UNAVAILABLE", "UNSUPPORTED_DEFAULT_WALLET", "VALIDATION_ERROR", "WEBHOOK_DELIVERY_NOT_FOUND", "WEBHOOK_ENDPOINT_NOT_FOUND", "WEBHOOK_EVENT_UNSUPPORTED", "WEBHOOK_SIGNATURE_INVALID", "CHECKOUT_SESSION_NOT_PAYABLE", "INVOICE_NOT_FOUND", "INVOICE_STATE_MISMATCH", "INVOICE_TRANSITION_GUARD_FAILED", "IDEMPOTENCY_KEY_CONFLICT"];
|
|
160
|
+
type PayclaveApiErrorCode = (typeof PAYCLAVE_API_ERROR_CODES)[number];
|
|
161
|
+
declare const PAYCLAVE_SERVER_SDK_ERROR_CODES: readonly ["INVALID_SECRET_KEY", "INVALID_API_BASE_URL", "INVALID_TIMEOUT", "INVALID_ID", "INVALID_AMOUNT", "INVALID_EXPIRY", "INVALID_METADATA", "INVALID_IDEMPOTENCY_KEY", "INVALID_LIMIT", "INVALID_WEBHOOK_URL", "INVALID_REQUEST_BODY", "INVALID_RESPONSE", "NETWORK_ERROR", "TIMEOUT", "ABORTED"];
|
|
162
|
+
type PayclaveServerSdkErrorCode = (typeof PAYCLAVE_SERVER_SDK_ERROR_CODES)[number];
|
|
163
|
+
declare const PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES: readonly ["WEBHOOK_SIGNATURE_INVALID", "WEBHOOK_TIMESTAMP_INVALID", "WEBHOOK_TIMESTAMP_OUTSIDE_TOLERANCE", "WEBHOOK_TOLERANCE_INVALID", "WEBHOOK_PAYLOAD_INVALID"];
|
|
164
|
+
type PayclaveWebhookVerificationErrorCode = (typeof PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES)[number];
|
|
165
|
+
type PayclaveErrorCode = PayclaveApiErrorCode | PayclaveServerSdkErrorCode | PayclaveWebhookVerificationErrorCode | (string & {});
|
|
166
|
+
type VerifyWebhookSignatureInput = {
|
|
167
|
+
payload: string | Buffer | Uint8Array;
|
|
168
|
+
signature: string;
|
|
169
|
+
secret: string;
|
|
170
|
+
toleranceSeconds?: number;
|
|
171
|
+
now?: Date | number;
|
|
172
|
+
};
|
|
173
|
+
declare class PayclaveError extends Error {
|
|
174
|
+
code: PayclaveErrorCode;
|
|
175
|
+
status: number;
|
|
176
|
+
requestId: string | null;
|
|
177
|
+
details: unknown;
|
|
178
|
+
constructor({ message, code, status, requestId, details, cause, }: {
|
|
179
|
+
message: string;
|
|
180
|
+
code: PayclaveErrorCode;
|
|
181
|
+
status: number;
|
|
182
|
+
requestId?: string | null;
|
|
183
|
+
details?: unknown;
|
|
184
|
+
cause?: unknown;
|
|
185
|
+
});
|
|
186
|
+
toJSON(): {
|
|
187
|
+
name: string;
|
|
188
|
+
message: string;
|
|
189
|
+
code: PayclaveErrorCode;
|
|
190
|
+
status: number;
|
|
191
|
+
requestId: string | null;
|
|
192
|
+
details: unknown;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
declare const PAYCLAVE_SERVER_SDK_NAME = "payclave-sdk-server";
|
|
196
|
+
declare const PAYCLAVE_SERVER_SDK_VERSION = "0.1.0";
|
|
197
|
+
declare function assertPayclaveWebhookSignature({ payload, signature, secret, toleranceSeconds, now, }: VerifyWebhookSignatureInput): void;
|
|
198
|
+
declare function verifyPayclaveWebhookSignature(input: VerifyWebhookSignatureInput): boolean;
|
|
199
|
+
declare function constructPayclaveWebhookEvent<TData extends PayclaveWebhookData = PayclaveWebhookData>(input: VerifyWebhookSignatureInput): PayclaveWebhookEvent<TData>;
|
|
200
|
+
declare function createPayclaveServerClient({ secretKey, apiBaseUrl, fetcher, timeoutMs, }: PayclaveServerClientOptions): {
|
|
201
|
+
createCheckoutSession: (input: CreateCheckoutSessionInput) => Promise<PayclaveCreatedCheckoutSession>;
|
|
202
|
+
getCheckoutSession: (id: string, options?: PayclaveRequestOptions) => Promise<PayclaveCheckoutSession>;
|
|
203
|
+
createInvoice: (input: CreateInvoiceInput) => Promise<PayclaveInvoice>;
|
|
204
|
+
getInvoice: (id: string, options?: PayclaveRequestOptions) => Promise<PayclaveInvoice>;
|
|
205
|
+
getPayment: (id: string, options?: PayclaveRequestOptions) => Promise<PayclavePayment>;
|
|
206
|
+
createWebhookEndpoint: (input: CreateWebhookEndpointInput) => Promise<PayclaveWebhookEndpoint>;
|
|
207
|
+
createTestWebhook: (input: CreateTestWebhookInput) => Promise<PayclaveWebhookDelivery>;
|
|
208
|
+
listWebhookDeliveries: (input?: ListWebhookDeliveriesInput) => Promise<PayclaveWebhookDelivery[]>;
|
|
209
|
+
};
|
|
210
|
+
type PayclaveServerClient = ReturnType<typeof createPayclaveServerClient>;
|
|
211
|
+
|
|
212
|
+
export { type CreateCheckoutSessionInput, type CreateInvoiceInput, type CreateTestWebhookInput, type CreateWebhookEndpointInput, type ListWebhookDeliveriesInput, PAYCLAVE_API_ERROR_CODES, PAYCLAVE_SERVER_SDK_ERROR_CODES, PAYCLAVE_SERVER_SDK_NAME, PAYCLAVE_SERVER_SDK_VERSION, PAYCLAVE_WEBHOOK_EVENT_TYPES, PAYCLAVE_WEBHOOK_VERIFICATION_ERROR_CODES, type PayclaveApiErrorCode, type PayclaveCheckoutSession, type PayclaveCreatedCheckoutSession, PayclaveError, type PayclaveErrorCode, type PayclaveFetcher, type PayclaveInvoice, type PayclaveInvoiceStatus, type PayclaveMetadata, type PayclaveMode, type PayclavePayment, type PayclavePaymentStatus, type PayclaveRequestOptions, type PayclaveServerClient, type PayclaveServerClientOptions, type PayclaveServerSdkErrorCode, type PayclaveWebhookData, type PayclaveWebhookDelivery, type PayclaveWebhookDeliveryAttemptSummary, type PayclaveWebhookDeliveryStatus, type PayclaveWebhookEndpoint, type PayclaveWebhookEvent, type PayclaveWebhookEventType, type PayclaveWebhookVerificationErrorCode, type VerifyWebhookSignatureInput, assertPayclaveWebhookSignature, constructPayclaveWebhookEvent, createPayclaveServerClient, verifyPayclaveWebhookSignature };
|