Skip to content

Repository files navigation

@fanth/paymentic-sdk

TypeScript SDK for the Paymentic REST API (docs).

Install

npm install @fanth/paymentic-sdk

With pnpm:

pnpm add @fanth/paymentic-sdk

Usage

See examples in examples directory.

import { PaymenticClient } from "@fanth/paymentic-sdk";

const client = new PaymenticClient({
    pointId: process.env.PAYMENTIC_POINT_ID!,
    apiToken: process.env.PAYMENTIC_API_TOKEN!,
    signatureKey: process.env.PAYMENTIC_SIGNATURE_KEY!,
    sandbox: process.env.PAYMENTIC_IS_SANDBOX === "true",
});

const transaction = await client.createTransaction({
    amount: "10.00",
    currency: "PLN",
    title: "Order #1",
});

Webhook notifications

Use parseWebhook to verify and parse incoming Paymentic webhook calls. It checks the X-Paymentic-Signature header against the raw body and throws PaymenticInvalidSignatureError if it's missing or invalid.

// e.g. a Next.js route handler / any Request-based HTTP framework
export async function POST(request: Request) {
    const notification = await client.parseWebhook(request);

    if (notification.event === "PAYMENT.TRANSACTION_STATUS_CHANGED" && notification.status === "PAID") {
        // mark the order as paid
    }

    return new Response("OK", { status: 200 });
}

Note: parseWebhook reads the body via request.text(), so pass it the raw Request before any other code consumes the body.

Note: Not all endpoints are implemented yet. If you need an endpoint that is not implemented, feel free to open up a pull request :)

About

TypeScript SDK for the Paymentic REST API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages