@waffo/pancake-nextjs 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 +22 -0
- package/README.md +371 -0
- package/dist/index.cjs +466 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +560 -0
- package/dist/index.d.ts +560 -0
- package/dist/index.js +427 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +82 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +96 -0
- package/dist/server.d.ts +96 -0
- package/dist/server.js +54 -0
- package/dist/server.js.map +1 -0
- package/package.json +96 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AnonymousCheckoutParams, AuthenticatedCheckoutParams, CheckoutSessionResult, AuthenticatedCheckoutResult, IssueSessionTokenParams, SessionToken, GraphQLParams, GraphQLResponse, CancelSubscriptionParams, CancelSubscriptionResult, CancelOnetimeOrderParams, CancelOnetimeOrderResult, ReactivateSubscriptionParams, ReactivateSubscriptionResult, CreateRefundTicketParams, RefundTicket, ResubmitRefundTicketParams, VerifyWebhookOptions, WebhookEventData, WebhookEvent } from '@waffo/pancake-ts';
|
|
4
|
+
export { BillingDetail, PriceInfo, TaxCategory, WaffoPancakeError, WebhookEvent, WebhookEventData, WebhookEventType } from '@waffo/pancake-ts';
|
|
5
|
+
|
|
6
|
+
/** Parameters for the checkout server action */
|
|
7
|
+
type CheckoutActionParams = ({
|
|
8
|
+
type?: "anonymous";
|
|
9
|
+
} & AnonymousCheckoutParams) | ({
|
|
10
|
+
type: "authenticated";
|
|
11
|
+
} & AuthenticatedCheckoutParams);
|
|
12
|
+
/** Result of the checkout server action */
|
|
13
|
+
type CheckoutActionResult = CheckoutSessionResult | AuthenticatedCheckoutResult;
|
|
14
|
+
/** Server action signature for checkout */
|
|
15
|
+
type CheckoutAction = (params: CheckoutActionParams) => Promise<CheckoutActionResult>;
|
|
16
|
+
/** Server action signature for issuing buyer tokens */
|
|
17
|
+
type BuyerTokenAction = (params: IssueSessionTokenParams) => Promise<SessionToken>;
|
|
18
|
+
/** Buyer action types */
|
|
19
|
+
type BuyerSessionActionType = "cancelSubscription" | "cancelOnetimeOrder" | "reactivateSubscription" | "createRefundTicket" | "resubmitRefundTicket" | "query";
|
|
20
|
+
/** Server action signature for buyer session operations */
|
|
21
|
+
type BuyerSessionAction = (token: string, actionType: BuyerSessionActionType, params: unknown) => Promise<unknown>;
|
|
22
|
+
/** Server action signature for merchant GraphQL queries */
|
|
23
|
+
type MerchantQueryAction = (params: GraphQLParams) => Promise<GraphQLResponse>;
|
|
24
|
+
|
|
25
|
+
/** Buyer configuration for automatic token management */
|
|
26
|
+
interface BuyerConfig {
|
|
27
|
+
/** Buyer identity (email or merchant-provided identifier) */
|
|
28
|
+
identity: string;
|
|
29
|
+
/** Store ID (optional when `productId` is provided) */
|
|
30
|
+
storeId?: string;
|
|
31
|
+
/** Product ID — used to derive the store when `storeId` is omitted */
|
|
32
|
+
productId?: string;
|
|
33
|
+
/** Server action for issuing tokens — from `createBuyerTokenAction()` */
|
|
34
|
+
issueToken: BuyerTokenAction;
|
|
35
|
+
/** Server action for buyer operations — from `createBuyerSessionAction()` */
|
|
36
|
+
sessionAction: BuyerSessionAction;
|
|
37
|
+
}
|
|
38
|
+
interface WaffoPancakeProviderProps {
|
|
39
|
+
/** Buyer configuration for automatic token management */
|
|
40
|
+
buyer: BuyerConfig;
|
|
41
|
+
children: React.ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Provider that manages buyer token lifecycle via server actions.
|
|
45
|
+
*
|
|
46
|
+
* Auto-issues session tokens on mount and refreshes before expiry.
|
|
47
|
+
* All buyer hooks (`useBuyer`, `useBuyerOrders`, etc.) read from context.
|
|
48
|
+
*
|
|
49
|
+
* The private key never leaves the server — token issuance and buyer
|
|
50
|
+
* operations are delegated to server actions.
|
|
51
|
+
*
|
|
52
|
+
* @param props - Provider configuration
|
|
53
|
+
* @param props.buyer - Buyer identity and server actions
|
|
54
|
+
* @param props.children - React children
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <WaffoPancakeProvider buyer={{
|
|
59
|
+
* identity: user.email,
|
|
60
|
+
* storeId: "STO_xxx",
|
|
61
|
+
* issueToken, // from createBuyerTokenAction()
|
|
62
|
+
* sessionAction, // from createBuyerSessionAction()
|
|
63
|
+
* }}>
|
|
64
|
+
* <App />
|
|
65
|
+
* </WaffoPancakeProvider>
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function WaffoPancakeProvider({ buyer, children }: WaffoPancakeProviderProps): react_jsx_runtime.JSX.Element;
|
|
69
|
+
|
|
70
|
+
/** Redirect mode for checkout navigation */
|
|
71
|
+
type CheckoutMode = "redirect" | "popup";
|
|
72
|
+
/** Base checkout options shared by all checkout types */
|
|
73
|
+
interface CheckoutBaseOptions {
|
|
74
|
+
/** How to navigate to checkout page. Default: `"redirect"` */
|
|
75
|
+
mode?: CheckoutMode;
|
|
76
|
+
/**
|
|
77
|
+
* Loading page URL shown in popup while checkout session is being created.
|
|
78
|
+
* Only used when `mode` is `"popup"`. Defaults to a minimal inline loading page.
|
|
79
|
+
*/
|
|
80
|
+
popupLoadingUrl?: string;
|
|
81
|
+
/** Callback fired on error */
|
|
82
|
+
onError?: (error: Error) => void;
|
|
83
|
+
}
|
|
84
|
+
/** Link checkout — redirects to product page URL, no API call needed */
|
|
85
|
+
interface LinkCheckoutProps extends CheckoutBaseOptions {
|
|
86
|
+
type: "link";
|
|
87
|
+
/** Store slug (from Dashboard) */
|
|
88
|
+
storeSlug: string;
|
|
89
|
+
/** Product ID */
|
|
90
|
+
productId: string;
|
|
91
|
+
/** Currency code (ISO 4217). If omitted, product page auto-detects. */
|
|
92
|
+
currency?: string;
|
|
93
|
+
/** Pre-fill buyer email */
|
|
94
|
+
email?: string;
|
|
95
|
+
/** Redirect URL after successful payment */
|
|
96
|
+
successUrl?: string;
|
|
97
|
+
/** Use test environment */
|
|
98
|
+
test?: boolean;
|
|
99
|
+
/** Pre-fill billing country (ISO 3166-1) */
|
|
100
|
+
country?: string;
|
|
101
|
+
/** Is business purchase */
|
|
102
|
+
isBusiness?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Base URL of the storefront. Default: `"https://pancake.waffo.ai"`
|
|
105
|
+
*/
|
|
106
|
+
baseUrl?: string;
|
|
107
|
+
}
|
|
108
|
+
/** Anonymous checkout — creates session via server action */
|
|
109
|
+
type AnonymousCheckoutProps = CheckoutBaseOptions & {
|
|
110
|
+
type?: "anonymous";
|
|
111
|
+
/** Server action created by `createCheckoutAction()` */
|
|
112
|
+
action: CheckoutAction;
|
|
113
|
+
/** Callback fired when checkout session is successfully created */
|
|
114
|
+
onSuccess?: (result: CheckoutSessionResult) => void;
|
|
115
|
+
} & AnonymousCheckoutParams;
|
|
116
|
+
/** Authenticated checkout — creates session + token via server action */
|
|
117
|
+
type AuthenticatedCheckoutProps = CheckoutBaseOptions & {
|
|
118
|
+
type: "authenticated";
|
|
119
|
+
/** Server action created by `createCheckoutAction()` */
|
|
120
|
+
action: CheckoutAction;
|
|
121
|
+
/** Callback fired when checkout session is successfully created */
|
|
122
|
+
onSuccess?: (result: AuthenticatedCheckoutResult) => void;
|
|
123
|
+
} & AuthenticatedCheckoutParams;
|
|
124
|
+
/** Union of all checkout prop types */
|
|
125
|
+
type CheckoutProps = LinkCheckoutProps | AnonymousCheckoutProps | AuthenticatedCheckoutProps;
|
|
126
|
+
/** Return type of useCheckout hook */
|
|
127
|
+
interface UseCheckoutReturn {
|
|
128
|
+
/** Trigger the checkout flow */
|
|
129
|
+
checkout: () => void;
|
|
130
|
+
/** Whether a checkout session is being created */
|
|
131
|
+
isLoading: boolean;
|
|
132
|
+
/** Error from the last checkout attempt, if any */
|
|
133
|
+
error: Error | null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
type CheckoutButtonBaseProps = {
|
|
137
|
+
/** Button content */
|
|
138
|
+
children: React.ReactNode;
|
|
139
|
+
/** Content shown while checkout session is being created */
|
|
140
|
+
loadingChildren?: React.ReactNode;
|
|
141
|
+
/** Additional class name */
|
|
142
|
+
className?: string;
|
|
143
|
+
/** Additional inline styles */
|
|
144
|
+
style?: React.CSSProperties;
|
|
145
|
+
/** Disabled state (merged with isLoading) */
|
|
146
|
+
disabled?: boolean;
|
|
147
|
+
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick" | "disabled" | "children">;
|
|
148
|
+
/** Props for CheckoutButton — link mode */
|
|
149
|
+
type LinkCheckoutButtonProps = CheckoutButtonBaseProps & LinkCheckoutProps;
|
|
150
|
+
/** Props for CheckoutButton — anonymous mode */
|
|
151
|
+
type AnonymousCheckoutButtonProps = CheckoutButtonBaseProps & AnonymousCheckoutProps;
|
|
152
|
+
/** Props for CheckoutButton — authenticated mode */
|
|
153
|
+
type AuthenticatedCheckoutButtonProps = CheckoutButtonBaseProps & AuthenticatedCheckoutProps;
|
|
154
|
+
type CheckoutButtonProps = LinkCheckoutButtonProps | AnonymousCheckoutButtonProps | AuthenticatedCheckoutButtonProps;
|
|
155
|
+
/**
|
|
156
|
+
* A button that triggers a Waffo Pancake checkout flow on click.
|
|
157
|
+
*
|
|
158
|
+
* Three checkout types:
|
|
159
|
+
* - **link**: Instant redirect to product page URL (no server action needed)
|
|
160
|
+
* - **anonymous**: Calls server action to create session, then redirects
|
|
161
|
+
* - **authenticated**: Calls server action to create session + token, then redirects
|
|
162
|
+
*
|
|
163
|
+
* The private key never leaves the server — anonymous and authenticated modes
|
|
164
|
+
* use a server action created by `createCheckoutAction()`.
|
|
165
|
+
*
|
|
166
|
+
* @param props - Flattened checkout props, button content, and optional styling
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```tsx
|
|
170
|
+
* // Link checkout — no server action needed
|
|
171
|
+
* <CheckoutButton type="link" storeSlug="my-store" productId="PROD_xxx" currency="USD">
|
|
172
|
+
* Buy Now
|
|
173
|
+
* </CheckoutButton>
|
|
174
|
+
*
|
|
175
|
+
* // Anonymous checkout — via server action
|
|
176
|
+
* <CheckoutButton action={checkout} productId="PROD_xxx" currency="USD">
|
|
177
|
+
* Buy Now
|
|
178
|
+
* </CheckoutButton>
|
|
179
|
+
*
|
|
180
|
+
* // Authenticated checkout — via server action
|
|
181
|
+
* <CheckoutButton action={checkout} type="authenticated" productId="PROD_xxx" currency="USD" buyerIdentity="user@example.com">
|
|
182
|
+
* Buy Now
|
|
183
|
+
* </CheckoutButton>
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function CheckoutButton(props: CheckoutButtonProps): react_jsx_runtime.JSX.Element;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* React hook for triggering a Waffo Pancake checkout flow.
|
|
190
|
+
*
|
|
191
|
+
* Supports three checkout types:
|
|
192
|
+
* - **link**: Builds a product page URL and navigates directly (no API call, synchronous)
|
|
193
|
+
* - **anonymous**: Calls a server action to create a checkout session, then navigates
|
|
194
|
+
* - **authenticated**: Calls a server action to create a session + token, then navigates
|
|
195
|
+
*
|
|
196
|
+
* The private key never leaves the server — anonymous and authenticated modes
|
|
197
|
+
* use a server action created by `createCheckoutAction()`.
|
|
198
|
+
*
|
|
199
|
+
* @param args - Flattened checkout props
|
|
200
|
+
* @returns `{ checkout, isLoading, error }`
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```tsx
|
|
204
|
+
* // Link checkout — no server action needed
|
|
205
|
+
* const { checkout } = useCheckout({
|
|
206
|
+
* type: "link",
|
|
207
|
+
* storeSlug: "my-store",
|
|
208
|
+
* productId: "PROD_xxx",
|
|
209
|
+
* currency: "USD",
|
|
210
|
+
* });
|
|
211
|
+
*
|
|
212
|
+
* // Anonymous checkout — via server action
|
|
213
|
+
* const { checkout, isLoading } = useCheckout({
|
|
214
|
+
* action: checkout, // from createCheckoutAction()
|
|
215
|
+
* productId: "PROD_xxx",
|
|
216
|
+
* currency: "USD",
|
|
217
|
+
* });
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function useCheckout(args: CheckoutProps): UseCheckoutReturn;
|
|
221
|
+
|
|
222
|
+
/** State of an async buyer action */
|
|
223
|
+
interface BuyerActionState<T = unknown> {
|
|
224
|
+
/** Execute the action */
|
|
225
|
+
execute: (params: T) => Promise<void>;
|
|
226
|
+
/** Whether the action is in progress */
|
|
227
|
+
isLoading: boolean;
|
|
228
|
+
/** Error from the last attempt */
|
|
229
|
+
error: Error | null;
|
|
230
|
+
}
|
|
231
|
+
/** Return type of useBuyer hook */
|
|
232
|
+
interface UseBuyerReturn {
|
|
233
|
+
/** Cancel a subscription order */
|
|
234
|
+
cancelSubscription: BuyerActionState<CancelSubscriptionParams> & {
|
|
235
|
+
data: CancelSubscriptionResult | null;
|
|
236
|
+
};
|
|
237
|
+
/** Cancel a one-time order */
|
|
238
|
+
cancelOnetimeOrder: BuyerActionState<CancelOnetimeOrderParams> & {
|
|
239
|
+
data: CancelOnetimeOrderResult | null;
|
|
240
|
+
};
|
|
241
|
+
/** Reactivate a canceling subscription */
|
|
242
|
+
reactivateSubscription: BuyerActionState<ReactivateSubscriptionParams> & {
|
|
243
|
+
data: ReactivateSubscriptionResult | null;
|
|
244
|
+
};
|
|
245
|
+
/** Create a refund ticket */
|
|
246
|
+
createRefundTicket: BuyerActionState<CreateRefundTicketParams> & {
|
|
247
|
+
data: RefundTicket | null;
|
|
248
|
+
};
|
|
249
|
+
/** Resubmit a rejected refund ticket */
|
|
250
|
+
resubmitRefundTicket: BuyerActionState<ResubmitRefundTicketParams> & {
|
|
251
|
+
data: RefundTicket | null;
|
|
252
|
+
};
|
|
253
|
+
/** Execute a GraphQL query */
|
|
254
|
+
query: <T = Record<string, unknown>>(params: GraphQLParams) => Promise<GraphQLResponse<T>>;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* React hook for buyer self-service actions.
|
|
258
|
+
*
|
|
259
|
+
* Must be used within `<WaffoPancakeProvider>`. All operations are executed
|
|
260
|
+
* via server actions — the private key never leaves the server.
|
|
261
|
+
*
|
|
262
|
+
* @returns Buyer action handlers with loading/error states
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```tsx
|
|
266
|
+
* function AccountPage() {
|
|
267
|
+
* const buyer = useBuyer();
|
|
268
|
+
* return (
|
|
269
|
+
* <button onClick={() => buyer.cancelSubscription.execute({ orderId: "ORD_xxx" })}>
|
|
270
|
+
* Cancel
|
|
271
|
+
* </button>
|
|
272
|
+
* );
|
|
273
|
+
* }
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
declare function useBuyer(): UseBuyerReturn;
|
|
277
|
+
|
|
278
|
+
/** Query state with typed data */
|
|
279
|
+
interface QueryState<T> {
|
|
280
|
+
data: T | null;
|
|
281
|
+
isLoading: boolean;
|
|
282
|
+
error: Error | null;
|
|
283
|
+
refetch: () => void;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A buyer's one-time order */
|
|
287
|
+
interface BuyerOnetimeOrder {
|
|
288
|
+
id: string;
|
|
289
|
+
status: string;
|
|
290
|
+
currency: string;
|
|
291
|
+
buyerEmail: string;
|
|
292
|
+
product: {
|
|
293
|
+
id: string;
|
|
294
|
+
name: string;
|
|
295
|
+
} | null;
|
|
296
|
+
payments: Array<{
|
|
297
|
+
id: string;
|
|
298
|
+
status: string;
|
|
299
|
+
snapshotDisplayAmount: string;
|
|
300
|
+
snapshotDisplayCurrency: string;
|
|
301
|
+
createdAt: string;
|
|
302
|
+
}>;
|
|
303
|
+
createdAt: string;
|
|
304
|
+
}
|
|
305
|
+
/** A buyer's subscription order */
|
|
306
|
+
interface BuyerSubscriptionOrder {
|
|
307
|
+
id: string;
|
|
308
|
+
status: string;
|
|
309
|
+
currency: string;
|
|
310
|
+
buyerEmail: string;
|
|
311
|
+
currentPeriodStart: string | null;
|
|
312
|
+
currentPeriodEnd: string | null;
|
|
313
|
+
cancelAt: string | null;
|
|
314
|
+
product: {
|
|
315
|
+
id: string;
|
|
316
|
+
name: string;
|
|
317
|
+
billingPeriod: string;
|
|
318
|
+
} | null;
|
|
319
|
+
payments: Array<{
|
|
320
|
+
id: string;
|
|
321
|
+
status: string;
|
|
322
|
+
snapshotDisplayAmount: string;
|
|
323
|
+
snapshotDisplayCurrency: string;
|
|
324
|
+
createdAt: string;
|
|
325
|
+
}>;
|
|
326
|
+
createdAt: string;
|
|
327
|
+
}
|
|
328
|
+
/** A buyer's payment record */
|
|
329
|
+
interface BuyerPayment {
|
|
330
|
+
id: string;
|
|
331
|
+
orderId: string;
|
|
332
|
+
status: string;
|
|
333
|
+
snapshotDisplayAmount: string;
|
|
334
|
+
snapshotDisplayCurrency: string;
|
|
335
|
+
failureReason: string | null;
|
|
336
|
+
createdAt: string;
|
|
337
|
+
}
|
|
338
|
+
/** A buyer's refund ticket */
|
|
339
|
+
interface BuyerRefundTicket {
|
|
340
|
+
id: string;
|
|
341
|
+
status: string;
|
|
342
|
+
reason: string;
|
|
343
|
+
requestedAmount: string;
|
|
344
|
+
requestedCurrency: string;
|
|
345
|
+
createdAt: string;
|
|
346
|
+
}
|
|
347
|
+
interface BuyerOrdersData {
|
|
348
|
+
onetimeOrders: BuyerOnetimeOrder[];
|
|
349
|
+
subscriptionOrders: BuyerSubscriptionOrder[];
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Fetch the buyer's order history (one-time + subscription).
|
|
353
|
+
*
|
|
354
|
+
* Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
|
|
355
|
+
*
|
|
356
|
+
* @returns Orders with product info and payment history
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```tsx
|
|
360
|
+
* const { data, isLoading, refetch } = useBuyerOrders();
|
|
361
|
+
* // data.onetimeOrders + data.subscriptionOrders
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
declare function useBuyerOrders(): QueryState<BuyerOrdersData>;
|
|
365
|
+
/**
|
|
366
|
+
* Fetch the buyer's payment history.
|
|
367
|
+
*
|
|
368
|
+
* Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
|
|
369
|
+
*
|
|
370
|
+
* @returns Payment records with amounts and status
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```tsx
|
|
374
|
+
* const { data: payments, isLoading } = useBuyerPayments();
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
declare function useBuyerPayments(): QueryState<BuyerPayment[]>;
|
|
378
|
+
/**
|
|
379
|
+
* Fetch the buyer's refund tickets.
|
|
380
|
+
*
|
|
381
|
+
* Must be used within `<WaffoPancakeProvider>`. Token is auto-managed.
|
|
382
|
+
*
|
|
383
|
+
* @returns Refund tickets with status and requested amounts
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```tsx
|
|
387
|
+
* const { data: tickets, isLoading } = useBuyerRefundTickets();
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
declare function useBuyerRefundTickets(): QueryState<BuyerRefundTicket[]>;
|
|
391
|
+
|
|
392
|
+
/** A merchant's recent order (one-time or subscription) */
|
|
393
|
+
interface MerchantOrder {
|
|
394
|
+
id: string;
|
|
395
|
+
status: string;
|
|
396
|
+
currency: string;
|
|
397
|
+
buyerEmail: string;
|
|
398
|
+
testMode: boolean;
|
|
399
|
+
product: {
|
|
400
|
+
id: string;
|
|
401
|
+
name: string;
|
|
402
|
+
} | null;
|
|
403
|
+
payments: Array<{
|
|
404
|
+
id: string;
|
|
405
|
+
status: string;
|
|
406
|
+
snapshotDisplayAmount: string;
|
|
407
|
+
snapshotDisplayCurrency: string;
|
|
408
|
+
}>;
|
|
409
|
+
createdAt: string;
|
|
410
|
+
}
|
|
411
|
+
/** Sales overview statistics */
|
|
412
|
+
interface SalesOverview {
|
|
413
|
+
totalOrders: number;
|
|
414
|
+
totalRevenue: string;
|
|
415
|
+
totalCustomers: number;
|
|
416
|
+
currency: string;
|
|
417
|
+
ordersByStatus: Array<{
|
|
418
|
+
status: string;
|
|
419
|
+
count: number;
|
|
420
|
+
}>;
|
|
421
|
+
revenueByPeriod: Array<{
|
|
422
|
+
period: string;
|
|
423
|
+
amount: string;
|
|
424
|
+
}>;
|
|
425
|
+
}
|
|
426
|
+
/** Subscription overview */
|
|
427
|
+
interface SubscriptionOverview {
|
|
428
|
+
activeCount: number;
|
|
429
|
+
cancelingCount: number;
|
|
430
|
+
pastDueCount: number;
|
|
431
|
+
totalCount: number;
|
|
432
|
+
subscriptions: MerchantSubscription[];
|
|
433
|
+
}
|
|
434
|
+
/** A merchant's subscription with status details */
|
|
435
|
+
interface MerchantSubscription {
|
|
436
|
+
id: string;
|
|
437
|
+
status: string;
|
|
438
|
+
currency: string;
|
|
439
|
+
buyerEmail: string;
|
|
440
|
+
currentPeriodStart: string | null;
|
|
441
|
+
currentPeriodEnd: string | null;
|
|
442
|
+
cancelAt: string | null;
|
|
443
|
+
product: {
|
|
444
|
+
id: string;
|
|
445
|
+
name: string;
|
|
446
|
+
billingPeriod: string;
|
|
447
|
+
} | null;
|
|
448
|
+
createdAt: string;
|
|
449
|
+
}
|
|
450
|
+
interface MerchantOrdersOptions {
|
|
451
|
+
/** Store ID to filter by */
|
|
452
|
+
storeId: string;
|
|
453
|
+
/** Max results (default: 20) */
|
|
454
|
+
limit?: number;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Fetch recent orders for a store (one-time + subscription).
|
|
458
|
+
*
|
|
459
|
+
* @param query - Server action from `createMerchantQueryAction()`
|
|
460
|
+
* @param options - Store ID and optional limit
|
|
461
|
+
* @returns Recent orders with product info and payment summary
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```tsx
|
|
465
|
+
* const { data, isLoading, refetch } = useMerchantOrders(merchantQuery, { storeId: "STO_xxx" });
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
declare function useMerchantOrders(query: MerchantQueryAction, options: MerchantOrdersOptions): QueryState<{
|
|
469
|
+
onetimeOrders: MerchantOrder[];
|
|
470
|
+
subscriptionOrders: MerchantOrder[];
|
|
471
|
+
}>;
|
|
472
|
+
/**
|
|
473
|
+
* Fetch sales overview for a store.
|
|
474
|
+
*
|
|
475
|
+
* @param query - Server action from `createMerchantQueryAction()`
|
|
476
|
+
* @param storeId - Store ID
|
|
477
|
+
* @returns Aggregated sales statistics
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```tsx
|
|
481
|
+
* const { data: sales } = useMerchantSales(merchantQuery, "STO_xxx");
|
|
482
|
+
* ```
|
|
483
|
+
*/
|
|
484
|
+
declare function useMerchantSales(query: MerchantQueryAction, storeId: string): QueryState<SalesOverview>;
|
|
485
|
+
/**
|
|
486
|
+
* Fetch subscription overview for a store.
|
|
487
|
+
*
|
|
488
|
+
* @param query - Server action from `createMerchantQueryAction()`
|
|
489
|
+
* @param storeId - Store ID
|
|
490
|
+
* @returns Subscription counts and detailed list
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```tsx
|
|
494
|
+
* const { data: subs } = useMerchantSubscriptions(merchantQuery, "STO_xxx");
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
declare function useMerchantSubscriptions(query: MerchantQueryAction, storeId: string): QueryState<SubscriptionOverview>;
|
|
498
|
+
|
|
499
|
+
/** Handler function for a specific webhook event */
|
|
500
|
+
type EventHandler<T = WebhookEventData> = (event: WebhookEvent<T>) => void | Promise<void>;
|
|
501
|
+
/** Configuration for the Webhook route handler factory */
|
|
502
|
+
interface WebhookConfig {
|
|
503
|
+
/** Webhook signature verification options (environment, publicKey, tolerance, etc.) */
|
|
504
|
+
verifyOptions?: VerifyWebhookOptions;
|
|
505
|
+
/** Catch-all handler — called for every event regardless of type */
|
|
506
|
+
onPayload?: EventHandler;
|
|
507
|
+
/** One-time order first payment succeeded */
|
|
508
|
+
onOrderCompleted?: EventHandler;
|
|
509
|
+
/** Subscription first payment succeeded (newly activated) */
|
|
510
|
+
onSubscriptionActivated?: EventHandler;
|
|
511
|
+
/** Subscription renewal payment succeeded */
|
|
512
|
+
onSubscriptionPaymentSucceeded?: EventHandler;
|
|
513
|
+
/** Buyer initiated cancellation (expires at end of current period) */
|
|
514
|
+
onSubscriptionCanceling?: EventHandler;
|
|
515
|
+
/** Buyer withdrew cancellation (subscription restored) */
|
|
516
|
+
onSubscriptionUncanceled?: EventHandler;
|
|
517
|
+
/** Subscription product changed (upgrade/downgrade) */
|
|
518
|
+
onSubscriptionUpdated?: EventHandler;
|
|
519
|
+
/** Subscription fully terminated */
|
|
520
|
+
onSubscriptionCanceled?: EventHandler;
|
|
521
|
+
/** Renewal payment failed (past due) */
|
|
522
|
+
onSubscriptionPastDue?: EventHandler;
|
|
523
|
+
/** Refund succeeded */
|
|
524
|
+
onRefundSucceeded?: EventHandler;
|
|
525
|
+
/** Refund failed */
|
|
526
|
+
onRefundFailed?: EventHandler;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Create a Next.js POST route handler for Waffo Pancake webhooks.
|
|
530
|
+
*
|
|
531
|
+
* Automatically verifies the webhook signature using `@waffo/pancake-ts`,
|
|
532
|
+
* then dispatches to the matching event handler.
|
|
533
|
+
*
|
|
534
|
+
* @param config - Verification options and event handlers
|
|
535
|
+
* @returns A Next.js POST route handler
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* ```ts
|
|
539
|
+
* // app/api/webhooks/waffo/route.ts
|
|
540
|
+
* import { Webhook } from "@waffo/pancake-nextjs";
|
|
541
|
+
*
|
|
542
|
+
* export const POST = Webhook({
|
|
543
|
+
* verifyOptions: { environment: "prod" },
|
|
544
|
+
* onOrderCompleted: async (event) => {
|
|
545
|
+
* console.log("Order completed:", event.data.orderId);
|
|
546
|
+
* // Grant access to the product
|
|
547
|
+
* },
|
|
548
|
+
* onSubscriptionActivated: async (event) => {
|
|
549
|
+
* console.log("Subscription activated:", event.data.orderId);
|
|
550
|
+
* },
|
|
551
|
+
* onRefundSucceeded: async (event) => {
|
|
552
|
+
* console.log("Refund succeeded:", event.data.refundId);
|
|
553
|
+
* // Revoke access
|
|
554
|
+
* },
|
|
555
|
+
* });
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
declare function Webhook(config: WebhookConfig): (request: Request) => Promise<Response>;
|
|
559
|
+
|
|
560
|
+
export { type AnonymousCheckoutButtonProps, type AnonymousCheckoutProps, type AuthenticatedCheckoutButtonProps, type AuthenticatedCheckoutProps, type BuyerActionState, type BuyerConfig, type BuyerOnetimeOrder, type BuyerPayment, type BuyerRefundTicket, type BuyerSessionAction, type BuyerSubscriptionOrder, type BuyerTokenAction, type CheckoutAction, type CheckoutActionParams, type CheckoutActionResult, type CheckoutBaseOptions, CheckoutButton, type CheckoutButtonProps, type CheckoutMode, type CheckoutProps, type LinkCheckoutButtonProps, type LinkCheckoutProps, type MerchantOrder, type MerchantOrdersOptions, type MerchantQueryAction, type MerchantSubscription, type QueryState, type SalesOverview, type SubscriptionOverview, type UseBuyerReturn, type UseCheckoutReturn, WaffoPancakeProvider, type WaffoPancakeProviderProps, Webhook, type WebhookConfig, useBuyer, useBuyerOrders, useBuyerPayments, useBuyerRefundTickets, useCheckout, useMerchantOrders, useMerchantSales, useMerchantSubscriptions };
|