@kwespay/widget 1.0.7 → 1.0.9

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/dist/index.d.ts CHANGED
@@ -1,19 +1,66 @@
1
1
  declare module "@kwespay/widget" {
2
- interface KwesPayOptions {
2
+ export interface KwesPayConfig {
3
3
  apiKey: string;
4
4
  vendorId: string;
5
5
  amount: number;
6
6
  currency?: string;
7
7
  acceptedTokens?: string[] | "stablecoins";
8
+ onPaymentSuccess?: (payload: PaymentResult) => void;
9
+ onPaymentConfirmed?: (payload: PaymentResult) => void;
10
+ onPaymentUnconfirmed?: (payload: UnconfirmedPayload) => void;
11
+ onPaymentError?: (payload: { error: string; errorType: string }) => void;
8
12
  }
9
13
 
10
- export default class KwesPayWidget {
11
- constructor(options: KwesPayOptions);
14
+ export interface PaymentResult {
15
+ transactionHash: string;
16
+ transactionReference: string;
17
+ paymentIdBytes32: string;
18
+ /** "completed" when backend confirmed; "unconfirmed" on polling timeout */
19
+ transactionStatus: "completed" | "unconfirmed";
20
+ fiatAmount: number;
21
+ currency: string;
22
+ token: string;
23
+ network: string;
24
+ }
25
+
26
+ export interface UnconfirmedPayload {
27
+ transactionReference: string;
28
+ transactionHash: string;
29
+ reason: string;
30
+ }
31
+
32
+ export class KwesPayWidget {
33
+ constructor(config: KwesPayConfig);
34
+
35
+ /**
36
+ * Open the widget and await the payment result.
37
+ *
38
+ * Resolves with PaymentResult on success.
39
+ * Rejects with an Error (err.code set) on cancellation or failure.
40
+ */
41
+ open(): Promise<PaymentResult>;
12
42
 
13
- open(): Promise<void>;
14
43
  close(): void;
15
44
  destroy(): void;
16
- updateAmount(amount: number, currency?: string): void;
17
45
  isOpen(): boolean;
46
+ updateAmount(amount: number, currency?: string): void;
47
+ getState(): object;
18
48
  }
49
+
50
+ /**
51
+ * Open the KwesPay checkout widget and await the result.
52
+ * Handles instance lifecycle (creation, caching, cleanup) automatically.
53
+ *
54
+ * @example
55
+ * try {
56
+ * const result = await kwespay({ apiKey, vendorId, amount, currency: "USD" });
57
+ * console.log("Paid:", result.transactionHash);
58
+ * } catch (err) {
59
+ * if (err.code !== "USER_CANCELLED") console.error(err);
60
+ * }
61
+ */
62
+ export function kwespay(config: KwesPayConfig): Promise<PaymentResult>;
63
+
64
+ /** Default export is the KwesPayWidget class (backward compatibility) */
65
+ export default KwesPayWidget;
19
66
  }