# Cancelling a transaction Cancel all or part of an authorized payment that has not yet been captured, such as when an item is removed from an order before shipment. Cancellations can be full or partial, and multiple cancellations can be made against the same transaction, provided the total cancelled amount does not exceed the remaining authorized amount. For more information, see the [Payment API 2.0 documentation](https://docs.ratepay.com/docs/developer/api_integration/payment_2.0/payment_api_2.0). ```java Java import com.ratepay.sdk.CancellationOutcome; import com.ratepay.sdk.model.api.payment.CancellationRequest; import java.math.BigDecimal; CancellationRequest request = new CancellationRequest( new BigDecimal("249.00"), // grossAmount, cancelling the full remaining authorization null, // items null, // partnerOperationId null, // partnerShopId null, // specialItems null // vats ); CancellationOutcome outcome = client.cancel(ratepayTransactionId, request, null); if (outcome.kind() == CancellationOutcome.Kind.ACCEPTED) { var accepted = (CancellationOutcome.Accepted) outcome; System.out.println("Cancelled: " + accepted.getRatepayCancellationId()); } else { var declined = (CancellationOutcome.Declined) outcome; System.out.println("Cancellation declined: " + declined.getDecline().getCategory()); } ``` ```kotlin Kotlin import com.ratepay.sdk.CancellationOutcome import com.ratepay.sdk.model.api.payment.CancellationRequest import java.math.BigDecimal val request = CancellationRequest(grossAmount = BigDecimal("249.00")) when (val outcome = client.cancel(ratepayTransactionId, request)) { is CancellationOutcome.Accepted -> println("Cancelled: ${outcome.ratepayCancellationId}") is CancellationOutcome.Declined -> println("Cancellation declined: ${outcome.decline.category}") } ``` A cancellation may be declined if the requested amount exceeds the remaining authorized amount. Check `Declined.decline.reasons` for `CANCELLATION_AMOUNT_TOO_HIGH` and `Declined.decline.category` for the broader decline category. ## Exceptions | Exception | HTTP Status Code | | --- | --- | | `RatepayAuthException` | 401/403 | | `RatepayValidationException` | 400 | | `RatepayTransactionNotFoundException` | 404 | | `RatepayLegalException` | 451 | | `RatepayNetworkException` | 5xx/transport | ## Next - [Refunding amounts that have already been captured.](/docs/developer/sdk/guides/refunding-a-transaction).