LedeWire SDK

Browser CDN — Getting Started

Add a paywall to any webpage without a build step. Drop in a single <script> tag and the Ledewire global is ready to use.

Who this is for: Site owners publishing articles, guides, or media who want to gate content without modifying an existing build pipeline.

Add the script tag

Include the CDN bundle on every page that needs paywall logic. Pin to a major version so you receive non-breaking updates automatically.

<!-- Pin to a major version in production -->
<script src="https://cdn.jsdelivr.net/npm/@ledewire/browser@0/dist/ledewire.min.js"></script>

Initialise the client

Call Ledewire.init() with your API key (available in the LedeWire merchant dashboard).

const lw = Ledewire.init({
  apiKey: 'your_api_key',

  // Optional: called when the buyer's session expires
  onAuthExpired: () => showLoginModal(),
})

Check checkout state

Call lw.checkout.state(contentId) to determine what the current visitor needs to do next. The next_required_action field drives your UI.

const state = await lw.checkout.state('content-id')

switch (state.checkout_state.next_required_action) {
  case 'view_content':
    showFullArticle()
    break
  case 'authenticate':
    showLoginPrompt()
    break
  case 'fund_wallet':
    showFundWalletPrompt(state.price_cents)
    break
  case 'purchase':
    showPurchaseButton()
    break
}

Authenticate the buyer

Use email/password or Google OAuth. On success, tokens are stored in memory (or localStorage if you prefer persistence).

// Email + password
await lw.auth.loginWithEmail({ email, password })

// Google OAuth (receives the id_token from Google Sign-In)
await lw.auth.loginWithGoogle({ id_token: googleIdToken })

Fund the wallet (Stripe)

LedeWire uses a wallet model. Buyers deposit funds first, then purchase content. Use createPaymentSession to get a Stripe client secret, then present the Stripe Elements UI.

const session = await lw.wallet.createPaymentSession({ amount_cents: 1000 })
// session.public_key  → Stripe publishable key
// session.client_secret → pass to Stripe Elements / PaymentElement

Purchase and reveal content

Once the wallet has sufficient funds, create a purchase and refresh the checkout state — next_required_action will become 'view_content'.

await lw.purchases.create({ content_id: 'content-id' })
const updated = await lw.checkout.state('content-id')
// updated.checkout_state.next_required_action === 'view_content' ✓

Full example

See examples/browser-cdn/index.html for a complete working page including wallet funding and the full paywall state machine.

Persistent sessions

By default, tokens are stored in memory and lost on page reload. To keep the buyer logged in across reloads, pass the built-in localStorageAdapter (imported via ES module, not CDN):

import { init, localStorageAdapter } from '@ledewire/browser'

const lw = init({
  apiKey: 'your_api_key',
  storage: localStorageAdapter(),  // persists to localStorage
})