Cancel a payment
Find out how to cancel a payment intent that hasn't yet been authorized.
Payment intents can be canceled if they are no longer needed — for instance, if the card issuer declines authorization. Note that cancellation is only possible while the intent is in the Created status
Cancel using the Dojo API
To cancel a payment to your customer, use the endpoint below:
DELETE /payment-intents/{paymentIntentId}
In your request, include:
paymentIntentId: identifies the payment being canceled.
For the full specification, see the API reference.
Request example
The next example shows how to cancel a payment intent.
- cURL
- PowerShell
- Python
- C#
- PHP
# The sandbox API key passed in 'authorization' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
curl -v --request DELETE \
--url https://api.dojo.tech/payment-intents/<paymentIntentId> \
--header 'Authorization: Basic <your_api_key>' \
--header 'Version: 2024-02-05'
# The sandbox API key passed in '$publicSandboxKey' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
$publicSandboxKey = "sk_sandbox_c8oLGaI__msxsXbpBDpdtwJEz_eIhfQoKHmedqgZPCdBx59zpKZLSk8OPLT0cZolbeuYJSBvzDVVsYvtpo5RkQ"
# Replace <payment_intent_id> with ID of payment intent you want to cancel.
Invoke-WebRequest `
-Uri 'https://api.dojo.tech/payment-intents/<paymentIntentId>' `
-Method DELETE `
-Headers @{
"Version" = "2024-02-05"
"Authorization" = "Basic $publicSandboxKey"
}
# The sandbox API key passed in 'authorization' is public.
# Don't submit any personally identifiable information in any requests made with this key.
# Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
# for secure testing.
import http.client
conn = http.client.HTTPSConnection("api.dojo.tech")
headers = {
'Version': "2024-02-05",
'Authorization': "Basic <your_api_key>"
}
conn.request("DELETE", f"/payment-intents/{paymentIntentId}", headers=headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
conn.close()
// The sandbox API key passed in 'ApiKeyClientAuthorization' is public.
// Don't submit any personally identifiable information in any requests made with this key.
// Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
// for secure testing.
var paymentIntentsClient = new PaymentIntentsClient(new HttpClient(), new ApiKeyClientAuthorization("<your_api_key>"));
var result = await paymentIntentsClient.DeleteAsync("<paymentIntentId>");
<?php
// The sandbox API key used in this example is public.
// Don't submit any personally identifiable information in any requests made with this key.
// Sign in to developer.dojo.tech to create your own private sandbox key and use that instead
// for secure testing.
namespace Test;
require_once "vendor/autoload.php";
use Dojo_PHP\ApiFactory;
$apiKey = "<your_api_key>";
$apiPaymentIntent = ApiFactory::createPaymentIntentApi($apiKey);
$apiPaymentIntent->paymentIntentsDelete(\Dojo_PHP\API_VERSION, "<paymentIntentId>");
Response example
If your request is successful, the response will return information about the canceled payment, and the status will be Canceled.
{
"id": "pi_sandbox_RBMHTJ4fIkmSppDILZVCGw",
"captureMode": "Auto",
"status": "Canceled",
"paymentMethods": [
"Card"
],
"amount": {
"value": 1000,
"currencyCode": "GBP"
},
"totalAmount": {
"value": 1000,
"currencyCode": "GBP"
},
"createdAt": "2022-02-21T14:39:21.6050276Z",
"updatedAt": "2022-02-21T14:39:21.6050277Z"
}