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
enrollments.listByUserJsr(cpf, { deviceId })— gate: confirm the payer has anAUTHORISEDenrollment and pick it.- (flow-specific) build the payload and call
consents.createJsr(req). Returns{ id, consentId, fidoSignOptions };idis thepaymentRequestId. See Pay a QR Code, Pix transfer by key, or Instant Pix (JSR) for this step. - [device] the device calls
navigator.credentials.get()withconsent.fidoSignOptionsand produces a FIDO2 assertion. payments.processJsr(req)— submit theassertionplusriskSignalsto execute the payment. Check the result with theisPaidhelper.
Sequence diagram
Carregando diagrama…
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);// 1) Gate: an AUTHORISED enrollment is required
UserEnrollments user = client.enrollments.listByUserJsr(cpf, ListEnrollmentsQuery.deviceId(deviceId));
EnrollmentSummary enrollment = user.enrollments().get(0);
// 2) Build the consent — flow-specific, see Pay a QR Code / Pix transfer / Instant Pix (JSR)
// JsrConsentResult consent = client.consents.createJsr(..., CallOptions.clientIp(ip));
// 3) [device] produce the FIDO2 assertion from consent.fidoSignOptions()
// 4) Execute the payment
PaymentResult result = client.payments.processJsr(
new ProcessJsrPaymentRequest()
.enrollmentId(enrollment.enrollmentId())
.paymentRequestId(consent.id())
.riskSignals(risk)
.fidoAssertion(assertion),
CallOptions.clientIp(ip));
System.out.println(Helpers.isPaid(result) ? "Paid" : result.status());// 1) Gate: an AUTHORISED enrollment is required
let user = try await client.enrollments.listByUserJsr(cpf, query: ListEnrollmentsQuery(deviceId: deviceId))
guard let enrollment = user.enrollments.first else { return }
// 2) Build the consent — flow-specific, see Pay a QR Code / Pix transfer / Instant Pix (JSR)
// let consent = try await client.consents.createJsr(..., options: .clientIp(ip))
// 3) [device] produce the FIDO2 assertion from consent.fidoSignOptions
// 4) Execute the payment
let result = try await client.payments.processJsr(
ProcessJsrPaymentRequest(
enrollmentId: enrollment.enrollmentId,
paymentRequestId: consent.id,
riskSignals: risk,
fidoAssertion: assertion),
options: .clientIp(ip))
print(Helpers.isPaid(result) ? "Paid" : result.status)// 1) Gate: an AUTHORISED enrollment is required
var user = await client.Enrollments.ListByUserJsrAsync(cpf, new ListEnrollmentsQuery { DeviceId = deviceId });
var enrollment = user.Enrollments[0];
// 2) Build the consent — flow-specific, see Pay a QR Code / Pix transfer / Instant Pix (JSR)
// var consent = await client.Consents.CreateJsrAsync(..., CallOptions.WithClientIp(ip));
// 3) [device] produce the FIDO2 assertion from consent.FidoSignOptions
// 4) Execute the payment
var result = await client.Payments.ProcessJsrAsync(new ProcessJsrPaymentRequest
{
EnrollmentId = enrollment.EnrollmentId,
PaymentRequestId = consent.Id,
RiskSignals = risk,
FidoAssertion = assertion,
}, CallOptions.WithClientIp(ip));
Console.WriteLine(Helpers.IsPaid(result) ? "Paid" : result.Status);Next steps
- Pay a QR Code — build the consent from a scanned QR Code.
- Pix transfer by key — build the consent from a Pix key lookup.
- Instant Pix (JSR) — build the consent from receiver data directly.
- Error handling — classify
DependencyError,BadRequestError, and more.