Pular para o conteúdo

Execute a JSR payment

Every JSR payment flow — Pay a QR Code, Pix transfer by key, and Instant Pix (JSR) — ends the same way: gate on the enrollment, open a consent, sign on the device, then execute with payments.processJsr. This page covers that shared mechanics once. Each flow page above documents only what's specific to it — decoding a QR Code, resolving a Pix key, or building a transfer payload — then links back here to finish.

Method sequence

  1. enrollments.listByUserJsr(cpf, { deviceId }) — gate: confirm the payer has an AUTHORISED enrollment and pick it.
  2. (flow-specific) build the payload and call consents.createJsr(req). Returns { id, consentId, fidoSignOptions }; id is the paymentRequestId. See Pay a QR Code, Pix transfer by key, or Instant Pix (JSR) for this step.
  3. [device] the device calls navigator.credentials.get() with consent.fidoSignOptions and produces a FIDO2 assertion.
  4. payments.processJsr(req) — submit the assertion plus riskSignals to execute the payment. Check the result with the isPaid helper.

Sequence diagram

Execute a JSR payment — gate on the enrollment, sign on device, execute (consent creation is flow-specific)

Code

Continuing from a consent already created by one of the flow pages — consent.id is the paymentRequestId. Both consents.createJsr and payments.processJsr require the clientIp (the X-Client-IP header).

import { isPaid } from '@linainfratech/embedded-payments';

// 1) Gate: an AUTHORISED enrollment is required
const user = await client.enrollments.listByUserJsr(cpf, { deviceId: riskSignals.deviceId });
const enrollment = user.enrollments[0];

// 2) Build the consent — flow-specific, see Pay a QR Code / Pix transfer / Instant Pix (JSR)
// const consent = await client.consents.createJsr({ ... }, { clientIp });

// 3) [device] navigator.credentials.get(consent.fidoSignOptions) -> assertion

// 4) Execute the payment
const result = await client.payments.processJsr({
enrollmentId: enrollment.enrollmentId,
paymentRequestId: consent.id,
riskSignals,
fidoAssertion: assertion,
}, { clientIp });

console.log(isPaid(result) ? 'Paid' : result.status);

Next steps