@moneymq/react 0.2.1 → 0.3.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/dist/index.d.mts +222 -9
- package/dist/index.d.ts +222 -9
- package/dist/index.js +202 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -3
package/dist/index.d.mts
CHANGED
|
@@ -32,73 +32,286 @@ interface SandboxContextState {
|
|
|
32
32
|
isSandboxMode: boolean;
|
|
33
33
|
sandboxAccounts: SandboxAccount[];
|
|
34
34
|
}
|
|
35
|
+
declare const MoneyMQContext: React.Context<MoneyMQClient | null>;
|
|
36
|
+
declare const SandboxContext: React.Context<SandboxContextState>;
|
|
35
37
|
declare function useMoneyMQ(): MoneyMQClient;
|
|
36
38
|
declare function useSandbox(): SandboxContextState;
|
|
37
39
|
declare function MoneyMQProvider({ children, client, branding, }: MoneyMQProviderProps): react_jsx_runtime.JSX.Element | null;
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Represents a completed payment transaction.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* const handleSuccess = (payment: Payment) => {
|
|
47
|
+
* console.log(`Payment ${payment.id} completed for ${payment.amount} ${payment.currency}`);
|
|
48
|
+
* console.log(`Transaction signature: ${payment.signature}`);
|
|
49
|
+
* };
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
39
52
|
interface Payment$1 {
|
|
53
|
+
/** Unique payment identifier (e.g., "pay_1234567890") */
|
|
40
54
|
id: string;
|
|
55
|
+
/** Payment amount in the currency's standard unit (e.g., 9.99 for $9.99) */
|
|
41
56
|
amount: number;
|
|
57
|
+
/** Currency code (e.g., "USDC") */
|
|
42
58
|
currency: string;
|
|
59
|
+
/** Current status of the payment */
|
|
43
60
|
status: 'pending' | 'completed' | 'failed';
|
|
61
|
+
/** Blockchain transaction signature (available after completion) */
|
|
44
62
|
signature?: string;
|
|
45
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Represents a price for a product.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const price: Price = {
|
|
70
|
+
* id: 'price_abc123',
|
|
71
|
+
* unit_amount: 999, // $9.99 in cents
|
|
72
|
+
* currency: 'USDC',
|
|
73
|
+
* product: 'prod_xyz789',
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
46
77
|
interface Price {
|
|
78
|
+
/** Unique price identifier from your catalog */
|
|
47
79
|
id: string;
|
|
80
|
+
/** Price amount in cents (e.g., 999 for $9.99) */
|
|
48
81
|
unit_amount: number;
|
|
82
|
+
/** Currency code (e.g., "USDC") */
|
|
49
83
|
currency: string;
|
|
84
|
+
/** Associated product ID */
|
|
50
85
|
product?: string;
|
|
51
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Represents a product in your catalog.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```tsx
|
|
92
|
+
* const product: Product = {
|
|
93
|
+
* id: 'prod_xyz789',
|
|
94
|
+
* name: 'Pro Subscription',
|
|
95
|
+
* description: 'Monthly access to premium features',
|
|
96
|
+
* };
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
52
99
|
interface Product {
|
|
100
|
+
/** Unique product identifier from your catalog */
|
|
53
101
|
id: string;
|
|
102
|
+
/** Display name shown to the customer */
|
|
54
103
|
name: string;
|
|
104
|
+
/** Optional description for additional context */
|
|
55
105
|
description?: string;
|
|
56
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Represents an item in the checkout basket.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* const item: BasketItem = {
|
|
113
|
+
* product: { id: 'prod_123', name: 'Pro Plan' },
|
|
114
|
+
* price: { id: 'price_456', unit_amount: 999, currency: 'USDC' },
|
|
115
|
+
* quantity: 1,
|
|
116
|
+
* };
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
57
119
|
interface BasketItem {
|
|
58
|
-
/** Product details */
|
|
120
|
+
/** Product details including id and name */
|
|
59
121
|
product: Product;
|
|
60
|
-
/** Price details */
|
|
122
|
+
/** Price details including amount and currency */
|
|
61
123
|
price: Price;
|
|
62
|
-
/**
|
|
124
|
+
/** Number of items (defaults to 1) */
|
|
63
125
|
quantity?: number;
|
|
64
126
|
}
|
|
65
|
-
|
|
66
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Props for the CheckoutButton component.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* <CheckoutButton
|
|
133
|
+
* basket={[{ product, price }]}
|
|
134
|
+
* onSuccess={(payment) => console.log('Paid!', payment.id)}
|
|
135
|
+
* onError={(error) => console.error('Failed:', error)}
|
|
136
|
+
* variant="solid"
|
|
137
|
+
* >
|
|
138
|
+
* Pay Now
|
|
139
|
+
* </CheckoutButton>
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
interface CheckoutButtonProps {
|
|
143
|
+
/** Array of items to purchase. Each item includes product, price, and optional quantity. */
|
|
67
144
|
basket: BasketItem[];
|
|
145
|
+
/** Callback fired when payment completes successfully. Receives the Payment object with transaction details. */
|
|
68
146
|
onSuccess?: (payment: Payment$1) => void;
|
|
147
|
+
/** Callback fired when payment fails. Receives the Error with failure details. */
|
|
69
148
|
onError?: (error: Error) => void;
|
|
149
|
+
/** Button style variant. "solid" has a filled background, "outline" has a border only. @default "solid" */
|
|
70
150
|
variant?: 'solid' | 'outline';
|
|
151
|
+
/** Custom button content. If not provided, displays "Pay". */
|
|
71
152
|
children?: React.ReactNode;
|
|
153
|
+
/** Disable the button, preventing clicks. */
|
|
72
154
|
disabled?: boolean;
|
|
155
|
+
/** Enable debug mode to show a debug panel with account balance in the checkout modal. @default false */
|
|
156
|
+
debug?: boolean;
|
|
73
157
|
}
|
|
74
|
-
|
|
158
|
+
/**
|
|
159
|
+
* A button component that opens a checkout modal for processing payments.
|
|
160
|
+
*
|
|
161
|
+
* Must be used within a `MoneyMQProvider`. When clicked, displays a modal where
|
|
162
|
+
* users can select their wallet and complete the payment.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* import { MoneyMQProvider, CheckoutButton } from '@moneymq/react';
|
|
167
|
+
*
|
|
168
|
+
* function App() {
|
|
169
|
+
* const product = { id: 'prod_123', name: 'Pro Plan' };
|
|
170
|
+
* const price = { id: 'price_456', unit_amount: 999, currency: 'USDC' };
|
|
171
|
+
*
|
|
172
|
+
* return (
|
|
173
|
+
* <MoneyMQProvider client={client}>
|
|
174
|
+
* <CheckoutButton
|
|
175
|
+
* basket={[{ product, price }]}
|
|
176
|
+
* onSuccess={(payment) => {
|
|
177
|
+
* console.log('Payment completed:', payment.signature);
|
|
178
|
+
* }}
|
|
179
|
+
* >
|
|
180
|
+
* Subscribe - $9.99
|
|
181
|
+
* </CheckoutButton>
|
|
182
|
+
* </MoneyMQProvider>
|
|
183
|
+
* );
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @see {@link CheckoutButtonProps} for available props
|
|
188
|
+
* @see {@link CheckoutModal} for the modal component used internally
|
|
189
|
+
*/
|
|
190
|
+
declare const CheckoutButton: React.ForwardRefExoticComponent<CheckoutButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
75
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Represents a line item in the checkout, including product, price, quantity, and calculated subtotal.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* const lineItem: LineItem = {
|
|
198
|
+
* product: { id: 'prod_123', name: 'Pro Plan' },
|
|
199
|
+
* price: { id: 'price_456', unit_amount: 999, currency: 'USDC' },
|
|
200
|
+
* quantity: 2,
|
|
201
|
+
* subtotal: 19.98,
|
|
202
|
+
* };
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
76
205
|
interface LineItem {
|
|
206
|
+
/** Product information */
|
|
77
207
|
product: {
|
|
208
|
+
/** Unique product identifier */
|
|
78
209
|
id: string;
|
|
210
|
+
/** Display name shown to the customer */
|
|
79
211
|
name: string;
|
|
212
|
+
/** Optional description */
|
|
80
213
|
description?: string;
|
|
81
214
|
};
|
|
215
|
+
/** Price information */
|
|
82
216
|
price: {
|
|
217
|
+
/** Unique price identifier */
|
|
83
218
|
id: string;
|
|
219
|
+
/** Price amount in cents (e.g., 999 for $9.99) */
|
|
84
220
|
unit_amount: number;
|
|
221
|
+
/** Currency code (e.g., "USDC") */
|
|
85
222
|
currency: string;
|
|
86
223
|
};
|
|
224
|
+
/** Quantity of this item */
|
|
87
225
|
quantity: number;
|
|
226
|
+
/** Calculated subtotal (unit_amount / 100 * quantity) */
|
|
88
227
|
subtotal: number;
|
|
89
228
|
}
|
|
90
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Props for the CheckoutModal component.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```tsx
|
|
234
|
+
* <CheckoutModal
|
|
235
|
+
* visible={isOpen}
|
|
236
|
+
* onClose={() => setIsOpen(false)}
|
|
237
|
+
* amount={9.99}
|
|
238
|
+
* currency="USDC"
|
|
239
|
+
* recipient="7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
|
|
240
|
+
* onSuccess={(signature) => console.log('Paid:', signature)}
|
|
241
|
+
* />
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
interface CheckoutModalProps {
|
|
245
|
+
/** Whether the modal is visible */
|
|
91
246
|
visible: boolean;
|
|
247
|
+
/** Callback to close the modal */
|
|
92
248
|
onClose: () => void;
|
|
249
|
+
/** Total payment amount (e.g., 9.99 for $9.99) */
|
|
93
250
|
amount: number;
|
|
251
|
+
/** Currency code (e.g., "USDC") */
|
|
94
252
|
currency: string;
|
|
253
|
+
/** Recipient wallet address */
|
|
95
254
|
recipient: string;
|
|
255
|
+
/** Optional line items to display in the checkout summary */
|
|
96
256
|
lineItems?: LineItem[];
|
|
257
|
+
/** Callback fired when payment completes. Receives the transaction signature. */
|
|
97
258
|
onSuccess?: (signature: string) => void;
|
|
259
|
+
/** Callback fired when payment fails. Receives the Error with failure details. */
|
|
98
260
|
onError?: (error: Error) => void;
|
|
261
|
+
/** Accent color for UI elements. @default "#ec4899" */
|
|
99
262
|
accentColor?: string;
|
|
263
|
+
/** Enable debug mode to show account balance panel. @default false */
|
|
264
|
+
debug?: boolean;
|
|
100
265
|
}
|
|
101
|
-
|
|
266
|
+
/**
|
|
267
|
+
* A modal component for completing payments.
|
|
268
|
+
*
|
|
269
|
+
* Displays a payment interface where users can:
|
|
270
|
+
* - View the total amount and line items
|
|
271
|
+
* - Select a payment method (browser wallet or sandbox account)
|
|
272
|
+
* - Complete the payment transaction
|
|
273
|
+
*
|
|
274
|
+
* Must be used within a `MoneyMQProvider`. Usually used internally by `CheckoutButton`,
|
|
275
|
+
* but can be rendered directly for custom checkout flows.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```tsx
|
|
279
|
+
* import { MoneyMQProvider, CheckoutModal } from '@moneymq/react';
|
|
280
|
+
*
|
|
281
|
+
* function CustomCheckout() {
|
|
282
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
283
|
+
*
|
|
284
|
+
* return (
|
|
285
|
+
* <MoneyMQProvider client={client}>
|
|
286
|
+
* <button onClick={() => setIsOpen(true)}>Pay</button>
|
|
287
|
+
* <CheckoutModal
|
|
288
|
+
* visible={isOpen}
|
|
289
|
+
* onClose={() => setIsOpen(false)}
|
|
290
|
+
* amount={9.99}
|
|
291
|
+
* currency="USDC"
|
|
292
|
+
* recipient="7xKXtg..."
|
|
293
|
+
* lineItems={[
|
|
294
|
+
* {
|
|
295
|
+
* product: { id: 'prod_1', name: 'Pro Plan' },
|
|
296
|
+
* price: { id: 'price_1', unit_amount: 999, currency: 'USDC' },
|
|
297
|
+
* quantity: 1,
|
|
298
|
+
* subtotal: 9.99,
|
|
299
|
+
* },
|
|
300
|
+
* ]}
|
|
301
|
+
* onSuccess={(signature) => {
|
|
302
|
+
* console.log('Payment successful:', signature);
|
|
303
|
+
* setIsOpen(false);
|
|
304
|
+
* }}
|
|
305
|
+
* />
|
|
306
|
+
* </MoneyMQProvider>
|
|
307
|
+
* );
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @see {@link CheckoutModalProps} for available props
|
|
312
|
+
* @see {@link CheckoutButton} for a simpler button-based checkout
|
|
313
|
+
*/
|
|
314
|
+
declare function CheckoutModal({ visible, onClose, amount, currency, recipient, lineItems, onSuccess, onError, accentColor, debug, }: CheckoutModalProps): react_jsx_runtime.JSX.Element | null;
|
|
102
315
|
|
|
103
316
|
interface Payment {
|
|
104
317
|
id: string;
|
|
@@ -114,4 +327,4 @@ interface UsePaymentReturn {
|
|
|
114
327
|
}
|
|
115
328
|
declare function usePayment(): UsePaymentReturn;
|
|
116
329
|
|
|
117
|
-
export { type BasketItem, type Branding, type
|
|
330
|
+
export { type BasketItem, type Branding, CheckoutButton, type CheckoutButtonProps, CheckoutModal, type CheckoutModalProps, type LineItem, type MoneyMQClient, MoneyMQContext, MoneyMQProvider, type MoneyMQProviderProps, type Payment$1 as Payment, type Price, type Product, type SandboxAccount, SandboxContext, type UsePaymentReturn, useMoneyMQ, usePayment, useSandbox };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,73 +32,286 @@ interface SandboxContextState {
|
|
|
32
32
|
isSandboxMode: boolean;
|
|
33
33
|
sandboxAccounts: SandboxAccount[];
|
|
34
34
|
}
|
|
35
|
+
declare const MoneyMQContext: React.Context<MoneyMQClient | null>;
|
|
36
|
+
declare const SandboxContext: React.Context<SandboxContextState>;
|
|
35
37
|
declare function useMoneyMQ(): MoneyMQClient;
|
|
36
38
|
declare function useSandbox(): SandboxContextState;
|
|
37
39
|
declare function MoneyMQProvider({ children, client, branding, }: MoneyMQProviderProps): react_jsx_runtime.JSX.Element | null;
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Represents a completed payment transaction.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* const handleSuccess = (payment: Payment) => {
|
|
47
|
+
* console.log(`Payment ${payment.id} completed for ${payment.amount} ${payment.currency}`);
|
|
48
|
+
* console.log(`Transaction signature: ${payment.signature}`);
|
|
49
|
+
* };
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
39
52
|
interface Payment$1 {
|
|
53
|
+
/** Unique payment identifier (e.g., "pay_1234567890") */
|
|
40
54
|
id: string;
|
|
55
|
+
/** Payment amount in the currency's standard unit (e.g., 9.99 for $9.99) */
|
|
41
56
|
amount: number;
|
|
57
|
+
/** Currency code (e.g., "USDC") */
|
|
42
58
|
currency: string;
|
|
59
|
+
/** Current status of the payment */
|
|
43
60
|
status: 'pending' | 'completed' | 'failed';
|
|
61
|
+
/** Blockchain transaction signature (available after completion) */
|
|
44
62
|
signature?: string;
|
|
45
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Represents a price for a product.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const price: Price = {
|
|
70
|
+
* id: 'price_abc123',
|
|
71
|
+
* unit_amount: 999, // $9.99 in cents
|
|
72
|
+
* currency: 'USDC',
|
|
73
|
+
* product: 'prod_xyz789',
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
46
77
|
interface Price {
|
|
78
|
+
/** Unique price identifier from your catalog */
|
|
47
79
|
id: string;
|
|
80
|
+
/** Price amount in cents (e.g., 999 for $9.99) */
|
|
48
81
|
unit_amount: number;
|
|
82
|
+
/** Currency code (e.g., "USDC") */
|
|
49
83
|
currency: string;
|
|
84
|
+
/** Associated product ID */
|
|
50
85
|
product?: string;
|
|
51
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Represents a product in your catalog.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```tsx
|
|
92
|
+
* const product: Product = {
|
|
93
|
+
* id: 'prod_xyz789',
|
|
94
|
+
* name: 'Pro Subscription',
|
|
95
|
+
* description: 'Monthly access to premium features',
|
|
96
|
+
* };
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
52
99
|
interface Product {
|
|
100
|
+
/** Unique product identifier from your catalog */
|
|
53
101
|
id: string;
|
|
102
|
+
/** Display name shown to the customer */
|
|
54
103
|
name: string;
|
|
104
|
+
/** Optional description for additional context */
|
|
55
105
|
description?: string;
|
|
56
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Represents an item in the checkout basket.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* const item: BasketItem = {
|
|
113
|
+
* product: { id: 'prod_123', name: 'Pro Plan' },
|
|
114
|
+
* price: { id: 'price_456', unit_amount: 999, currency: 'USDC' },
|
|
115
|
+
* quantity: 1,
|
|
116
|
+
* };
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
57
119
|
interface BasketItem {
|
|
58
|
-
/** Product details */
|
|
120
|
+
/** Product details including id and name */
|
|
59
121
|
product: Product;
|
|
60
|
-
/** Price details */
|
|
122
|
+
/** Price details including amount and currency */
|
|
61
123
|
price: Price;
|
|
62
|
-
/**
|
|
124
|
+
/** Number of items (defaults to 1) */
|
|
63
125
|
quantity?: number;
|
|
64
126
|
}
|
|
65
|
-
|
|
66
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Props for the CheckoutButton component.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* <CheckoutButton
|
|
133
|
+
* basket={[{ product, price }]}
|
|
134
|
+
* onSuccess={(payment) => console.log('Paid!', payment.id)}
|
|
135
|
+
* onError={(error) => console.error('Failed:', error)}
|
|
136
|
+
* variant="solid"
|
|
137
|
+
* >
|
|
138
|
+
* Pay Now
|
|
139
|
+
* </CheckoutButton>
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
interface CheckoutButtonProps {
|
|
143
|
+
/** Array of items to purchase. Each item includes product, price, and optional quantity. */
|
|
67
144
|
basket: BasketItem[];
|
|
145
|
+
/** Callback fired when payment completes successfully. Receives the Payment object with transaction details. */
|
|
68
146
|
onSuccess?: (payment: Payment$1) => void;
|
|
147
|
+
/** Callback fired when payment fails. Receives the Error with failure details. */
|
|
69
148
|
onError?: (error: Error) => void;
|
|
149
|
+
/** Button style variant. "solid" has a filled background, "outline" has a border only. @default "solid" */
|
|
70
150
|
variant?: 'solid' | 'outline';
|
|
151
|
+
/** Custom button content. If not provided, displays "Pay". */
|
|
71
152
|
children?: React.ReactNode;
|
|
153
|
+
/** Disable the button, preventing clicks. */
|
|
72
154
|
disabled?: boolean;
|
|
155
|
+
/** Enable debug mode to show a debug panel with account balance in the checkout modal. @default false */
|
|
156
|
+
debug?: boolean;
|
|
73
157
|
}
|
|
74
|
-
|
|
158
|
+
/**
|
|
159
|
+
* A button component that opens a checkout modal for processing payments.
|
|
160
|
+
*
|
|
161
|
+
* Must be used within a `MoneyMQProvider`. When clicked, displays a modal where
|
|
162
|
+
* users can select their wallet and complete the payment.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* import { MoneyMQProvider, CheckoutButton } from '@moneymq/react';
|
|
167
|
+
*
|
|
168
|
+
* function App() {
|
|
169
|
+
* const product = { id: 'prod_123', name: 'Pro Plan' };
|
|
170
|
+
* const price = { id: 'price_456', unit_amount: 999, currency: 'USDC' };
|
|
171
|
+
*
|
|
172
|
+
* return (
|
|
173
|
+
* <MoneyMQProvider client={client}>
|
|
174
|
+
* <CheckoutButton
|
|
175
|
+
* basket={[{ product, price }]}
|
|
176
|
+
* onSuccess={(payment) => {
|
|
177
|
+
* console.log('Payment completed:', payment.signature);
|
|
178
|
+
* }}
|
|
179
|
+
* >
|
|
180
|
+
* Subscribe - $9.99
|
|
181
|
+
* </CheckoutButton>
|
|
182
|
+
* </MoneyMQProvider>
|
|
183
|
+
* );
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @see {@link CheckoutButtonProps} for available props
|
|
188
|
+
* @see {@link CheckoutModal} for the modal component used internally
|
|
189
|
+
*/
|
|
190
|
+
declare const CheckoutButton: React.ForwardRefExoticComponent<CheckoutButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
75
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Represents a line item in the checkout, including product, price, quantity, and calculated subtotal.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* const lineItem: LineItem = {
|
|
198
|
+
* product: { id: 'prod_123', name: 'Pro Plan' },
|
|
199
|
+
* price: { id: 'price_456', unit_amount: 999, currency: 'USDC' },
|
|
200
|
+
* quantity: 2,
|
|
201
|
+
* subtotal: 19.98,
|
|
202
|
+
* };
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
76
205
|
interface LineItem {
|
|
206
|
+
/** Product information */
|
|
77
207
|
product: {
|
|
208
|
+
/** Unique product identifier */
|
|
78
209
|
id: string;
|
|
210
|
+
/** Display name shown to the customer */
|
|
79
211
|
name: string;
|
|
212
|
+
/** Optional description */
|
|
80
213
|
description?: string;
|
|
81
214
|
};
|
|
215
|
+
/** Price information */
|
|
82
216
|
price: {
|
|
217
|
+
/** Unique price identifier */
|
|
83
218
|
id: string;
|
|
219
|
+
/** Price amount in cents (e.g., 999 for $9.99) */
|
|
84
220
|
unit_amount: number;
|
|
221
|
+
/** Currency code (e.g., "USDC") */
|
|
85
222
|
currency: string;
|
|
86
223
|
};
|
|
224
|
+
/** Quantity of this item */
|
|
87
225
|
quantity: number;
|
|
226
|
+
/** Calculated subtotal (unit_amount / 100 * quantity) */
|
|
88
227
|
subtotal: number;
|
|
89
228
|
}
|
|
90
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Props for the CheckoutModal component.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```tsx
|
|
234
|
+
* <CheckoutModal
|
|
235
|
+
* visible={isOpen}
|
|
236
|
+
* onClose={() => setIsOpen(false)}
|
|
237
|
+
* amount={9.99}
|
|
238
|
+
* currency="USDC"
|
|
239
|
+
* recipient="7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
|
|
240
|
+
* onSuccess={(signature) => console.log('Paid:', signature)}
|
|
241
|
+
* />
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
interface CheckoutModalProps {
|
|
245
|
+
/** Whether the modal is visible */
|
|
91
246
|
visible: boolean;
|
|
247
|
+
/** Callback to close the modal */
|
|
92
248
|
onClose: () => void;
|
|
249
|
+
/** Total payment amount (e.g., 9.99 for $9.99) */
|
|
93
250
|
amount: number;
|
|
251
|
+
/** Currency code (e.g., "USDC") */
|
|
94
252
|
currency: string;
|
|
253
|
+
/** Recipient wallet address */
|
|
95
254
|
recipient: string;
|
|
255
|
+
/** Optional line items to display in the checkout summary */
|
|
96
256
|
lineItems?: LineItem[];
|
|
257
|
+
/** Callback fired when payment completes. Receives the transaction signature. */
|
|
97
258
|
onSuccess?: (signature: string) => void;
|
|
259
|
+
/** Callback fired when payment fails. Receives the Error with failure details. */
|
|
98
260
|
onError?: (error: Error) => void;
|
|
261
|
+
/** Accent color for UI elements. @default "#ec4899" */
|
|
99
262
|
accentColor?: string;
|
|
263
|
+
/** Enable debug mode to show account balance panel. @default false */
|
|
264
|
+
debug?: boolean;
|
|
100
265
|
}
|
|
101
|
-
|
|
266
|
+
/**
|
|
267
|
+
* A modal component for completing payments.
|
|
268
|
+
*
|
|
269
|
+
* Displays a payment interface where users can:
|
|
270
|
+
* - View the total amount and line items
|
|
271
|
+
* - Select a payment method (browser wallet or sandbox account)
|
|
272
|
+
* - Complete the payment transaction
|
|
273
|
+
*
|
|
274
|
+
* Must be used within a `MoneyMQProvider`. Usually used internally by `CheckoutButton`,
|
|
275
|
+
* but can be rendered directly for custom checkout flows.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```tsx
|
|
279
|
+
* import { MoneyMQProvider, CheckoutModal } from '@moneymq/react';
|
|
280
|
+
*
|
|
281
|
+
* function CustomCheckout() {
|
|
282
|
+
* const [isOpen, setIsOpen] = useState(false);
|
|
283
|
+
*
|
|
284
|
+
* return (
|
|
285
|
+
* <MoneyMQProvider client={client}>
|
|
286
|
+
* <button onClick={() => setIsOpen(true)}>Pay</button>
|
|
287
|
+
* <CheckoutModal
|
|
288
|
+
* visible={isOpen}
|
|
289
|
+
* onClose={() => setIsOpen(false)}
|
|
290
|
+
* amount={9.99}
|
|
291
|
+
* currency="USDC"
|
|
292
|
+
* recipient="7xKXtg..."
|
|
293
|
+
* lineItems={[
|
|
294
|
+
* {
|
|
295
|
+
* product: { id: 'prod_1', name: 'Pro Plan' },
|
|
296
|
+
* price: { id: 'price_1', unit_amount: 999, currency: 'USDC' },
|
|
297
|
+
* quantity: 1,
|
|
298
|
+
* subtotal: 9.99,
|
|
299
|
+
* },
|
|
300
|
+
* ]}
|
|
301
|
+
* onSuccess={(signature) => {
|
|
302
|
+
* console.log('Payment successful:', signature);
|
|
303
|
+
* setIsOpen(false);
|
|
304
|
+
* }}
|
|
305
|
+
* />
|
|
306
|
+
* </MoneyMQProvider>
|
|
307
|
+
* );
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* @see {@link CheckoutModalProps} for available props
|
|
312
|
+
* @see {@link CheckoutButton} for a simpler button-based checkout
|
|
313
|
+
*/
|
|
314
|
+
declare function CheckoutModal({ visible, onClose, amount, currency, recipient, lineItems, onSuccess, onError, accentColor, debug, }: CheckoutModalProps): react_jsx_runtime.JSX.Element | null;
|
|
102
315
|
|
|
103
316
|
interface Payment {
|
|
104
317
|
id: string;
|
|
@@ -114,4 +327,4 @@ interface UsePaymentReturn {
|
|
|
114
327
|
}
|
|
115
328
|
declare function usePayment(): UsePaymentReturn;
|
|
116
329
|
|
|
117
|
-
export { type BasketItem, type Branding, type
|
|
330
|
+
export { type BasketItem, type Branding, CheckoutButton, type CheckoutButtonProps, CheckoutModal, type CheckoutModalProps, type LineItem, type MoneyMQClient, MoneyMQContext, MoneyMQProvider, type MoneyMQProviderProps, type Payment$1 as Payment, type Price, type Product, type SandboxAccount, SandboxContext, type UsePaymentReturn, useMoneyMQ, usePayment, useSandbox };
|