{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars/sdk_sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["code-group"]},"type":"markdown"},"seo":{"title":"Cancelling a transaction","description":"The specifications of Ratepay's APIs for easy payment transactions.","siteUrl":"https://docs.ratepay.com","keywords":"Ratepay developer portal, Ratepay api portal, Ratepay api reference docs","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"cancelling-a-transaction","__idx":0},"children":["Cancelling a transaction"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["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."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For more information, see the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://docs.ratepay.com/docs/developer/api_integration/payment_2.0/payment_api_2.0"},"children":["Payment API 2.0 documentation"]},"."]},{"$$mdtype":"Tag","name":"CodeGroup","attributes":{"mode":"tabs"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"java","data-title":"Java","header":{"title":"Java","controls":{"copy":{}}},"source":"import com.ratepay.sdk.CancellationOutcome;\nimport com.ratepay.sdk.model.api.payment.CancellationRequest;\nimport java.math.BigDecimal;\n\nCancellationRequest request = new CancellationRequest(\n    new BigDecimal(\"249.00\"), // grossAmount, cancelling the full remaining authorization\n    null, // items\n    null, // partnerOperationId\n    null, // partnerShopId\n    null, // specialItems\n    null  // vats\n);\n\nCancellationOutcome outcome = client.cancel(ratepayTransactionId, request, null);\n\nif (outcome.kind() == CancellationOutcome.Kind.ACCEPTED) {\n    var accepted = (CancellationOutcome.Accepted) outcome;\n    System.out.println(\"Cancelled: \" + accepted.getRatepayCancellationId());\n} else {\n    var declined = (CancellationOutcome.Declined) outcome;\n    System.out.println(\"Cancellation declined: \" + declined.getDecline().getCategory());\n}\n","lang":"java"},"children":[]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"kotlin","data-title":"Kotlin","header":{"title":"Kotlin","controls":{"copy":{}}},"source":"import com.ratepay.sdk.CancellationOutcome\nimport com.ratepay.sdk.model.api.payment.CancellationRequest\nimport java.math.BigDecimal\n\nval request = CancellationRequest(grossAmount = BigDecimal(\"249.00\"))\n\nwhen (val outcome = client.cancel(ratepayTransactionId, request)) {\n    is CancellationOutcome.Accepted -> println(\"Cancelled: ${outcome.ratepayCancellationId}\")\n    is CancellationOutcome.Declined -> println(\"Cancellation declined: ${outcome.decline.category}\")\n}\n","lang":"kotlin"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A cancellation may be declined if the requested amount exceeds the remaining authorized amount. Check ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Declined.decline.reasons"]}," for ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["CANCELLATION_AMOUNT_TOO_HIGH"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Declined.decline.category"]}," for the broader decline category."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"exceptions","__idx":1},"children":["Exceptions"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Exception"},"children":["Exception"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"HTTP Status Code"},"children":["HTTP Status Code"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["RatepayAuthException"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["401/403"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["RatepayValidationException"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["400"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["RatepayTransactionNotFoundException"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["404"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["RatepayLegalException"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["451"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["RatepayNetworkException"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["5xx/transport"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"next","__idx":2},"children":["Next"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"/docs/developer/sdk/guides/refunding-a-transaction"},"children":["Refunding amounts that have already been captured."]},"."]}]}]},"headings":[{"value":"Cancelling a transaction","id":"cancelling-a-transaction","depth":1},{"value":"Exceptions","id":"exceptions","depth":2},{"value":"Next","id":"next","depth":2}],"frontmatter":{"seo":{"title":"Cancelling a transaction"}},"lastModified":"2026-11-03T16:38:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/docs/developer/sdk/guides/cancelling-a-transaction","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}