@fanth/paymentic-sdk
v0.1.8
Published
TypeScript SDK for the Paymentic REST API
Readme
@fanth/paymentic-sdk
TypeScript SDK for the Paymentic REST API (docs).
Install
npm install @fanth/paymentic-sdkWith pnpm:
pnpm add @fanth/paymentic-sdkUsage
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:
parseWebhookreads the body viarequest.text(), so pass it the rawRequestbefore 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 :)
