Pular para o conteúdo

Pay with an enrollment

Once a device enrollment is AUTHORISED, pay without redirecting the payer to their bank — createPaymentWithEnrollment internally creates the consent, requests FIDO2 sign options, prompts the device for biometrics, signs, and authorizes the payment in a single call.

import {
createPaymentWithEnrollment,
type PaymentWithEnrollmentRequest,
LinaPayError,
} from 'react-native-lina-pay-sdk'
import { Platform } from 'react-native'

async function payWithEnrollment(enrollmentId: string) {
try {
  const platform = Platform.OS === 'ios' ? 'IOS' : Platform.OS === 'android' ? 'ANDROID' : 'WEB'

  const payment = await createPaymentWithEnrollment(
    { subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
    {
      enrollmentId,
      organisationId: 'org-uuid',
      authorisationServerId: 'auth-uuid',
      payment: {
        value: 1500.5,
        details: 'Service payment',
        externalId: 'payment-123',
        redirectUri: 'https://your-app.com/payment-success',
        cpfCnpj: '12345678901',
        creditor: {
          name: 'Beneficiary Company',
          personType: 'PESSOA_JURIDICA',
          cpfCnpj: '12345678000190',
          accountNumber: '123456',
          accountIssuer: '0001',
          accountPixKey: 'company@example.com',
          accountIspb: '12345678',
          accountType: 'CACC',
        },
        txId: [],
      },
      fidoSignOptions: {
        rp: 'app.linaopenx.com.br',
        platform,
      },
    },
  )

  console.log(payment.id, payment.consentId)
  // The payer is prompted for biometrics automatically during this call
} catch (error) {
  if (error instanceof LinaPayError) console.error('Error processing payment:', error.message)
}
}

Next steps