Learn how to cancel an existing Payment Request to prevent further processing. This operation transitions the Payment Request to the CANCELED state, which is a final state from which no further actions can be taken.
90 min read
Introduction
Cancel an existing Payment Request to prevent further processing. This operation transitions the Payment Request to the CANCELED state, which is a final state from which no further actions can be taken.
Proactive cancellation recommended
Klarna recommends proactively canceling Payment Requests that have not resulted in successful transactions, especially if the Partner's checkout timeout is shorter than the Payment Request lifetime. By default, a Payment Request remains open for 3 hours and will automatically expire if not completed or explicitly canceled. You can override this default with the custom Payment Request expiry feature.
Prerequisites
Before canceling a Payment Request, ensure the following:
A valid Partner Account with API credentials
Backend capability to receive and process Klarna webhooks
An existing Payment Request that can be canceled
The payment_request_id of the Payment Request to cancel
Cancelable states
Payment Requests can be canceled while in SUBMITTED, IN_PROGRESS, or COMPLETED state. A COMPLETED Payment Request can be canceled only until the Payment Authorization is finalized. See Cancel a completed Payment Request. Payment Requests in EXPIRED or DECLINED state can't be canceled.
Request
Call cancelPaymentRequest with the payment_request_id to cancel the Payment Request. This is a DELETE operation with no request body.
Subscribe to the payment.request.state-change.canceled webhook event using the guidelines provided here. Klarna sends this event when a Payment Request is successfully canceled.
A Payment Request in COMPLETED state can be canceled with cancelPaymentRequest as long as the Payment Authorization hasn't been finalized, meaning no Payment Transaction has been created from it. This lets the Acquiring Partner stop a purchase after the customer completes the Klarna Purchase Journey, for example when the Acquiring Partner's own checks fail before the payment is authorized.
The Payment Authorization is finalized once the Klarna Network Session Token issued for the Payment Request is used to create a Payment Transaction. Until then, the Payment Request can be canceled, even if the Klarna Network Session Token has expired without being used.
The result depends on the Payment Request:
Payment Request
Result
COMPLETED, Payment Authorization not finalized
200 OK. The Payment Request moves to CANCELED with state_reasonPARTNER_CANCELED. Klarna sends a payment.request.state-change.canceled webhook with previous_stateCOMPLETED.
COMPLETED, Payment Authorization finalized (a Payment Transaction was created)
409 Conflict with error_codeRESOURCE_CONFLICT and the message The payment authorization has been finalized and the payment request can no longer be canceled. To reverse the payment, call voidPaymentTransaction or refundPaymentTransaction on the Payment Transaction instead.
COMPLETED tokenization-only request (no amount; a Customer Token was created)
409 Conflict with the message Tokenization-only payment requests can not be canceled after the customer token is created. This applies only to Payment Requests without an amount. A COMPLETED Payment Request with a one-time charge and a Customer Token is handled like any other COMPLETED Payment Request: it can be canceled until its Payment Authorization is finalized.
Already CANCELED
200 OK with the canceled Payment Request. The call is idempotent, and Klarna doesn't send a second webhook.
DECLINED
409 Conflict with error_codeRESOURCE_CONFLICT and the message Operation is not valid for the state: DECLINED.
Past expires_at, including EXPIRED
404 Not Found.
After the cancellation
Klarna cancels the Klarna Network Session Token issued for the Payment Request:
If the Acquiring Partner calls authorizePayment with this Klarna Network Session Token and includes step_up_config, Klarna returns STEP_UP_REQUIRED with result_reasonKLARNA_NETWORK_SESSION_TOKEN_NOT_FOUND. Without step_up_config, Klarna returns DECLINED.
Calling readPaymentRequest for the canceled Payment Request returns 404 Not Found.
Customer Token not affected
Canceling a Payment Request doesn't revoke a Customer Token. The Customer Token stays valid.
Use cases
Cancel Payment Requests in various scenarios to maintain accurate payment tracking and free up resources. Common scenarios include abandoned checkouts, checkout timeouts, and error recovery.
Abandoned checkout
Cancel the Payment Request when the customer abandons the checkout flow.
Proactively cancel Payment Requests when the Partner's checkout times out to avoid unnecessary open requests.
Align expiry with session timeout
Consider using the custom Payment Request expiry feature in authorizePayment (step_up_config.customer_interaction_config.interaction_expiry) to align Payment Request expiration times with the Partner's checkout timeout. This reduces the need for manual cancellation when the Partner's checkout times out.
Implement automatic cancellation for Payment Requests that haven't completed within your expected timeframe. This helps:
Reduce unnecessary open Payment Requests
Improve Payment Request tracking and reporting
Free up system resources
Maintain clean Payment Request state
Webhook integration
Subscribe to the payment.request.state-change.canceled webhook to be notified when Payment Requests are canceled, whether by your system or by Klarna (due to expiration or other reasons).
Error handling
Implement proper error handling for cancellation failures:
Handle 409 Conflict errors for Payment Requests that can't be canceled: DECLINED Payment Requests, and COMPLETED Payment Requests whose Payment Authorization was finalized, or that were tokenization-only (no amount) and created a Customer Token
Handle 404 Not Found errors for Payment Requests past expires_at, including EXPIRED ones
Retry with exponential backoff for temporary failures
Log cancellation attempts for debugging and auditing