Skip to content

SwiftPayFi/sdk

Repository files navigation

SwiftPay SDKs

Official SDKs for integrating SwiftPay payment infrastructure into your applications.

πŸ“¦ Available SDKs

Checkout SDK (./checkout/)

Browser and React SDK for accepting stablecoin payments via popup, iframe, or redirect flows.

  • Package: @swiftpayfi/checkout-sdk
  • Platforms: Browser, React, vanilla JavaScript
  • Size: ~11 KB minified (IIFE)
  • Status: βœ… Production-ready
  • Documentation
import SwiftPayCheckout from '@swiftpayfi/checkout-sdk';

const checkout = new SwiftPayCheckout({ key: 'pk_live_...' });
const session = await checkout.createInvoice({ amount: 100, reference: 'order-123' });
await checkout.open();

Node.js SDK (./nodejs/)

Backend SDK for Node.js/TypeScript applications. Create invoices, manage webhooks, and handle payments server-side.

  • Package: @swiftpayfi/sdk
  • Platforms: Node.js 18+, TypeScript
  • Status: βœ… Production-ready
  • Documentation
import { SwiftPay } from '@swiftpayfi/sdk';

const client = new SwiftPay({ apiKey: 'sk_live_...' });
const invoice = await client.invoices.create({
  amount: 100,
  token: 'USDC',
  reference: 'order-123',
});

Python SDK (./python/)

Backend SDK for Python applications. Create invoices, manage webhooks, and handle payments server-side.

  • Package: swiftpay
  • Platforms: Python 3.8+
  • Status: βœ… Production-ready
  • Documentation
from swiftpay import SwiftPay

client = SwiftPay(api_key='sk_live_...')
invoice = client.invoices.create(
    amount=100,
    token='USDC',
    reference='order-123'
)

x402 Node Guard (./x402-node-guard/)

Express and Fastify middleware that enforces x402 payment-required responses, settling payments through the SwiftPay API before allowing access to protected routes.

  • Package: @swiftpayfi/x402-node-guard
  • Platforms: Node.js 18+, Express, Fastify
  • Status: βœ… Production-ready
  • Documentation
import { SwiftPay } from '@swiftpayfi/api-client';
import { x402Express } from '@swiftpayfi/x402-node-guard/express';

const client = new SwiftPay({ secretKey: process.env.SWIFTPAY_SECRET_KEY });
const x402 = x402Express({ client });

app.get('/v1/analyze', x402('https://api.example.com/v1/analyze'), (req, res) => {
  res.json({ sentiment: 'positive', score: 0.87 });
});

x402 FastAPI Guard (./x402-fastapi-guard/)

FastAPI middleware that enforces x402 payment-required responses, settling payments through the SwiftPay API before allowing access to protected routes.

  • Package: swiftpay-x402-fastapi-guard
  • Platforms: Python 3.8+, FastAPI
  • Status: βœ… Production-ready
  • Documentation
from fastapi import FastAPI
from swiftpay import AsyncSwiftPay
from swiftpay_x402_fastapi_guard import X402Guard

client = AsyncSwiftPay(secret_key="sk_live_...")

app = FastAPI()
app.add_middleware(
    X402Guard,
    client=client,
    routes={"/v1/analyze": "https://api.example.com/v1/analyze"},
)

πŸš€ Quick Start

Installation

# Checkout SDK (npm)
npm install @swiftpayfi/checkout-sdk

# Or use from CDN
<script src="https://cdn.swiftpay.finance/checkout@latest/index.iife.js"></script>

Basic Usage

// Initialize checkout
const checkout = new SwiftPayCheckout({
  key: 'pk_live_xxx',      // Your publishable key
  sandbox: false,          // Production API
  mode: 'iframe',          // popup | iframe | redirect
});

// Listen for payment completion
checkout.on('payment.completed', ({ invoice }) => {
  console.log('Payment received:', invoice.reference);
});

// Create an invoice
const session = await checkout.createInvoice({
  amount: 99.99,
  reference: 'order-12345',
});

// Open checkout UI
if (session) {
  await checkout.open();
}

Selecting the Right SDK

Use Case SDK Language
Browser/Frontend Checkout Checkout TypeScript/React
Backend Integration Node.js TypeScript/Node.js
Backend Integration Python Python
x402 Paywall (Express/Fastify) x402 Node Guard TypeScript/Node.js
x402 Paywall (FastAPI) x402 FastAPI Guard Python

