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

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,13 +21,17 @@ 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
+ title: 'Describe the purchase shown to the buyer',
31
35
  description: 'A description of the purchase',
32
36
  amount: 500, // 500 USD cents or Bitcoin sats
33
37
  currency: 'USD', // or 'SAT'
@@ -38,12 +42,22 @@ export default function HomePage() {
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,7 @@ 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({
86
100
  title: "Premium Plan",
87
101
  description: 'Monthly subscription',
88
102
  amount: 1000,
@@ -115,7 +129,7 @@ Customers are matched by `email` or `externalId`. When a match is found:
115
129
  When your user is already authenticated in your app, pass `externalId` to link checkouts to their account:
116
130
 
117
131
  ```jsx
118
- navigate({
132
+ const result = await createCheckout({
119
133
  title: "Premium Plan",
120
134
  description: 'Monthly subscription',
121
135
  amount: 1000,
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ 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 type { MdkError, Result } from '@moneydevkit/core/client';
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.2",
4
4
  "title": "@moneydevkit/nextjs",
5
5
  "description": "moneydevkit checkout components for Next.js.",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  "dependencies": {
52
52
  "@hookform/resolvers": "^5.0.1",
53
53
  "@moneydevkit/api-contract": "^0.1.13",
54
- "@moneydevkit/core": "0.7.0-beta.0",
54
+ "@moneydevkit/core": "0.7.0-beta.2",
55
55
  "@moneydevkit/lightning-js": "^0.1.59",
56
56
  "@orpc/client": "1.3.0",
57
57
  "@orpc/contract": "1.3.0",