Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.1 KB

File metadata and controls

57 lines (42 loc) · 1.1 KB

Quickstart

1. Install

npm install @link2pay/sdk

2. Initialize the client

import { Link2PayClient } from "@link2pay/sdk";

const client = new Link2PayClient({
  apiKey: process.env.LINK2PAY_API_KEY!,
  environment: "sandbox"
});

Use environment: "production" for live traffic.

3. Create a payment link

const paymentLink = await client.paymentLinks.create({
  amount: "49.00",
  currency: "USD",
  reference: "order_2048",
  customerEmail: "buyer@example.com",
  redirectUrl: "https://merchant.example/checkout/success"
});

console.log(paymentLink.id, paymentLink.url);

4. Fetch a payment link

const fetched = await client.paymentLinks.retrieve(paymentLink.id);
console.log(fetched.status, fetched.settlementStatus);

5. Handle webhooks securely

import { verifyWebhookSignature } from "@link2pay/sdk/webhooks";

const isValid = verifyWebhookSignature({
  payload: rawBody,
  signatureHeader: request.headers["link2pay-signature"],
  secret: process.env.LINK2PAY_WEBHOOK_SECRET!
});

if (!isValid) {
  throw new Error("Invalid webhook signature");
}