SDK Comparison

Feature Checkout Node.js Python x402 Node Guard x402 FastAPI Guard
Invoice Creation ❌ Backend API βœ… βœ… ❌ ❌
Payment Detection βœ… Polling/SSE βœ… Webhooks βœ… Webhooks βœ… Auto-settle βœ… Auto-settle
Checkout UI βœ… ❌ ❌ ❌ ❌
Webhook Management ❌ βœ… βœ… ❌ ❌
x402 Paywall ❌ ❌ ❌ βœ… βœ…
Type Safety βœ… TypeScript βœ… TypeScript βœ… Type hints βœ… TypeScript βœ… Type hints

πŸš€ Getting Started by Use Case

Frontend Checkout

  1. Install: npm install @swiftpayfi/checkout-sdk
  2. Read: Checkout SDK Docs
  3. Integrate: Use popup, iframe, or redirect mode

Backend Server (Node.js)

  1. Install: npm install @swiftpayfi/sdk
  2. Read: Node.js SDK Docs
  3. Integrate: Create invoices, handle webhooks

Backend Server (Python)

  1. Install: pip install swiftpay
  2. Read: Python SDK Docs
  3. Integrate: Create invoices, handle webhooks

x402 API Paywall (Node.js)

  1. Install: npm install @swiftpayfi/x402-node-guard @swiftpayfi/api-client
  2. Read: x402 Node Guard Docs
  3. Integrate: Add middleware to Express or Fastify routes

x402 API Paywall (Python)

  1. Install: pip install swiftpay-x402-fastapi-guard
  2. Read: x402 FastAPI Guard Docs
  3. Integrate: Add middleware to FastAPI routes

πŸ“‚ Repository Structure

sdk/
β”œβ”€β”€ checkout/                      # Browser/React checkout SDK (TypeScript)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts              # Main SDK class
β”‚   β”‚   └── react.ts              # React hook
β”‚   β”œβ”€β”€ dist/                      # Compiled & minified output
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ README.md                  # Complete documentation
β”‚   └── .gitignore
β”‚
β”œβ”€β”€ nodejs/                        # Backend SDK (Node.js/TypeScript)
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ dist/
β”‚   β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ README.md                  # Complete documentation
β”‚   └── vitest.config.ts           # Testing configuration
β”‚
β”œβ”€β”€ python/                        # Backend SDK (Python)
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ pyproject.toml
β”‚   β”œβ”€β”€ README.md                  # Complete documentation
β”‚   └── .python-version
β”‚
β”œβ”€β”€ x402-node-guard/               # x402 payment middleware (Express/Fastify)
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ package.json
β”‚   └── README.md                  # Complete documentation
β”‚
β”œβ”€β”€ x402-fastapi-guard/            # x402 payment middleware (FastAPI)
β”‚   β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ pyproject.toml
β”‚   └── README.md                  # Complete documentation
β”‚
β”œβ”€β”€ .github/workflows/
β”‚   β”œβ”€β”€ checkout-ci.yml            # Checkout SDK CI
β”‚   β”œβ”€β”€ checkout-release.yml       # Checkout SDK release
β”‚   β”œβ”€β”€ nodejs-ci.yml              # Node.js SDK CI
β”‚   β”œβ”€β”€ nodejs-release.yml         # Node.js SDK release
β”‚   β”œβ”€β”€ python-ci.yml              # Python SDK CI
β”‚   └── python-release.yml         # Python SDK release
β”‚
β”œβ”€β”€ .changeset/
β”‚   β”œβ”€β”€ config.json                # Changesets configuration
β”‚   └── README.md                  # Version management guide
β”‚
β”œβ”€β”€ LICENSE                        # Apache 2.0 (applies to all SDKs)
β”œβ”€β”€ .gitignore
└── README.md                      # This file

πŸ› οΈ Development

Local Setup

cd checkout

# Install dependencies
npm install

# Development mode (watch TypeScript compilation)
npm run dev

# Build all formats
npm run build

# Build specific formats
npm run build:types    # TypeScript declarations
npm run build:esm      # ES modules for npm
npm run build:iife     # Standalone browser script

