@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
| Item | Value |
|---|---|
| Framework | Svelte 5 (runs in SvelteKit) |
| Package | @payproof/svelte |
| Version | 0.4.2 |
| Key | pk_live_… (publishable client key) |
| Browsers | Current Chrome, Safari, Firefox, Edge |
Install
npm install @payproof/svelte@0.4.2Initialize
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.
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.
// 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.
<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} />| Component | Props | Purpose |
|---|---|---|
Paywall | appId, customerRef, onVerified | Live packages grouped by billing period, checkout sheet, receipt upload. |
PayProofAccess | appId, online, accessMode, onNeedLogin | Renders children only when the entitlement allows access; handles offline grace. |
ManageSubscription | appId, onViewPlans | Current plan, renewal/grace state, change-plan entry point. Cancel and resume are opt-in per app. |
StatusCard | status, onRenew, onPayRemaining, onManage | Compact state card for headers and account pages. |
PackageList | packages, selectedId, onSelect | Headless 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.
| Method | Returns | Notes |
|---|---|---|
getOfferings(appId?) | Catalog packages and products | Use for a custom pricing page. |
createCheckout(request) | Created checkout | Sends an Idempotency-Key automatically. Prefer server creation. |
getPublicCheckout(publicId) | Checkout + payment accounts | Public; no key required. |
getBillingStatus(opts?) | Billing state for a customer or checkout | Accepts customerRef, appId, or checkoutId. |
getEntitlement(opts?) | Authoritative access decision | Includes server time for offline caching. |
getMe() / getHealth() | Key introspection / liveness | Wrapped by diagnose(). |
cancelSubscription(opts?) | SubscriptionStatus | Defaults to period end. Prefers the synced subscriptionId. Opt-in for publishable keys. |
resumeSubscription(id?) | SubscriptionStatus | Undoes a scheduled cancellation before period end. |
// 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();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
// 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.
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.
import { userMessage, userHint } from '@payproof/svelte';
const res = await PayProof.getEntitlement({ customerRef: user.id });
if (!res.ok) {
showBanner(userMessage(res), userHint(res));
}Related
/api/v1/me/