Skip to main content

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

FeatureDescription
StripeCard payments, subscriptions, checkout sessions
PayPalPayPal orders, captures, and webhooks
OnchainCryptocurrency 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 session
  • POST /pay/stripe/webhook -- Handle Stripe webhooks
  • POST /pay/paypal/order -- Create a PayPal order
  • POST /pay/paypal/capture/:orderId -- Capture a PayPal payment
  • POST /pay/paypal/webhook -- Handle PayPal webhooks
  • POST /pay/onchain/payment -- Create an on-chain payment request
  • GET /pay/onchain/payment/:id -- Check payment status
  • GET /pay/transactions -- List all transactions
  • GET /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

VariableDefaultDescription
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_SANDBOXtrueUse PayPal sandbox
RPC_URL--EVM RPC endpoint
PAYMENT_WALLET--On-chain payment receiver address