Making Changes

  1. Create feature branch from dev or main:

    git checkout -b feat/my-feature dev
  2. Make your changes to the SDK

  3. Document the change with a changeset:

    npx changeset add
    # Interactive prompt guides you through:
    # - Which package changed
    # - Bump type (major/minor/patch)
    # - Change description
  4. Commit and push:

    git add .changeset/*.md checkout/
    git commit -m "feat: add new capability"
    git push origin feat/my-feature
  5. Open a pull request on GitHub β€” CI runs automatically

Development Branches

Branch Purpose Auto-publishes
main Production releases βœ… Latest to npm + CDN
dev Beta/pre-release testing βœ… Beta versions to npm
feat/* Feature branches ❌ Only for CI verification

πŸ“¦ Releases & Versions

Version Numbering

  • Production: 1.0.0, 1.1.0, 2.0.0 (semantic versioning)
  • Beta: 1.0.0-beta.1, 1.0.0-beta.2 (on dev branch)

Accessing Releases

# Latest production version
npm install @swiftpayfi/checkout-sdk

# Specific version
npm install @swiftpayfi/checkout-sdk@1.0.0

# Latest beta (pre-release)
npm install @swiftpayfi/checkout-sdk@beta

# Browser CDN (production)
<script src="https://cdn.swiftpay.finance/checkout@latest/index.iife.js"></script>

# Browser CDN (specific version)
<script src="https://cdn.swiftpay.finance/checkout@1.0.0/index.iife.js"></script>

# Browser CDN (beta)
<script src="https://cdn.swiftpay.finance/checkout@beta/index.iife.js"></script>

Version Management

This project uses Changesets for automated version management. When you add a changeset, the version bump and changelog are generated automatically during release.

For detailed information, see Changesets Guide.

πŸ› οΈ System Requirements

  • Node.js: 20.0.0 or higher
  • npm: 10.0.0 or higher

Build Dependencies

  • TypeScript (5.9+) β€” Type checking
  • esbuild (0.21+) β€” Bundling and minification
  • Changesets (2.31+) β€” Version management
  • React (18+) β€” Peer dependency for React hook

πŸ§ͺ Testing

Manual Testing Checklist

  • βœ… SDK initialization with different options
  • βœ… Invoice creation and checkout flows
  • βœ… All checkout modes (popup, iframe, redirect)
  • βœ… Event emission and callbacks
  • βœ… Error handling and edge cases
  • βœ… Cross-browser compatibility (Chrome, Firefox, Safari, Edge)
  • βœ… Mobile responsiveness

Automated CI

Pull requests and pushes to main, dev, and feat/* branches automatically run:

  • TypeScript type checking
  • Bundle generation (ESM + IIFE)
  • Package integrity verification

πŸ” Security

API Endpoints

Environment Endpoint
Production https://api.swiftpay.finance
Sandbox https://sandbox-api.swiftpay.finance

The SDK automatically selects the correct endpoint based on the sandbox option.

Best Practices

  • βœ… Use publishable keys only (pk_*) in client code
  • βœ… Never commit or expose secret keys (sk_*)
  • βœ… Always use HTTPS in production
  • βœ… Validate origin in iframe integrations
  • βœ… Keep SDKs updated for security patches
  • βœ… Never log sensitive data (tokens, keys, card numbers)

πŸ“– Documentation

🀝 Contributing

We welcome contributions! Here's how to get started:

  1. Review the development section above
  2. Create a feature branch from dev or main
  3. Make your changes and add a changeset
  4. Submit a pull request with a clear description
  5. Ensure CI passes and request review
  6. Once approved, merge your PR

Contribution Guidelines

  • Code style: Follow existing patterns in the codebase
  • TypeScript: Use strict type checking
  • Documentation: Update README.md if adding public APIs
  • Testing: Add manual test cases for new features
  • Commits: Write clear, descriptive commit messages
  • Changesets: Document all user-facing changes

πŸ“ž Support & Feedback

πŸ“„ License

Licensed under the Apache License, Version 2.0.

Summary:

  • βœ… Free to use, modify, and distribute
  • βœ… Commercial use allowed
  • βœ… Patent protection included
  • βœ… Must include license and copyright notice
  • βœ… No warranty or liability

Copyright Β© 2026 SwiftPay Finance

See LICENSE for full details.


Last Updated: May 2026
Latest Release: Check releases page
API Version: v1

About

Official SDKs for integrating SwiftPay payment infrastructure into your applications.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors