Pular para o conteúdo

Enrollments

An enrollment registers the payer's device with a FIDO2/Passkey. Once authorised, the payer can pay again without leaving the app or being redirected to their bank — see Pay with an enrollment.

1. Create an enrollment

import { createEnrollment, type CreateEnrollmentRequest, LinaPayError } from 'react-native-lina-pay-sdk'
import { Linking } from 'react-native'

async function createDeviceEnrollment(selected: Participant) {
try {
  const enrollment = await createEnrollment(
    { subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
    {
      organisationId: selected.organisationId,
      authorisationServerId: selected.authorisationServerId,
      enrollment: {
        document: '12345678901', // payer's CPF
        deviceName: "Jane's iPhone",
        debtor: {
          accountNumber: '123456',
          accountIssuer: '0001',
          accountIspb: '12345678',
          accountType: 'CACC',
        },
      },
      redirectUri: 'https://your-app.com/enrollment-callback',
    },
  )

  if (enrollment.redirectUrl) Linking.openURL(enrollment.redirectUrl)
} catch (error) {
  if (error instanceof LinaPayError) console.error('Error creating enrollment:', error.message)
}
}

2. Register the device (after the callback)

Once the payer authorizes at their bank and the redirect delivers state/code/idToken back to your app, complete the FIDO2 registration:

import { registerDevice, LinaPayError } from 'react-native-lina-pay-sdk'
import { Platform } from 'react-native'

async function registerDeviceAfterCallback(state: string, code: string, idToken: string) {
try {
  const platform = Platform.OS === 'ios' ? 'IOS' : Platform.OS === 'android' ? 'ANDROID' : 'WEB'

  const enrollment = await registerDevice(
    { subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
    { state, code, idToken, tenantId: 'your-subtenant-id', platform },
  )

  console.log(enrollment.enrollmentId, enrollment.status) // AUTHORISED once ready
} catch (error) {
  if (error instanceof LinaPayError) console.error('Error registering device:', error.message)
}
}

platform accepts 'ANDROID' | 'IOS' | 'WEB' | 'BROWSER' | 'CROSS_PLATFORM'.

List and revoke enrollments

import { getEnrollmentList, revokeEnrollment, LinaPayError } from 'react-native-lina-pay-sdk'

async function listUserEnrollments(cpf: string) {
try {
  const { enrollments } = await getEnrollmentList(
    { subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
    cpf,
  )

  enrollments.forEach((e) => console.log(e.enrollmentId, e.status))
} catch (error) {
  if (error instanceof LinaPayError) console.error('Error listing enrollments:', error.message)
}
}

async function removeEnrollment(enrollmentId: string) {
await revokeEnrollment(
  { subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
  enrollmentId,
)
}

Next steps