Skip to main content
@moneydevkit/nextjs is the moneydevkit checkout SDK for App Router-based Next.js apps. It bundles the client hook, hosted checkout UI, API route handler, and config helpers required to launch Lightning-powered payments within minutes.

Setup

  1. Create a Money Dev Kit account at moneydevkit.com or run npx @moneydevkit/create to generate credentials locally, then grab your api_key and mnemonic.
  2. Install the SDK in your project:
    npm install @moneydevkit/nextjs
    
  3. Add required secrets to .env (or similar):
    MDK_ACCESS_TOKEN=your_api_key_here
    MDK_MNEMONIC=your_mnemonic_here
    

Quick Start (Next.js App Router)

1

Trigger a checkout from any client component

// app/page.js
'use client'

import { useCheckout } from '@moneydevkit/nextjs'

export default function HomePage() {
  const { navigate, isNavigating } = useCheckout()

  const handlePurchase = () => {
    navigate({
      title: "Describe the purchase shown to the buyer",
      description: 'A description of the purchase',
      amount: 500,
      currency: 'USD',
      successUrl: '/checkout/success',
      metadata: {
        type: 'my_type',
        customField: 'internal reference for this checkout',
        name: 'John Doe'
      }
    })
  }

  return (
    <button onClick={handlePurchase} disabled={isNavigating}>
      {isNavigating ? 'Creating checkout…' : 'Buy Now'}
    </button>
  )
}
2

Render the hosted checkout page

// app/checkout/[id]/page.js
"use client";
import { Checkout } from "@moneydevkit/nextjs";
import { use } from "react";

export default function CheckoutPage({ params }) {
  const { id } = use(params);

  return <Checkout id={id} />;
}
3

Expose the unified Money Dev Kit endpoint

// app/api/mdk/route.js
export { POST } from '@moneydevkit/nextjs/server/route'
4

Configure Next.js

// next.config.js / next.config.mjs
import withMdkCheckout from '@moneydevkit/nextjs/next-plugin'

export default withMdkCheckout({})
You now have a complete Lightning checkout loop: the button creates a session, the dynamic route renders it, and the webhook endpoint signals your Lightning node to claim paid invoices.

Verify successful payments

When a checkout completes, use useCheckoutSuccess() on the success page.
'use client'

import { useCheckoutSuccess } from '@moneydevkit/nextjs'

export default function SuccessPage() {
  const { isCheckoutPaidLoading, isCheckoutPaid, metadata } = useCheckoutSuccess()

  if (isCheckoutPaidLoading || isCheckoutPaid === null) {
    return <p>Verifying payment…</p>
  }

  if (!isCheckoutPaid) {
    return <p>Payment has not been confirmed.</p>
  }

  // Access custom fields set during navigate() for informational purposes
  console.log('Customer name:', metadata?.name) // "John Doe"
  console.log('Custom field:', metadata?.customField)

  return (
    <div>
      <p>Payment confirmed. Enjoy your purchase!</p>
    </div>
  )
}

Customers

Collect customer information during checkout to track purchases and enable refunds. See the full Customers documentation for more details.

Pass Customer Data Directly

If you already know the customer’s information, pass it when creating the checkout:
navigate({
  title: 'Product Name',
  amount: 500,
  currency: 'USD',
  successUrl: '/checkout/success',
  customer: {
    email: '[email protected]',
    name: 'Jane Doe',
    externalId: 'user-123' // Your system's user ID
  }
})

Require Customer Data Entry

Use requireCustomerData to display a form that collects customer information before payment:
navigate({
  title: 'Product Name',
  amount: 500,
  currency: 'USD',
  successUrl: '/checkout/success',
  requireCustomerData: ['email', 'name']
})

Combining Both Approaches

Pre-fill known data and require additional fields:
navigate({
  title: 'Product Name',
  amount: 500,
  currency: 'USD',
  successUrl: '/checkout/success',
  customer: {
    externalId: 'user-123',
    name: 'Jane Doe'
  },
  requireCustomerData: ['email', 'name', 'company']
  // Form will only ask for email and company since name is already provided
})