Skip to main content
The ApiCardPreAuthorizations class provides methods to create and manage card pre-authorizations, which reserve funds on a card without immediately capturing them.

Methods

Create

Create a new pre-authorization.
public function Create($cardPreAuthorization, $idempotencyKey = null)
cardPreAuthorization
\MangoPay\CardPreAuthorization
required
The CardPreAuthorization object to create
idempotencyKey
string
Optional idempotency key for safe retries
Returns: \MangoPay\CardPreAuthorization - The created CardPreAuthorization object Example:
$preAuth = new \MangoPay\CardPreAuthorization();
$preAuth->AuthorId = $userId;
$preAuth->DebitedFunds = new \MangoPay\Money();
$preAuth->DebitedFunds->Currency = 'EUR';
$preAuth->DebitedFunds->Amount = 5000;
$preAuth->CardId = 'card_123456';
$preAuth->SecureMode = 'DEFAULT';
$preAuth->SecureModeReturnURL = 'https://example.com/return';

$result = $api->CardPreAuthorizations->Create($preAuth);

Get

Get a pre-authorization by its ID.
public function Get($cardPreAuthorizationId)
cardPreAuthorizationId
string
required
The unique identifier of the pre-authorization
Returns: \MangoPay\CardPreAuthorization - The CardPreAuthorization object Example:
$preAuth = $api->CardPreAuthorizations->Get('preauth_123456');

Update

Update a pre-authorization (typically to cancel it or adjust the payment status).
public function Update($cardPreAuthorization)
cardPreAuthorization
\MangoPay\CardPreAuthorization
required
The CardPreAuthorization object to update (must include Id)
Returns: \MangoPay\CardPreAuthorization - The updated CardPreAuthorization object Example:
$preAuth = $api->CardPreAuthorizations->Get('preauth_123456');
$preAuth->PaymentStatus = 'CANCELED';

$result = $api->CardPreAuthorizations->Update($preAuth);

GetTransactions

Get all transactions (pay-ins) associated with a pre-authorization.
public function GetTransactions($cardPreAuthorizationId, & $pagination = null, $filter = null, $sorting = null)
cardPreAuthorizationId
string
required
The ID of the pre-authorization
pagination
\MangoPay\Pagination
Pagination object (passed by reference)
filter
\MangoPay\FilterTransactions
Filtering options
sorting
\MangoPay\Sorting
Sorting options
Returns: \MangoPay\Transaction[] - Array of Transaction objects Example:
$pagination = new \MangoPay\Pagination();
$transactions = $api->CardPreAuthorizations->GetTransactions('preauth_123456', $pagination);

CardPreAuthorization Entity

The CardPreAuthorization entity represents a reservation of funds on a payment card.

Properties

Id
string
The unique identifier of the pre-authorization
CreationDate
int
Unix timestamp of when the pre-authorization was created
Tag
string
Custom data for your use
AuthorId
string
required
The user ID of the pre-authorization author
DebitedFunds
\MangoPay\Money
required
The amount to pre-authorize on the card
Status
string
The status of the pre-authorization: CREATED, SUCCEEDED, FAILED
PaymentStatus
string
The payment status: WAITING, CANCELED, EXPIRED, VALIDATED
ResultCode
string
The result code of the pre-authorization
ResultMessage
string
The result message explaining the result code
StatementDescriptor
string
A description that appears on the bank statement
ExecutionType
string
How the pre-authorization is executed (always CARD)
SecureMode
string
required
The 3D Secure mode: DEFAULT, FORCE, NO_CHOICE
CardId
string
required
The ID of the registered card to use
SecureModeNeeded
bool
Whether 3D Secure validation was required
SecureModeRedirectURL
string
The URL to redirect users to for 3D Secure validation
SecureModeReturnURL
string
required
The URL where users are redirected after 3D Secure validation
ExpirationDate
int
Unix timestamp when the pre-authorization expires (typically 30 days)
AuthorizationDate
int
Unix timestamp when the pre-authorization was authorized
PaymentType
string
The type of payment (always CARD)
PayInId
string
The ID of the associated pay-in (if captured)
Billing
\MangoPay\Billing
Billing information for the transaction
SecurityInfo
\MangoPay\SecurityInfo
Security validation information
MultiCapture
bool
Whether multiple captures are allowed for this pre-authorization
RemainingFunds
\MangoPay\Money
The remaining funds available for capture
IpAddress
string
The IP address of the user
BrowserInfo
\MangoPay\BrowserInfo
Browser information for 3DS2
Shipping
\MangoPay\Shipping
Shipping information
Requested3DSVersion
string
The requested 3D Secure version
Applied3DSVersion
string
The 3D Secure version that was applied
CardInfo
object
Information about the card used
PaymentCategory
string
The payment category: ECommerce (default), TelephoneOrder
AuthenticationResult
\MangoPay\AuthenticationResult
3DS authentication result

Usage Examples

Create a Pre-Authorization

$preAuth = new \MangoPay\CardPreAuthorization();
$preAuth->AuthorId = $userId;
$preAuth->DebitedFunds = new \MangoPay\Money();
$preAuth->DebitedFunds->Currency = 'EUR';
$preAuth->DebitedFunds->Amount = 5000; // €50.00
$preAuth->CardId = 'card_123456';
$preAuth->SecureMode = 'DEFAULT';
$preAuth->SecureModeReturnURL = 'https://example.com/return';
$preAuth->IpAddress = $_SERVER['REMOTE_ADDR'];

$result = $api->CardPreAuthorizations->Create($preAuth);

if ($result->SecureModeNeeded) {
    // Redirect user to 3DS page
    header('Location: ' . $result->SecureModeRedirectURL);
    exit;
}

Capture Pre-Authorized Funds

// Create a pre-authorized pay-in to capture funds
$payIn = new \MangoPay\PayIn();
$payIn->AuthorId = $userId;
$payIn->CreditedWalletId = $walletId;
$payIn->DebitedFunds = new \MangoPay\Money();
$payIn->DebitedFunds->Currency = 'EUR';
$payIn->DebitedFunds->Amount = 5000;
$payIn->Fees = new \MangoPay\Money();
$payIn->Fees->Currency = 'EUR';
$payIn->Fees->Amount = 100;

$payIn->PaymentType = 'PREAUTHORIZED';
$payIn->ExecutionType = 'DIRECT';

$paymentDetails = new \MangoPay\PayInPaymentDetailsPreAuthorized();
$paymentDetails->PreauthorizationId = 'preauth_123456';
$payIn->PaymentDetails = $paymentDetails;

$executionDetails = new \MangoPay\PayInExecutionDetailsDirect();
$payIn->ExecutionDetails = $executionDetails;

$result = $api->PayIns->Create($payIn);

Cancel a Pre-Authorization

$preAuth = $api->CardPreAuthorizations->Get('preauth_123456');
$preAuth->PaymentStatus = 'CANCELED';

$result = $api->CardPreAuthorizations->Update($preAuth);

if ($result->PaymentStatus === 'CANCELED') {
    echo "Pre-authorization canceled successfully";
}
Pre-authorizations typically expire after 30 days. Make sure to capture the funds before the expiration date.
The full pre-authorized amount is reserved on the user’s card. If you capture a smaller amount, the remaining funds will be released automatically.

Build docs developers (and LLMs) love