Pular para o conteúdo

Automatic & recurring payments

Create and manage Automatic Pix / Sweeping-style recurring payment requests. These four functions accept either LinaPayCredentials ({ subtenantId, subtenantSecret }, resolved through IAM) or TokenCredentials ({ access_token }, when you already hold a valid Bearer token) as their first argument.

Create a recurring payment request

import {
createAutomaticPaymentRequest,
type AutomaticPaymentRequestCreated,
} from '@lina-openx/web-lina-pay-sdk'

const created: AutomaticPaymentRequestCreated = await createAutomaticPaymentRequest(
{ subtenantId: 'your-subtenant-id', subtenantSecret: 'your-subtenant-secret' },
{
  redirectUrl: 'https://example.com/redirect',
  details: 'Monthly subscription',
  recurringConsent: {
    // exactly one of "automatic" or "sweeping"
    automatic: { /* ... */ },
  },
} as never,
)

console.log(created.paymentRequestId, created.redirectUrl)

Get a recurring payment request

import { getAutomaticPaymentRequest, type AutomaticPaymentRequest } from '@lina-openx/web-lina-pay-sdk'

const request: AutomaticPaymentRequest = await getAutomaticPaymentRequest(
credentials,
{ paymentRequestId: created.paymentRequestId },
)

console.log(request.consentStatus)

Cancel a single recurring payment

Only reachable through the automaticPayments namespace — there is no individual export.

import { automaticPayments } from '@lina-openx/web-lina-pay-sdk'

await automaticPayments.cancelAutomaticPayment(credentials, {
recurringPaymentId: 'recurring-payment-id',
subTenantId: 'lina',
cpfCancelledBy: '45684134866',
})

PATCH /automatic-payments/recurring-payments/{recurringPaymentId}, with a subTenantId header and { cpfCancelledBy } body. The response is the raw API body — no data/message/type envelope, unlike most other calls.

Cancels every future payment under the consent in one call:

import { automaticPayments } from '@lina-openx/web-lina-pay-sdk'

await automaticPayments.cancelAutomaticPaymentRequest(credentials, {
consentId: 'consent-id',
revocation: {
  revokedBy: 'requester-name',
  revokedFrom: 'PAYMENT_INITIATOR',
  revokedAt: new Date().toISOString(),
  reason: { code: 'CUSTOMER_REQUESTED', detail: 'Requested by the payer' },
},
})

PATCH /automatic-payments/recurring-consents/{consentId} — the SDK fixes status: 'REVOKED' internally, so revocation is the only field you provide.

Next steps