Server API
Node SDK
`@mercestack/node` — a typed client for the server API.
Shell
pnpm add @mercestack/nodeTypeScript
import { Mercestack } from "@mercestack/node";
const mercestack = new Mercestack(process.env.MERCESTACK_SECRET_KEY!);
const link = await mercestack.paymentLinks.create(
{ title: "Invoice 88", amount: "150000" },
{ idempotencyKey: "invoice-88" },
);- Throws on a publishable key before sending anything.
- Retries network errors,
429and5xx— but a create only when you gave it anidempotencyKey, so a retry can't charge twice. .all()on customers and transactions walks every page for you.- Errors are
MercestackErrorwithstatus,code,messageandrequestId.
Webhooks
TypeScript
app.post("/mercestack", express.raw({ type: "application/json" }), (req, res) => {
const event = mercestack.webhooks.constructEvent(
req.body, // the raw bytes
req.header("Mercestack-Signature"),
process.env.MERCESTACK_WEBHOOK_SECRET!,
);
if (event.type === "payment_link.paid") fulfil(event.data);
res.sendStatus(200);
});Methods
TypeScript
mercestack.customers.list(params) .retrieve(id) .create(input) .update(id, input) .all()
mercestack.paymentLinks.list(params) .retrieve(id) .create(input) .deactivate(id)
mercestack.transactions.list(params) .retrieve(idOrReference) .all()
mercestack.balance.retrieve()
mercestack.payouts.list()
mercestack.classrooms.list() .retrieve(id)
mercestack.classrooms.enrollments.list(classId) .create(classId, input)
mercestack.products.list() .retrieve(id)
mercestack.orders.list() .retrieve(id)
mercestack.webhooks.constructEvent(rawBody, signature, secret)Email API
The same package has a client for the Email API, which takes an Email API key (msk_live_…) and talks to emailapi.mercestack.com. See Email API for the endpoints.
TypeScript
import { MercestackEmail } from "@mercestack/node";
const email = new MercestackEmail(process.env.MERCESTACK_EMAIL_KEY!);
email.emails.send(input, { idempotencyKey }) .batch(messages) .get(id) .cancel(id)
email.templates.list() .get(aliasOrId) .create(input) .update(aliasOrId, input) .remove(aliasOrId)