Skip to main content
All response types are imported from the @vtex/payment-provider package and represent your connector’s responses to VTEX’s Payment Gateway.

AuthorizationResponse

Response returned from the authorize() method. Use the helper methods from the Authorizations namespace to construct responses.
paymentId
string
required
Unique identifier for the payment (from the request)
status
string
required
Payment status
tid
string
Transaction identifier from your payment provider
authorizationId
string
Authorization identifier for approved payments (required when status is approved)
nsu
string
Unique sequential number from your payment provider
code
string
Response code from your payment provider
message
string
Human-readable message about the transaction result
delayToCancel
number
Time in milliseconds before automatic cancellation (for pending payments)
paymentUrl
string
Payment URL for bank invoice flows
redirectUrl
string
Redirect URL for redirect-based payment flows
delayToAutoSettle
number
Time in milliseconds before automatic settlement
delayToAutoSettleAfterAntifraud
number
Time in milliseconds before auto-settlement after antifraud check

Helper methods

Use the Authorizations namespace to construct properly formatted responses:
import { Authorizations } from '@vtex/payment-provider'

return Authorizations.approve(request, {
  authorizationId: 'auth_123456',
  nsu: 'nsu_789012',
  tid: 'tid_345678'
})
Returns status approved with the provided identifiers.
When returning a pending response, you must use the callback() method to send the final authorization result asynchronously.

CancellationResponse

Response returned from the cancel() method.
paymentId
string
required
Unique identifier for the payment (from the request)
cancellationId
string
Cancellation identifier from your payment provider (required for approved cancellations)
code
string
Response code from your payment provider
message
string
Human-readable message about the cancellation result
requestId
string
required
Request identifier (from the request)

Helper methods

import { Cancellations } from '@vtex/payment-provider'

return Cancellations.approve(request, {
  cancellationId: 'cancel_123456'
})

RefundResponse

Response returned from the refund() method.
paymentId
string
required
Unique identifier for the payment (from the request)
refundId
string
Refund identifier from your payment provider (required for approved refunds)
code
string
Response code from your payment provider
message
string
Human-readable message about the refund result
requestId
string
required
Request identifier (from the request)
value
number
Actual refunded amount in cents (may differ from requested amount)

Helper methods

import { Refunds } from '@vtex/payment-provider'

return Refunds.approve(request, {
  refundId: 'refund_123456',
  value: request.value
})

SettlementResponse

Response returned from the settle() method.
paymentId
string
required
Unique identifier for the payment (from the request)
settleId
string
Settlement identifier from your payment provider (required for approved settlements)
code
string
Response code from your payment provider
message
string
Human-readable message about the settlement result
requestId
string
required
Request identifier (from the request)
value
number
Actual settled amount in cents (may differ from requested amount)

Helper methods

import { Settlements } from '@vtex/payment-provider'

return Settlements.approve(request, {
  settleId: 'settle_123456',
  value: request.value
})

Common patterns

Using the callback for async operations

For pending authorizations, use the callback mechanism to send the final result:
public async authorize(
  authorization: AuthorizationRequest
): Promise<AuthorizationResponse> {
  // Start async processing
  this.processAsync(authorization).then(result => {
    const response = result.approved
      ? Authorizations.approve(authorization, {
          authorizationId: result.id,
          tid: result.transactionId
        })
      : Authorizations.deny(authorization, {
          tid: result.transactionId,
          message: result.errorMessage
        })
    
    // Send result via callback
    this.callback(authorization, response)
  })
  
  // Return pending status immediately
  return Authorizations.pending(authorization, {
    tid: generateTid(),
    delayToCancel: 300000
  })
}

Error handling

Always handle errors gracefully and return proper denial responses:
public async authorize(
  authorization: AuthorizationRequest
): Promise<AuthorizationResponse> {
  try {
    const result = await this.provider.authorize(authorization)
    
    return Authorizations.approve(authorization, {
      authorizationId: result.id,
      tid: result.tid,
      nsu: result.nsu
    })
  } catch (error) {
    return Authorizations.deny(authorization, {
      tid: generateTid(),
      code: error.code,
      message: error.message
    })
  }
}
Never throw errors from payment methods. Always return a properly formatted denial response when operations fail.

Partial settlements and refunds

You can settle or refund partial amounts:
public async settle(
  settlement: SettlementRequest
): Promise<SettlementResponse> {
  // Settle only 80% of authorized amount
  const partialAmount = Math.floor(settlement.value * 0.8)
  
  const result = await this.provider.capture({
    authorizationId: settlement.authorizationId,
    amount: partialAmount
  })
  
  return Settlements.approve(settlement, {
    settleId: result.id,
    value: partialAmount // Return actual settled amount
  })
}

Build docs developers (and LLMs) love