Cancel Payment
Cancel a payment where the status of the payment is ACT.
Relevant to payment methods where is_cancelable = true in the response to List Payment Methods by Country.
This method triggers the Payment Canceled Webhook. This webhook contains the same information as the response.
Note
If the
statusis CLO, use Create Refund.The code samples include successful requests (200) and bad requests (400).
For error messages that appear due to bad requests (400), see:
For information about unauthorized request (401) and other authentication errors, see Troubleshooting Authentication and Authorization Errors.
payment
ID of the payment. String starting with payment_.
Code Samples
.NET
using System; namespace RapydApiRequestSample { class Program { static void Main(string[] args) { try { string payment = "payment_84e75b8d03f7875463cb58d5a55db843"; string result = RapydApiRequestSample.Utilities.MakeRequest("DELETE", $"/v1/payments/{payment}"); Console.WriteLine(result); } catch (Exception e) { Console.WriteLine("Error completing request: " + e.Message); } } } }
JavaScript
const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest; async function main() { try { const result = await makeRequest( 'DELETE', '/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843' ); console.log(result); } catch (error) { console.error('Error completing request', error); } }
PHP
<?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/<path-to-your-utility-file>/utilities.php"; include($path); try { $object = make_request('delete', '/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843'); var_dump($object); } catch(Exception $e) { echo "Error: $e"; } ?>
Python
from pprint import pprint from utilities import make_request payment = "payment_84e75b8d03f7875463cb58d5a55db843" response = make_request(method='delete', path=f'/v1/payments/{payment}') pprint(response)
/v1/payments/:payment
Cancel Payment
curl -X delete 'https://sandboxapi.rapyd.net/v1/payments/payment_70277a0c2de53acb32916de664b2589e' \ -H 'access_key: your-access-key-here' \ -H 'Content-Type: application/json' \ -H 'salt: your-random-string-here' \ -H 'signature: your-calculated-signature-here' \ -H 'timestamp: your-unix-timestamp-here'
{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "e740d442-a0eb-4924-a438-24b11f6d2368" }, "data": { "id": "payment_70277a0c2de53acb32916de664b2589e", "amount": 0, "original_amount": 10, "is_partial": false, "currency_code": "EUR", "country_code": "GB", "status": "CAN", "description": "payment by card", "merchant_reference_id": "", "customer_token": "cus_4e25112ac20e144ad073a614dc46934b", "payment_method": "card_dd1c6cf0268d012188e73eb233064d56", "payment_method_data": { "cvv_check": "unchecked", "acs_check": "unchecked" }, "auth_code": null, "expiration": 1765272144, "captured": false, "refunded": false, "refunded_amount": 0, "receipt_email": "", "redirect_url": "", "complete_payment_url": "https://complete.rapyd.net", "error_payment_url": "https://error.rapyd.net", "receipt_number": "", "flow_type": "", "address": null, "statement_descriptor": "Doc Team", "transaction_id": "", "created_at": 1764667344, "metadata": {}, "failure_code": "", "failure_message": "", "paid": false, "paid_at": 0, "dispute": null, "refunds": null, "order": null, "outcome": null, "visual_codes": {}, "textual_codes": {}, "instructions": [], "ewallet_id": "ewallet_c1943cfeda5f98247ab117e5d2648861", "ewallets": [ { "ewallet_id": "ewallet_c1943cfeda5f98247ab117e5d2648861", "amount": 10, "percent": 100, "refunded_amount": 0 } ], "payment_method_options": {}, "payment_method_type": "gb_visa_card", "payment_method_type_category": "card", "fx_rate": 1, "merchant_requested_currency": null, "merchant_requested_amount": null, "fixed_side": "", "payment_fees": null, "invoice": "", "escrow": null, "group_payment": "", "cancel_reason": null, "initiation_type": "customer_present", "mid": "", "next_action": "not_applicable", "error_code": "", "remitter_information": {}, "save_payment_method": true, "merchant_advice_code": null, "merchant_advice_message": null, "transaction_link_id": null } }
Bad Request - Closed Payment
curl -X delete 'https://sandboxapi.rapyd.net/v1/payments/payment_eac0d2f27b85af17a018ec8b7ac2f504' \ -H 'access_key: your-access-key-here' \ -H 'Content-Type: application/json' \ -H 'salt: your-random-string-here' \ -H 'signature: your-calculated-signature-here' \ -H 'timestamp: your-unix-timestamp-here'
{ "status": { "error_code": "ERROR_PAYMENT_CAN_NOT_BE_CANCELED", "status": "ERROR", "message": "The request tried to cancel a payment, but the payment was already closed. The request was rejected. Corrective action: None. Determine why an attempt was made to cancel a closed payment.", "response_code": "ERROR_PAYMENT_CAN_NOT_BE_CANCELED", "operation_id": "06d87f28-957c-462b-891e-c3a45ca464d5" } }
Bad Request - Payment Not Found
curl -X delete 'https://sandboxapi.rapyd.net/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843' \ -H 'access_key: your-access-key-here' \ -H 'Content-Type: application/json' \ -H 'salt: your-random-string-here' \ -H 'signature: your-calculated-signature-here' \ -H 'timestamp: your-unix-timestamp-here'
{ "status": { "error_code": "ERROR_GET_PAYMENT", "status": "ERROR", "message": "The request tried to retrieve a payment, but the payment was not found. The request was rejected. Corrective action: Use a valid payment ID.", "response_code": "ERROR_GET_PAYMENT", "operation_id": "74bf0a50-4925-403f-8164-b545dcedbd30" } }