Developer Docs

Node.js SDK

Official typed Node.js client for the BSync Public API. Install from npm and start accepting payments in minutes.

Installation

npm install @bsync/node-sdk

Requires Node.js 18+ (native fetch).

Examples

Create a payment intent

import { BSync } from "@bsync/node-sdk";

const bsync = new BSync({
  apiKey: process.env.BSYNC_API_KEY,
});

const payment = await bsync.paymentIntents.create({
  amount: 150,
  currency: "EGP",
  externalOrderId: "ORD-1001",
  redirectDelay: 3,
});

console.log(payment.checkoutUrl);

Verify webhook signatures

import crypto from "crypto";
import express from "express";

const app = express();

app.post("/webhooks/bsync", express.raw({ type: "application/json" }), (req, res) => {
  const signature = req.headers["x-bsync-signature"];
  const secret = process.env.BSYNC_WEBHOOK_SECRET;
  const digest = crypto.createHmac("sha256", secret).update(req.body).digest("hex");

  if (signature !== digest) {
    return res.status(401).send("Invalid signature");
  }

  const event = JSON.parse(req.body.toString());
  console.log(event.type, event.data.paymentId);
  res.status(200).send("ok");
});

Express checkout endpoint

import express from "express";
import { BSync } from "@bsync/node-sdk";

const app = express();
app.use(express.json());

const bsync = new BSync({ apiKey: process.env.BSYNC_API_KEY });

app.post("/checkout", async (req, res) => {
  const payment = await bsync.paymentIntents.create({
    amount: req.body.amount,
    currency: "EGP",
    externalOrderId: req.body.orderId,
    successUrl: "https://merchant.example/success",
    cancelUrl: "https://merchant.example/cancel",
  });

  res.json({ checkoutUrl: payment.checkoutUrl });
});

Related guides

Command Palette

Search for a command to run...