@moneydevkit/nextjs 0.7.0-beta.0 → 0.7.0-beta.10

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.md CHANGED
@@ -21,29 +21,43 @@ moneydevkit checkout library for embedding Lightning-powered payments inside Nex
21
21
  'use client'
22
22
 
23
23
  import { useCheckout } from '@moneydevkit/nextjs'
24
+ import { useState } from 'react'
24
25
 
25
26
  export default function HomePage() {
26
- const { navigate, isNavigating } = useCheckout()
27
+ const { createCheckout, isLoading } = useCheckout()
28
+ const [error, setError] = useState(null)
27
29
 
28
- const handlePurchase = () => {
29
- navigate({
30
- title: "Describe the purchase shown to the buyer",
30
+ const handlePurchase = async () => {
31
+ setError(null)
32
+
33
+ const result = await createCheckout({
34
+ type: 'AMOUNT', // or 'PRODUCTS' for product-based checkouts
35
+ title: 'Describe the purchase shown to the buyer',
31
36
  description: 'A description of the purchase',
32
37
  amount: 500, // 500 USD cents or Bitcoin sats
33
38
  currency: 'USD', // or 'SAT'
34
39
  successUrl: '/checkout/success',
35
40
  metadata: {
36
- type: 'my_type',
37
41
  customField: 'internal reference for this checkout',
38
42
  name: 'John Doe'
39
43
  }
40
44
  })
45
+
46
+ if (result.error) {
47
+ setError(result.error.message)
48
+ return
49
+ }
50
+
51
+ window.location.href = result.data.checkoutUrl
41
52
  }
42
53
 
43
54
  return (
44
- <button onClick={handlePurchase} disabled={isNavigating}>
45
- {isNavigating ? 'Creating checkout…' : 'Buy Now'}
46
- </button>
55
+ <div>
56
+ {error && <p style={{ color: 'red' }}>{error}</p>}
57
+ <button onClick={handlePurchase} disabled={isLoading}>
58
+ {isLoading ? 'Creating checkout…' : 'Buy Now'}
59
+ </button>
60
+ </div>
47
61
  )
48
62
  }
49
63
  ```
@@ -65,7 +79,7 @@ export default function CheckoutPage({ params }) {
65
79
  ### 3. Expose the unified Money Dev Kit endpoint
66
80
  ```js
67
81
  // app/api/mdk/route.js
68
- export { POST } from '@moneydevkit/nextjs/server/route'
82
+ export { POST } from "@moneydevkit/nextjs/server/route";
69
83
  ```
70
84
 
71
85
  ### 4. Configure Next.js
@@ -82,7 +96,8 @@ You now have a complete Lightning checkout loop: the button creates a session, t
82
96
  Collect and store customer information with each checkout. Pass `customer` to pre-fill data and `requireCustomerData` to prompt the user for specific fields:
83
97
 
84
98
  ```jsx
85
- navigate({
99
+ const result = await createCheckout({
100
+ type: 'AMOUNT',
86
101
  title: "Premium Plan",
87
102
  description: 'Monthly subscription',
88
103
  amount: 1000,
@@ -115,7 +130,8 @@ Customers are matched by `email` or `externalId`. When a match is found:
115
130
  When your user is already authenticated in your app, pass `externalId` to link checkouts to their account:
116
131
 
117
132
  ```jsx
118
- navigate({
133
+ const result = await createCheckout({
134
+ type: 'AMOUNT',
119
135
  title: "Premium Plan",
120
136
  description: 'Monthly subscription',
121
137
  amount: 1000,
@@ -136,6 +152,57 @@ When `externalId` is provided:
136
152
  - Only fields missing from the customer record are requested
137
153
  - This prevents authenticated users from being asked for data you already have
138
154
 
155
+ ## Product Checkouts
156
+ Sell products defined in your Money Dev Kit dashboard using `type: 'PRODUCTS'`:
157
+
158
+ ```jsx
159
+ import { useCheckout, useProducts } from '@moneydevkit/nextjs'
160
+
161
+ function ProductPage() {
162
+ const { createCheckout, isLoading } = useCheckout()
163
+ const { products } = useProducts()
164
+
165
+ const handleBuyProduct = async (productId) => {
166
+ const result = await createCheckout({
167
+ type: 'PRODUCTS',
168
+ product: productId,
169
+ successUrl: '/checkout/success',
170
+ })
171
+
172
+ if (result.error) return
173
+ window.location.href = result.data.checkoutUrl
174
+ }
175
+
176
+ return (
177
+ <div>
178
+ {products?.map(product => (
179
+ <button key={product.id} onClick={() => handleBuyProduct(product.id)}>
180
+ Buy {product.name} - ${(product.price?.priceAmount ?? 0) / 100}
181
+ </button>
182
+ ))}
183
+ </div>
184
+ )
185
+ }
186
+ ```
187
+
188
+ ### Checkout Types
189
+ - **`type: 'AMOUNT'`** - For donations, tips, or custom amounts. Requires `amount` field.
190
+ - **`type: 'PRODUCTS'`** - For selling products. Requires `product` field with a product ID. Amount is calculated from product price.
191
+
192
+ ### Pay What You Want (CUSTOM prices)
193
+ Products can have CUSTOM prices that let customers choose their own amount. When a checkout includes a product with a CUSTOM price, the checkout UI automatically shows an amount input field:
194
+
195
+ ```jsx
196
+ // Create a checkout for a product with CUSTOM pricing
197
+ const result = await createCheckout({
198
+ type: 'PRODUCTS',
199
+ product: customPriceProductId, // Product configured with CUSTOM price in dashboard
200
+ successUrl: '/checkout/success',
201
+ })
202
+ ```
203
+
204
+ The customer enters their desired amount during checkout. For USD, amounts are in dollars (converted to cents internally). For SAT, amounts are in satoshis.
205
+
139
206
  ## Verify successful payments
140
207
  When a checkout completes, use `useCheckoutSuccess()` on the success page
141
208
  ```tsx
@@ -0,0 +1 @@
1
+ export { useProducts } from '@moneydevkit/core/client';
@@ -0,0 +1,3 @@
1
+ 'use client';
2
+ export { useProducts } from '@moneydevkit/core/client';
3
+ //# sourceMappingURL=useProducts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useProducts.js","sourceRoot":"","sources":["../../src/hooks/useProducts.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export { Checkout } from './components/Checkout';
2
2
  export type { CheckoutProps } from './components/Checkout';
3
3
  export { useCheckout } from './hooks/useCheckout';
4
4
  export { useCheckoutSuccess } from './hooks/useCheckoutSuccess';
5
+ export { useProducts } from './hooks/useProducts';
6
+ export type { MdkError, Result } from '@moneydevkit/core/client';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Checkout } from './components/Checkout';
2
2
  export { useCheckout } from './hooks/useCheckout';
3
3
  export { useCheckoutSuccess } from './hooks/useCheckoutSuccess';
4
+ export { useProducts } from './hooks/useProducts';
4
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { createCheckoutUrl } from '@moneydevkit/core/route';
2
+ export type { CreateCheckoutUrlOptions } from '@moneydevkit/core/route';
@@ -0,0 +1,2 @@
1
+ export { createCheckoutUrl } from '@moneydevkit/core/route';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA"}
@@ -1 +1 @@
1
- export { POST } from '@moneydevkit/core/route';
1
+ export { POST, GET } from '@moneydevkit/core/route';
@@ -1,2 +1,2 @@
1
- export { POST } from '@moneydevkit/core/route';
1
+ export { POST, GET } from '@moneydevkit/core/route';
2
2
  //# sourceMappingURL=route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/server/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/server/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneydevkit/nextjs",
3
- "version": "0.7.0-beta.0",
3
+ "version": "0.7.0-beta.10",
4
4
  "title": "@moneydevkit/nextjs",
5
5
  "description": "moneydevkit checkout components for Next.js.",
6
6
  "repository": {
@@ -20,6 +20,11 @@
20
20
  },
21
21
  "./mdk-styles.css": "./dist/mdk-styles.css",
22
22
  "./package.json": "./package.json",
23
+ "./server": {
24
+ "types": "./dist/server/index.d.ts",
25
+ "import": "./dist/server/index.js",
26
+ "default": "./dist/server/index.js"
27
+ },
23
28
  "./server/route": {
24
29
  "types": "./dist/server/route.d.ts",
25
30
  "import": "./dist/server/route.js",
@@ -50,9 +55,9 @@
50
55
  },
51
56
  "dependencies": {
52
57
  "@hookform/resolvers": "^5.0.1",
53
- "@moneydevkit/api-contract": "^0.1.13",
54
- "@moneydevkit/core": "0.7.0-beta.0",
55
- "@moneydevkit/lightning-js": "^0.1.59",
58
+ "@moneydevkit/api-contract": "^0.1.17",
59
+ "@moneydevkit/core": "0.7.0-beta.10",
60
+ "@moneydevkit/lightning-js": "^0.1.60",
56
61
  "@orpc/client": "1.3.0",
57
62
  "@orpc/contract": "1.3.0",
58
63
  "@radix-ui/react-collapsible": "^1.1.11",