Pay Wire
The Pay wire (@fluxkitdev/pay) provides a unified payment processing interface for Stripe, PayPal, and on-chain cryptocurrency payments.
Installation
npm install @fluxkitdev/core @fluxkitdev/pay
Quick Start
import { FluxKit } from "@fluxkitdev/core";
import { pay } from "@fluxkitdev/pay";
const app = new FluxKit({
wires: [
pay({
stripe: {
secretKey: process.env.STRIPE_SECRET_KEY,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
},
paypal: {
clientId: process.env.PAYPAL_CLIENT_ID,
clientSecret: process.env.PAYPAL_CLIENT_SECRET,
sandbox: process.env.NODE_ENV !== "production",
},
onchain: {
rpcUrl: process.env.RPC_URL,
receiverAddress: process.env.PAYMENT_WALLET,
supportedTokens: ["USDC", "USDT", "ETH"],
},
}),
],
database: { uri: process.env.MONGODB_URI },
});
await app.start({ port: 3000 });
Features
| Feature | Description |
|---|---|
| Stripe | Card payments, subscriptions, checkout sessions |
| PayPal | PayPal orders, captures, and webhooks |
| Onchain | Cryptocurrency payments on EVM chains |
Programmatic API
// Create a Stripe checkout session
const session = await app.pay.stripe.createCheckout({
items: [{ name: "Pro Plan", amount: 2999, currency: "usd" }],
successUrl: "https://myapp.com/success",
cancelUrl: "https://myapp.com/cancel",
});
// Create a PayPal order
const order = await app.pay.paypal.createOrder({
amount: 29.99,
currency: "USD",
description: "Pro Plan",
});
// Create an on-chain payment request
const payment = await app.pay.onchain.createPayment({
amount: "29.99",
token: "USDC",
chain: "arbitrum",
});
REST API Endpoints
POST /pay/stripe/checkout-- Create a Stripe checkout sessionPOST /pay/stripe/webhook-- Handle Stripe webhooksPOST /pay/paypal/order-- Create a PayPal orderPOST /pay/paypal/capture/:orderId-- Capture a PayPal paymentPOST /pay/paypal/webhook-- Handle PayPal webhooksPOST /pay/onchain/payment-- Create an on-chain payment requestGET /pay/onchain/payment/:id-- Check payment statusGET /pay/transactions-- List all transactionsGET /pay/health-- Health check
Transaction Model
All payments, regardless of provider, are tracked in a unified pay_transactions collection:
interface Transaction {
_id: ObjectId;
provider: "stripe" | "paypal" | "onchain";
status: "pending" | "completed" | "failed" | "refunded";
amount: number;
currency: string;
metadata: Record<string, unknown>;
providerTransactionId: string;
userId?: string;
createdAt: Date;
updatedAt: Date;
}
Environment Variables
| Variable | Default | Description |
|---|---|---|
STRIPE_SECRET_KEY | -- | Stripe secret key |
STRIPE_WEBHOOK_SECRET | -- | Stripe webhook signing secret |
PAYPAL_CLIENT_ID | -- | PayPal client ID |
PAYPAL_CLIENT_SECRET | -- | PayPal client secret |
PAYPAL_SANDBOX | true | Use PayPal sandbox |
RPC_URL | -- | EVM RPC endpoint |
PAYMENT_WALLET | -- | On-chain payment receiver address |