@moneydevkit/nextjs 0.6.2 → 0.7.0-alpha.1
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 +64 -11
- package/dist/hooks/useProducts.d.ts +1 -0
- package/dist/hooks/useProducts.js +3 -0
- package/dist/hooks/useProducts.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +2 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/route.d.ts +1 -1
- package/dist/server/route.js +1 -1
- package/dist/server/route.js.map +1 -1
- package/package.json +9 -4
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 {
|
|
27
|
+
const { createCheckout, isLoading } = useCheckout()
|
|
28
|
+
const [error, setError] = useState(null)
|
|
27
29
|
|
|
28
|
-
const handlePurchase = () => {
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
<
|
|
45
|
-
{
|
|
46
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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,43 @@ 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
|
+
products: [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 `products` array with product IDs. Amount is calculated from product prices.
|
|
191
|
+
|
|
139
192
|
## Verify successful payments
|
|
140
193
|
When a checkout completes, use `useCheckoutSuccess()` on the success page
|
|
141
194
|
```tsx
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useProducts } from '@moneydevkit/core/client';
|
|
@@ -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
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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA"}
|
package/dist/server/route.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { POST } from '@moneydevkit/core/route';
|
|
1
|
+
export { POST, GET } from '@moneydevkit/core/route';
|
package/dist/server/route.js
CHANGED
|
@@ -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
|
package/dist/server/route.js.map
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.7.0-alpha.1",
|
|
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.
|
|
54
|
-
"@moneydevkit/core": "0.
|
|
55
|
-
"@moneydevkit/lightning-js": "^0.1.
|
|
58
|
+
"@moneydevkit/api-contract": "^0.1.16",
|
|
59
|
+
"@moneydevkit/core": "0.7.0-alpha.1",
|
|
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",
|