Pakistan payment integration

EasyPaisa subscription webhook integration

Use the SSCodeAxis Paywall SDK to start a PKR checkout, verify the resulting webhook, and project subscription access into your app.

1. Create the checkout intent

Create the intent on your server and keep the API key private.

import { PaywallSDK } from "@sscodeaxis/paywall-sdk";

const sdk = new PaywallSDK({
  apiKey: process.env.PLATFORM_API_KEY!,
  baseUrl: process.env.PLATFORM_API_URL!,
});

const { id: intentId } = await sdk.checkout.createIntent({
  customerEmail: "customer@example.com",
  planId: process.env.PLAN_ID!,
  priceId: process.env.PKR_PRICE_ID!,
  successUrl: "https://yourapp.com/billing/success",
  cancelUrl: "https://yourapp.com/billing/cancelled",
});

// Redirect the customer to your hosted checkout with intentId.

2. Verify the webhook

Pass the raw request body to the verifier. Do not parse and reserialize it before signature validation.

import { constructWebhookEvent } from "@sscodeaxis/paywall-sdk";

app.post("/webhooks/sscodeaxis", express.raw({ type: "application/json" }), (req, res) => {
  const event = constructWebhookEvent(
    req.body.toString("utf8"),
    {
      signature: req.header("X-Webhook-Signature"),
      eventType: req.header("X-Webhook-Event"),
      deliveryId: req.header("X-Webhook-Delivery-Id"),
    },
    process.env.PLATFORM_WEBHOOK_SECRET!,
  );

  if (event.eventType === "subscription.updated") {
    // Update your local access projection idempotently.
  }
  res.sendStatus(200);
});

3. Handle recurring access correctly

EasyPaisa does not provide a native recurring-subscription primitive in the current adapter. Treat each renewal as a new provider checkout, or use a provider that supports native recurring billing. Only extend access after a verified successful payment event, and make webhook handling idempotent.