Skip to content

Subscription Auto‐Pay

WoompaLoompa edited this page Jul 12, 2026 · 1 revision

The CLINK plugin supports automatic payments for subscription invoices using the nDebit protocol — a Nostr-native payment authorization mechanism.

What is nDebit?

An ndebit1... string is a Bech32-encoded payment authorization that allows a third party (your BTCPay Server) to initiate Lightning payments on your behalf. It's similar to a standing order or direct debit, but for Lightning payments over Nostr.

When a customer provides their nDebit string, the plugin can automatically pay future subscription invoices without requiring the customer to manually scan a QR code each time.

How It Works

Setup Flow

  1. Customer subscribes to a recurring service on your BTCPay Store
  2. At checkout, the customer enters their ndebit1... string
  3. The plugin stores the nDebit string linked to the customer's email
  4. For future subscription invoices, the plugin automatically pays using the stored nDebit

Auto-Pay Flow

Subscription Invoice Created
        │
        ▼
Look up customer email → Find stored nDebit
        │
        ▼
nDebit found? ──Yes──► Auto-pay via Nostr (kind 21002)
        │                        │
        No                       ▼
        │               Payment confirmed
        ▼
Show QR code for manual payment

Setting Up nDebit

At Checkout (Subscription Invoices)

When a subscription invoice is detected at checkout, a special Auto-Pay with nDebit section appears above the payment box:

  1. Enter your ndebit1... string in the input field
  2. Click Pay with nDebit
  3. The plugin:
    • Stores your nDebit linked to your buyer email
    • Attempts to auto-pay the current invoice
    • Saves the nDebit for future subscription invoices

Standalone Setup Page

Customers can also set up auto-pay via the standalone nDebit setup page:

URL: /clink/ndebit-setup?storeId={storeId}&email={email}

This page can be linked from:

  • Subscription confirmation emails
  • Customer portal pages
  • Direct links from the merchant

Via Portal Session

If a portalSessionId is provided, the page automatically resolves the store and customer email from the portal session:

/clink/ndebit-setup?portalSessionId={session-id}

Supported Wallets

Currently, nDebit is supported by:

Wallet nDebit Support
ShockWallet (Browser Extension)

To find your nDebit string in ShockWallet:

  1. Open the ShockWallet browser extension
  2. Go to your wallet settings
  3. Find the nDebit or Auto-Pay section
  4. Copy your ndebit1... string

How Auto-Pay Works Internally

Connection String nDebit

If the store is configured with an nDebit in the connection string:

type=clink-noffer;noffer=noffer1...;ndebit=ndebit1...

Every new invoice is automatically paid using this nDebit when created. This is useful for merchant-controlled auto-pay scenarios.

Customer nDebit (Email-Based)

When a customer provides their nDebit at checkout:

  1. The nDebit is stored via EmailNdebitStore linked to {storeId}:{email}
  2. When a new subscription invoice is created for the same email:
    • The plugin looks up the stored nDebit
    • If found, automatically pays the invoice via the Nostr bridge
    • Returns a LightningInvoice with status Paid immediately

Payment Notification

After auto-payment, the plugin:

  1. Marks the invoice as paid in the NostrEventStore
  2. Returns the preimage from the Nostr bridge response
  3. BTCPay Server processes the payment normally

Security Considerations

  • nDebit strings are stored per-store, not shared across stores
  • Customer emails are used as the lookup key (normalized to lowercase)
  • The nDebit only authorizes payments to the specific merchant relay encoded in the string
  • Each auto-pay call generates a fresh ephemeral Nostr keypair
  • Customers can revoke access by rotating their nDebit in their wallet

Privacy

  • nDebit strings are stored in BTCPay Server's encrypted store settings
  • Email addresses are stored in BTCPay's standard customer data
  • Nostr communication uses NIP-44 encryption
  • Payment amounts are visible to the merchant's Lightning node (standard for Lightning payments)

Clone this wiki locally