Vanilla JavaScript / Any Platform
Works in any Node.js backend, Deno, Bun, Cloudflare Workers, or browser (session creation must be server-side).
npm install @swft-checkout/jsExpress
Section titled “Express”import express from 'express'import { createSession, verifySwftWebhookNode } from '@swft-checkout/js'
const app = express()
// Checkout endpoint — redirects to Swftapp.post('/checkout', async (req, res) => { const session = await createSession({ merchantApiKey: process.env.SWFT_MERCHANT_API_KEY, currency: 'GBP', lineItems: req.body.items, shippingMethods: [{ id: 'standard', label: 'Standard', cost: 499 }], subtotal: req.body.subtotal, }) res.redirect(session.sessionUrl)})
// Webhookapp.post('/webhooks/swft', express.raw({ type: 'application/json' }), (req, res) => { const payload = verifySwftWebhookNode( req.body, req.headers['x-swft-signature'] as string, process.env.SWFT_WEBHOOK_SECRET ) // handle payload.event === 'payment_succeeded' res.json({ received: true })})Cloudflare Workers / Deno / Bun
Section titled “Cloudflare Workers / Deno / Bun”Use verifySwftWebhook (async, Web Crypto API) instead of verifySwftWebhookNode.