Build your backend integration
This guide covers a custom server integration. For embedded mobile screens, use the SDK quickstart.
Your website or mobile app calls your backend. Only your backend calls Zwipe. This lets you keep partner credentials private, enforce customer ownership, and recover orders even when a customer closes the app.
Define your application routes
Section titled “Define your application routes”These are suggested routes you implement, not endpoints provided by Zwipe:
| Your route | Backend behavior |
|---|---|
POST /api/me/cardholder/send-code |
Resolve the customer’s email, authorize the action, apply resend controls, then call Zwipe. |
POST /api/me/cardholder/confirm-code |
Bind the submitted code to that customer’s selected email and check verified. |
POST /api/orders/{orderId}/card |
Verify ownership and funding, persist/lock the order, then submit its stable Zwipe request. |
GET /api/me/cards/{cardId} |
Check ownership, read status, return a customer-safe response. |
GET /api/me/cards/{cardId}/balance |
Check ownership, read balance, return integer cents and as_of. |
POST /api/me/cards/{cardId}/wallet-link |
Check ownership, retrieve the available issuer link on demand, return it with Cache-Control: no-store. |
Use your normal authenticated session. Cookie-based write routes need your application’s CSRF protection. Do not accept an arbitrary email or Zwipe ID as proof of ownership.
Persist before calling the API
Section titled “Persist before calling the API”At minimum, store the following with your own purchase record:
order_id, customer_id, payment_referenceexternal_ref (unique across the partner account)amount_cents, currency, first_name, last_name, email, phonebrand_id, restaurant_idzwipe_card_id, issuer_card_id, issuer_order_idlatest_status, latest_error_code, submitted_at, last_checked_atKeep the original request fields immutable after submission. Protect personal data according to your application’s retention and access policy. Do not store full response bodies indiscriminately: issuer links are sensitive.
Generate a reference such as purchase-1001 once and save it before the first network call. A request timeout must not generate purchase-1002 for the same purchase.
Submit from a durable worker
Section titled “Submit from a durable worker”This example uses the downloadable Node.js client. orders is your application repository, not a Zwipe package. Its withExclusiveOrder operation must serialize submissions for one order and persist the state described below. Implement it with a worker lease or another durable concurrency mechanism; do not hold an ordinary database transaction open across a long issuer call.
import { ZwipeClient } from './zwipe-client.mjs';
const zwipe = new ZwipeClient({ clientId: process.env.ZWIPE_CLIENT_ID, clientSecret: process.env.ZWIPE_CLIENT_SECRET,});
export async function submitPreparedOrder(orderId, orders) { return orders.withExclusiveOrder(orderId, async order => { // Your application implements these checks and persists the original request. if (!order.fundingConfirmed || !order.emailReady) { throw new Error('Order is not ready for issuance'); } if (order.zwipeCardId) return zwipe.getCard(order.zwipeCardId); if (order.submissionStartedAt) { // A prior attempt may have reached Zwipe. Recover this order separately. throw new Error('Order requires reconciliation'); }
await orders.markSubmissionStarted(order.id); const card = await zwipe.issueCard(order.zwipeRequest); // Persist IDs/status, but do not log or retain the wallet link here. await orders.saveZwipeResult(order.id, { cardId: card.card_id, status: card.status, errorCode: card.error_code, issuerCardId: card.issuer?.card_id ?? null, issuerOrderId: card.issuer?.order_id ?? null, }); return { card_id: card.card_id, status: card.status }; });}order.zwipeRequest is the validated CardRequest from the quickstart, built from your database. Never pass req.body straight into issueCard or trust a browser-supplied amount, restaurant, or funding flag.
If the network call or the result save fails, the persisted submission marker keeps another worker from blindly creating a new order. Reconcile using the original reference and exact request. Replaying the same reference can requeue a failed order, so make recovery a deliberate action. See replay behavior.
Authorize every read
Section titled “Authorize every read”An Express-style balance handler can look like this. requireCustomer and cards.findOwnedBy are application-provided authentication and database functions. They are deliberately not supplied by Zwipe.
app.get('/api/me/cards/:cardId/balance', requireCustomer, async (req, res, next) => { try { const card = await cards.findOwnedBy(req.user.id, req.params.cardId); if (!card) return res.sendStatus(404);
const balance = await zwipe.getBalance(card.zwipeCardId); res.set('Cache-Control', 'no-store').json({ card_id: balance.card_id, balance_cents: balance.balance_cents, currency: balance.currency, as_of: balance.as_of, }); } catch (error) { next(error); // Your error middleware returns a safe, documented app error. }});Zwipe scopes isolate partner accounts. They do not isolate customers inside your account; that is why the ownership lookup is required.
Polling and recovery
Section titled “Polling and recovery”Poll status roughly every two seconds during the initial foreground wait, then return a processing screen and let a durable background task resume. Store a next-check time and avoid having every open browser tab independently poll Zwipe.
Stop normal polling on issued or failed. Route in_doubt to the uncertain-order workflow. A UI timeout, lost mobile connection, or app close is not an issuance failure.
There is no lookup-by-external_ref endpoint or card list. Webhooks shorten the wait but do not replace the stored mapping. Your stored mapping and unfinished-order queue are part of the integration.
Return a small application response
Section titled “Return a small application response”Expose status, balance, timestamp, and the fields needed by the current screen. Keep Zwipe credentials, issuer order details, and raw error payloads on your server. Retrieve wallet links only for an authorized user’s explicit action, following the wallet guide.

