Cancel an authorization
Cancel the reserved amount for a payment.
OverviewOverview
Canceling an authorization releases the reserved money for the customer’s payment method. This is also called reversal. You can only perform the cancel
transaction on an existing authorization. This transaction is possible for selected payment methods only. Please check Payment methods page for details.
If you cancel an authorization, the total amount of the payment is reduced by the amount reversed.
Example
Reversal is triggered by calling payments/{codeororderid}/authorize/cancels
endpoint. You can cancel the authorization with an amount. In this case, only the specified authorization amount is released. If you do not specify an amount, the entire authorization is canceled.
Request
// full cancel on Authorization
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$authorization = $unzer->fetchAuthorization('s-pay-1');
$cancellation = $authorization->cancel();
// part cancel on Authorization
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$authorization = $unzer->fetchAuthorization('s-pay-1');
$cancellation = $authorization->cancel(50.0);
Cancellation of a Payment:
Some payment methods allow a cancellation directly on the payment resource without referring to a specific transaction:
// full cancel of Authorization
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$cancellation = $unzer->cancelAuthorizedPayment('s-pay-1');
// partial cancel of Authorization
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$cancellation = $unzer->cancelAuthorizedPayment('s-pay-1', new Cancellation(50.0));
paylater-invoice
.Arguments to Authorize::cancel
Parameter | Type | Description |
---|---|---|
amount | float | The amount to reduce the authorization by. The method will perform a full cancel of the authorization (and payment) if the amount is not set. |
Arguments to Unzer::cancelAuthorizedPayment
P3 only featurepaylater-invoice
.Parameter | Type | Description |
---|---|---|
payment (required) | Payment | string | The Payment object or the id of the Payment to be cancelled. |
cancellation | Cancellation | The Cancellation object. The method will perform a full cancel of the payment if cancellation left empty. |
Properties of Cancellation
The list below contains properties that are relevant for a cancellation transaction.
Parameter | Type | Description |
---|---|---|
amount | float | The amount to cancel. The method will perform a full cancel of the charge payment if the amount is not set. Required: false Default: null |
paymentReference | string | The reference string is show to the customer as reference text on their bank statement. Required: false Default: null |
Transaction Results
Transaction result descriptionThe transaction response is stored in the transaction object. It contains a paymentId
(for example, s-pay-1
) the transactionId
and other properties of the response. The transaction object provides getter functions to access those properties. For example, cancel.getPaymentId()
.
The parameters isSuccess
, isPending
, isError
indicate the result of the transaction. Only one of these three can be true.
If a transaction fails, the Unzer API will return an error resource instead of a transaction. In the SDK this is handled as an UnzerApiException
. Make sure to catch that case properly.
You can find an example for the transaction response on the Cancel an authorization (reversal) page.
try {
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$authorization= $unzer->fetchAuthorization($paymentId, $chargeId);
$cancellation = $authorization->cancel(100.0);
if ($cancelation->isSuccess) {
// Handle successful Cancelation
}
} catch (UnzerApiException $e) {
// Transaction failed. API returned error resource.
$this->log($e->getClientMessage());
$this->log($e->getMerchantMessage());
// Handle failed Cancelation
} catch (RuntimeException $e) {
$merchantMessage = $e->getMessage();
}