HSRCPAY Documentation

Integration Recipes

Common integration patterns and short examples.

Copy-paste recipes; adapt to your domain model before using directly in production.

Order to payment

const order = await createOrder(cart);
const payment = await hsrcpay.payments.create({
  amount: order.totalAmount,
  currency: order.currency,
  metadata: { orderId: order.id },
});
await hsrcpay.payments.confirm(payment.id, { paymentMethod: { id: pmId } });

Close order via webhook

if (event.type === "payment.succeeded") {
  await markOrderPaid(event.data.paymentId ?? event.data.metadata?.orderId);
}

Event payload shape may vary by the version you subscribe to; always verify with payment GET.

Safe error surface

try {
  await hsrcpay.payments.confirm(paymentId, body);
} catch (error) {
  logger.error({ error, paymentId }, "confirm_failed");
  return { ok: false, reason: "PAYMENT_UNAVAILABLE" };
}

Do not show raw provider messages to the user.

On this page