Cancelling an Invoice
To cancel an invoice, you need to send a DELETE request.
DELETEjs
https://api.payp.io/&/v2/invoice/(invoice_id)
Please note that the invoice will be closed, not deleted.
To cancel the invoice, send the request with the unique identifier. The request will only be successful if the invoice is in the "created" status.
Headers
Name | Type | Description |
---|---|---|
Authorization | string | Token API KEY |
Response
json
{
"status": "success",
}
json
// Check the correctness of the API key
{
"status": 401,
"name": "UnauthorizedError",
"message": "shop not found",
"details": "check api key"
}
json
// Check if fields are correctly specified
{
"status": 400,
"name": "BadRequestError",
"message": "Required field is missing",
"details": "uid"
}
json
// The invoice might already be closed, or the provided invoice uid is incorrect
{
"status": 404,
"name": "NotFoundError",
"message": "invoice not found",
"details": {}
}
Request Examples
These examples show how to send a request to cancel an invoice using Python and JavaScript. Note that you must include your API key in the Authorization header for successful request authorization.
php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.payp.io/&/v2/invoice/merchant/canceled");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("uuid" => "INV-XXXXXXXX")));
$headers = array(
"Authorization: Token <API KEY>",
"Content-Type: application/json"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode == 200) {
echo "Success: " . $response;
} else {
echo "Fail: " . $statusCode . " " . $response;
}
}
curl_close($ch);
?>
Python
import requests
import json
url = "https://api.payp.io/&/v2/invoice"
headers = {
"Authorization": "Token <API KEY>",
"Content-Type": "application/json"
}
data = {
"amount": 100.0,
"currency": "USD",
"description": "Pay"
}
response = requests.post(url, headers=headers, json=data)
# Check response
if response.status_code == 200:
print("Success:", response.json())
else:
print("Fail:", response.status_code, response.text)
js
const url = 'https://api.payp.io/&/v2/invoice';
const headers = new Headers({
'Authorization': 'Token <API KEY>',
'Content-Type': 'application/json'
});
const data = {
amount: 100.0,
currency: 'USD',
description: 'Pay'
};
fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
return Promise.reject('Error');
}
})
.then(data => {
console.log('Success:', data);
})
.catch(error => {
console.error('Fail:', error);
});