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. For more details, see Payment methods.

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 the cancel of the authorize object. You can specify the amount for canceling the authorization. In this case, only this amount of the authorization 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 BigDecimal The reversal amount. If nothing is specified then the whole authorized amount is reversed.
Required: false
Default: null

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 ERRROR.

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