TypeScript SDK
Use moosyl-sdk in TypeScript and Node.js apps
Overview
Use moosyl-sdk for backend/server flows and custom frontend integrations without prebuilt UI.
Installation
npm install moosyl-sdkCreate Client
import { Moosyl } from "moosyl-sdk";
const moosyl = new Moosyl("pk_test_...");Core Usage
const methods = await moosyl.getPaymentMethods(true);
const request = await moosyl.getPaymentRequest("txn_123");Process payment:
await moosyl.pay("txn_123", "+22212345678", "PASSCODE", "METHOD_ID");Backend-Only Methods
Use a secret key on your backend:
import { Moosyl } from "moosyl-sdk";
const moosyl = new Moosyl(process.env.MOOSYL_SECRET_KEY!);
const session = await moosyl.createCheckoutSession({
paymentRequestId: "payment_request_id",
transactionId: "txn_123",
amount: 5000,
phoneNumber: "+22212345678",
successUrl: "https://example.com/success",
cancelUrl: "https://example.com/cancel",
expiresInMinutes: 5,
});For a focused hosted-checkout flow, see Checkout Session.
Webhook Verification
const ok = moosyl.verifyWebhookSignature(rawBody, signature, webhookSecret);Notes
- Use publishable key for client-safe reads.
- Use secret key only on trusted backend infrastructure.
- Verify webhook signatures with your webhook secret.