Svelte / SvelteKit SDK

Checkout sheet, live pricing, entitlement gates, and subscription management for Svelte 5 apps.

AGENTS.md

@payproof/svelte is the web counterpart of the Android SDK. It ships the same bank-transfer checkout sheet, catalog helpers, entitlement cache, and manage-subscription screen with matching copy and design tokens.

Requirements

ItemValue
FrameworkSvelte 5 (runs in SvelteKit)
Package@payproof/svelte
Version0.4.2
Keypk_live_… (publishable client key)
BrowsersCurrent Chrome, Safari, Firefox, Edge

Install

shell
npm install @payproof/svelte@0.4.2

Initialize

src/lib/payproof.ts
import { PayProof } from '@payproof/svelte';
import '@payproof/svelte/theme.css';

PayProof.init({
  baseUrl: 'https://api.payproof.et',
  clientKey: 'pk_live_...', // publishable key — safe in the browser
  appId: 1,                 // optional when the key is app-scoped
});

Call init once in a browser-only module. During server-side rendering the SDK is inert; guard checkout calls with browser from $app/environment or call them from event handlers and onMount.

Identify the customer

After your own authentication, pass your stable user id. Entitlements are cached per customer, so the same value must be used on every device.

Svelte
PayProof.identify(user.id);

// On logout
PayProof.logOut();

Checkout

Create the checkout on your backend with a secret key, then hand only the public id to the browser. This keeps sk_… out of the bundle and lets you authorize the purchase server-side.

Server
// Your backend — never in the browser
const res = await fetch('https://api.payproof.et/api/v1/checkouts/', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PAYPROOF_SECRET_KEY}`,
    'Idempotency-Key': `order_${order.id}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    product_id: 12,
    customer_ref: user.id,
    success_url: `https://app.example.com/orders/${order.id}/thanks`,
  }),
});

const { checkout } = await res.json();
return checkout.public_id; // cs_...

Drop-in UI

Every component is optional. Use the paywall for a complete pricing list, or compose the pieces into your own layout.

Svelte
<script lang="ts">
  import {
    Paywall,
    PayProofAccess,
    ManageSubscription,
    StatusCard,
  } from '@payproof/svelte';
</script>

<!-- Pricing list + checkout, driven by the live catalog -->
<Paywall appId={appId} customerRef={user.id} onVerified={refresh} />

<!-- Gate app content on the server-issued entitlement -->
<PayProofAccess appId={appId} online={navigator.onLine}>
  <Dashboard />
</PayProofAccess>

<!-- Account screen: plan, renewal date, change plan -->
<ManageSubscription appId={appId} onViewPlans={() => showPlans = true} />
ComponentPropsPurpose
PaywallappId, customerRef, onVerifiedLive packages grouped by billing period, checkout sheet, receipt upload.
PayProofAccessappId, online, accessMode, onNeedLoginRenders children only when the entitlement allows access; handles offline grace.
ManageSubscriptionappId, onViewPlansCurrent plan, renewal/grace state, change-plan entry point. Cancel and resume are opt-in per app.
StatusCardstatus, onRenew, onPayRemaining, onManageCompact state card for headers and account pages.
PackageListpackages, selectedId, onSelectHeadless row list when you want a custom pricing layout.

Headless API

PayProof.client() exposes the same calls as the REST API without UI. Types match the wire contract.

MethodReturnsNotes
getOfferings(appId?)Catalog packages and productsUse for a custom pricing page.
createCheckout(request)Created checkoutSends an Idempotency-Key automatically. Prefer server creation.
getPublicCheckout(publicId)Checkout + payment accountsPublic; no key required.
getBillingStatus(opts?)Billing state for a customer or checkoutAccepts customerRef, appId, or checkoutId.
getEntitlement(opts?)Authoritative access decisionIncludes server time for offline caching.
getMe() / getHealth()Key introspection / livenessWrapped by diagnose().
cancelSubscription(opts?)SubscriptionStatusDefaults to period end. Prefers the synced subscriptionId. Opt-in for publishable keys.
resumeSubscription(id?)SubscriptionStatusUndoes a scheduled cancellation before period end.
Cancel / resume
// Prefer secret-key calls from your backend.
// Client keys work only when the app enables client cancel/resume.
await PayProof.cancelSubscription(); // at period end
await PayProof.resumeSubscription();
Svelte
const catalog = await PayProof.getOfferings();

const status = await PayProof.getBillingStatus({
  customerRef: user.id,
});

const entitlement = await PayProof.getEntitlement({
  customerRef: user.id,
});

Plan changes and trials

Svelte
// Preview first so the customer sees the amount and effective date
const quote = await PayProof.previewPlanChange(appId, packageId);

if (quote.ok) {
  // quote.value.amountEtb, direction, currentPeriodEnd
  const result = await PayProof.changePlan(appId, packageId);
}

// Server decides whether the trial is available
const trial = await PayProof.startTrial(appId, packageId);

The server enforces the app's plan_change_policy (prorate, full price, or at period end) and returns NeedsCheckout when a payment is required.

Diagnose

One call validates the key, its app binding, its scopes, and server reachability. Ask merchants to attach the output to support requests.

Svelte
const report = await PayProof.diagnose();

// {
//   ok: true,
//   sdkVersion: '0.4.2',
//   baseUrl: 'https://api.payproof.et',
//   key: { type: 'publishable', app_id: 1, scopes: [...] },
//   app: { id: 1, name: 'My Shop' },
//   serverTime: '2026-10-23T12:00:00Z',
//   health: { status: 'ok' }
// }

Errors

Every call returns { ok: true, value } or { ok: false, code, message }. Use userMessage() and userHint() for ready-to-render copy, or work with the raw code.

Svelte
import { userMessage, userHint } from '@payproof/svelte';

const res = await PayProof.getEntitlement({ customerRef: user.id });

if (!res.ok) {
  showBanner(userMessage(res), userHint(res));
}
GET/api/v1/me/