alt

Important information

There was an update of Unzer TLS/SSL certificates. Learn more

Unzer

Cancel an authorization

Cancel the reserved amount for a payment.

Overview

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.

icon info
Total amount
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 unzer = new Unzer('s-priv-xxxxxxxxxx');
Authorization authorization = unzer.fetchAuthorization('s-pay-1');
Cancel cancellation = authorization.cancel();
// full cancel on Authorization
Unzer unzer = new Unzer('s-priv-xxxxxxxxxx');
Authorization authorization = unzer.fetchAuthorization('s-pay-1');
Cancel cancellation = authorization.cancel(BigDecimal.valueOf(50.0));

Arguments to Authorize::cancel

Parameter Type Description
amount
(required)
float The reversal amount. If nothing is specified then the whole authorized amount is reversed.

Transaction Results

The 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 status-parameter indicate the result of the transaction. The Enum can only be SUCCESS, PENDING or ERROR.

If a transaction fails, the payment API returns an error resource instead of a transaction. In the SDK this is handled as an UnzerPaymentException. 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 unzer = new Unzer('s-priv-xxxxxxxxxx');
    Authorization authorization = unzer.fetchAuthorization('s-pay-1');
    Cancel cancellation = authorization.cancel(BigDecimal.valueOf(100.0));

    if (authorization.Status.equals(Cancel.Status.SUCCESS)) {
        this.redirectToSuccess();
    }
} catch (HttpCommunicationException | PaymentException e) {
    // Transaction failed. API returned error resource.
    List<PaymentError> paymentErrorList = e.getPaymentErrorList();
    //Handle API Errors
    
    this.redirectToFailure(); // redirect to the failure page of your shop
} catch (Exception e) {
    merchantMessage = e.getMessage();
}

See also