Cancel a payment
curl --request POST \
--url https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Tenant-ID: <tenant-id>' \
--data '
{
"reason": "<string>"
}
'import requests
url = "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel"
payload = { "reason": "<string>" }
headers = {
"Tenant-ID": "<tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Tenant-ID': '<tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({reason: '<string>'})
};
fetch('https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'reason' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Tenant-ID: <tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel"
payload := strings.NewReader("{\n \"reason\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Tenant-ID", "<tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel")
.header("Tenant-ID", "<tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"reason\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Tenant-ID"] = '<tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"reason\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"payment": {
"paymentId": "<string>",
"tenantId": "<string>",
"customerId": "<string>",
"subtotal": 1,
"total": 1,
"currency": "<string>",
"paymentType": "individual",
"billingPeriod": "<string>",
"status": "pending",
"idempotencyKey": "<string>",
"dueDate": "<string>",
"createdAt": "<string>",
"updatedAt": "<string>",
"taxAmount": 0,
"taxRate": 0,
"amount": 1,
"rentalId": "<string>",
"billingGroupId": "<string>",
"provider": "stripe",
"transactionId": "<string>",
"providerResponse": {},
"manuallyMarked": false,
"paymentReference": "<string>",
"markedBy": "<string>",
"captureAttempts": 0,
"lastCaptureError": {
"code": "<string>",
"message": "<string>",
"declineCode": "<string>"
},
"lineItems": [
{
"rentalId": "<string>",
"description": "<string>",
"amount": 1,
"taxAmount": 0
}
],
"lateFeeApplied": false,
"lateFeeAmount": 1,
"originalAmount": 1,
"notes": "<string>",
"paidAt": "<string>",
"lastCaptureAttempt": "<string>",
"nextRetryAt": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Payments
Cancel Payment
Cancels a pending payment. Cannot cancel already paid or processing payments.
POST
/
v1
/
payments
/
{paymentId}
/
cancel
Cancel a payment
curl --request POST \
--url https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Tenant-ID: <tenant-id>' \
--data '
{
"reason": "<string>"
}
'import requests
url = "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel"
payload = { "reason": "<string>" }
headers = {
"Tenant-ID": "<tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Tenant-ID': '<tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({reason: '<string>'})
};
fetch('https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'reason' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Tenant-ID: <tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel"
payload := strings.NewReader("{\n \"reason\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Tenant-ID", "<tenant-id>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel")
.header("Tenant-ID", "<tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"reason\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-eu.flexportal.io/v1/payments/{paymentId}/cancel")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Tenant-ID"] = '<tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"reason\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "<string>",
"payment": {
"paymentId": "<string>",
"tenantId": "<string>",
"customerId": "<string>",
"subtotal": 1,
"total": 1,
"currency": "<string>",
"paymentType": "individual",
"billingPeriod": "<string>",
"status": "pending",
"idempotencyKey": "<string>",
"dueDate": "<string>",
"createdAt": "<string>",
"updatedAt": "<string>",
"taxAmount": 0,
"taxRate": 0,
"amount": 1,
"rentalId": "<string>",
"billingGroupId": "<string>",
"provider": "stripe",
"transactionId": "<string>",
"providerResponse": {},
"manuallyMarked": false,
"paymentReference": "<string>",
"markedBy": "<string>",
"captureAttempts": 0,
"lastCaptureError": {
"code": "<string>",
"message": "<string>",
"declineCode": "<string>"
},
"lineItems": [
{
"rentalId": "<string>",
"description": "<string>",
"amount": 1,
"taxAmount": 0
}
],
"lateFeeApplied": false,
"lateFeeAmount": 1,
"originalAmount": 1,
"notes": "<string>",
"paidAt": "<string>",
"lastCaptureAttempt": "<string>",
"nextRetryAt": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Overview
Cancel a pending or failed payment. Use this when a payment should not be collected—for example, when a subscription was ended early or a billing adjustment is needed.Cancelling a payment removes it from collection. This action cannot be undone. For refunds of already-paid payments, use your payment processor’s refund functionality.
Common Use Cases
- Early Termination: Subscription ended before payment due
- Billing Adjustment: Correcting overcharges or errors
- Customer Goodwill: Waiving a payment as a courtesy
- Duplicate Payments: Removing duplicate scheduled payments
- Subscription Cancelled: Associated subscription was cancelled
Request Fields
| Field | Required | Description |
|---|---|---|
reason | Yes | Reason for cancellation |
Example Request
{
"reason": "Subscription ended early - customer relocated"
}
What Happens
When you cancel a payment:- Payment status changes to
cancelled - Cannot be collected or marked as paid
- Subscription metrics may be updated
- Reason recorded for audit trail
Which Payments Can Be Cancelled
| Current Status | Can Cancel? |
|---|---|
pending | Yes |
processing | No (wait for result) |
paid | No (use refund instead) |
failed | Yes |
cancelled | No (already cancelled) |
Example: Cancel Due to Early Return
async function handleEarlyReturn(subscriptionId) {
// Get all pending payments for this subscription
const { payments } = await listPayments({
rentalId: subscriptionId,
status: 'pending'
});
// Cancel remaining payments
for (const payment of payments) {
await cancelPayment(payment.paymentId, {
reason: `Subscription ${subscriptionId} ended early`
});
}
return {
cancelledPayments: payments.length,
savedAmount: payments.reduce((sum, p) => sum + p.amount, 0)
};
}
Example: Cancel with Customer Reason
async function cancelAsGoodwill(paymentId, customerName) {
return await cancelPayment(paymentId, {
reason: `Goodwill gesture for ${customerName} - approved by manager`
});
}
Error Handling
| Error Code | Cause | Solution |
|---|---|---|
NOT_FOUND | Payment doesn’t exist | Verify payment ID |
ALREADY_PAID | Cannot cancel paid payment | Use refund instead |
ALREADY_CANCELLED | Payment already cancelled | No action needed |
PAYMENT_PROCESSING | Payment currently processing | Wait for result |
Related Endpoints
- Get Payment - Check payment status
- List Payments - Find payments to cancel
- Mark Paid - Alternative: mark as paid
- Early Return - End subscription early
Authorizations
API key obtained from FlexPortal dashboard
Headers
Your tenant identifier
Path Parameters
The payment ID
Body
application/json
Minimum string length:
1Was this page helpful?