DocumentationPOST Cancel a subscription
Subscriptions API
POST
/subscriptions/{id}/cancelCancel a subscription
Stops renewals at the end of the paid period by default; pass `at_period_end: false` to end it now. Nothing is refunded and the saved card is forgotten.
Use your sandbox environment to start. Understand error codes and payment statuses before handling a live payment.
Cancel a subscription
curl --request POST "https://api.veyqo.org/api/v1/subscriptions/$PAYMENT_ID/cancel" \
--header "Authorization: Bearer $VEYQO_SECRET_KEY" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '{
"at_period_end": true
}'{
"success": true,
"data": {
"id": "csub_01M7Q3A1B2C3D4E5F6G7H8J9K0",
"object": "subscription",
"reference": "SUB-1001",
"status": "active",
"plan": {
"id": "rplan_01M7Q2Z8X4K3V9B6N5C1D0E2F3",
"object": "plan",
"name": "Pro monthly",
"description": "Everything in Pro",
"amount": 250000,
"currency": "NGN",
"interval": "month",
"interval_count": 1,
"trial_days": 0,
"active": true,
"metadata": [],
"created_at": "2026-11-19T12:00:00+00:00"
},
"customer": {
"email": "customer@example.com",
"name": "Ada Lovelace"
},
"card": {
"brand": "Visa",
"last4": "4081"
},
"current_period_start": "2026-11-19T12:00:00+00:00",
"current_period_end": "2026-12-19T12:00:00+00:00",
"trial_ends_at": null,
"pending_plan": null,
"cancel_at_period_end": true,
"cancelled_at": null,
"failed_attempts": 0,
"next_attempt_at": "2026-12-19T12:00:00+00:00",
"payments_count": 1,
"latest_payment_id": "pay_01M7Q3B2C3D4E5F6G7H8J9K0L1",
"checkout_url": null,
"metadata": {
"customer_id": "42"
},
"created_at": "2026-11-19T12:00:00+00:00"
}
}Illustrative examples. Replace IDs and environment variables with your own values. Keep secret keys on your server.
Headers
Authorizationstringrequired- Bearer <secret-key>. This key determines your project environment and must stay on your server.
Content-Typestringrequired- application/json
Acceptstringoptional- application/json
Endpoint
POST https://api.veyqo.org/api/v1/subscriptions/{id}/cancel
Server secret key required. Scope: subscriptions:write. The key determines the project and environment; no project-selection header is accepted.
Path and query parameters
| Parameter | Location | Required | Description |
|---|---|---|---|
| id | path | Yes | Use the ID returned when this resource was created. |
Request body
at_period_endbooleanoptional- Default true: stop renewing at period end. false ends it now.
Response fields
idstringoptional- csub_ id.
objectstringoptional- Always subscription.
referencestring | nulloptional- Your own reference, unique in the environment.
statusstringoptional- incomplete, trialing, active, past_due or cancelled. Values: incomplete, trialing, active, past_due, cancelled.
planPlanoptional- A plan your customers subscribe to.
plan.idstringoptional- rplan_ id.
plan.objectstringoptional- Always plan.
plan.namestringoptional- Shown on checkout.
plan.descriptionstring | nulloptional- Optional.
plan.amountintegeroptional- Per period, in the smallest currency unit.
plan.currencystringoptional- ISO 4217.
plan.intervalstringoptional- day, week, month or year. Values: day, week, month, year.
plan.interval_countintegeroptional- Periods per charge, e.g. 3 with month for quarterly.
plan.trial_daysintegeroptional- Free trial for new subscriptions, in days (0 for none).
plan.activebooleanoptional- False once archived.
plan.metadataobjectoptional- Your own key-values.
plan.created_atstringoptional- ISO 8601. Format: date-time.
customerobjectoptional- email and name.
cardobject | nulloptional- brand and last4 of the saved card, if any.
current_period_startstring | nulloptional- Start of the paid period.
current_period_endstring | nulloptional- When the next charge is due.
trial_ends_atstring | nulloptional- When the free trial ends, if it had one.
pending_planobject | nulloptional- The plan that takes over at the next renewal, if a change is scheduled.
cancel_at_period_endbooleanoptional- Ends instead of renewing.
cancelled_atstring | nulloptional- When it ended.
failed_attemptsintegeroptional- Failed renewal tries this period (ends after 3).
next_attempt_atstring | nulloptional- Next charge or retry.
payments_countintegeroptional- Periods paid.
latest_payment_idstring | nulloptional- The most recent payment.
checkout_urlstring | nulloptional- Where the customer pays, when something is due from them.
metadataobjectoptional- Your own key-values.
created_atstringoptional- ISO 8601. Format: date-time.
Errors and recovery
| Code | HTTP | Recovery | Retry policy |
|---|---|---|---|
| INVALID_API_KEY | 401 | Use a current kc_test_ or kc_live_ secret key on /api/v1. Use a pk_test_ or pk_live_ publishable key only on browser checkout. | After fixing credentials. |
| INSUFFICIENT_PERMISSION | 403 | Grant the required scope or use a suitably scoped key. Dashboard organization roles and staff permissions are separate. | After permission changes. |
| RATE_LIMIT_EXCEEDED | 429 | Honor Retry-After, use bounded exponential backoff with jitter, and reduce concurrent requests. Read X-RateLimit headers. | Yes, after Retry-After; preserve write idempotency. |
| METHOD_NOT_ALLOWED | 405 | Use the method documented for the endpoint, such as POST for verification and refunds. | After fixing the method. |
| INTERNAL_ERROR | 500 | Record X-Request-Id, timestamp and sanitized request context. Reconcile unknown payment outcomes before retrying a write; contact support if it persists. | Safe reads: bounded backoff. Writes: reconcile first. |
| RESOURCE_NOT_FOUND | 404 | Check the ID, project and environment. Do not guess another project’s IDs. An inactive payment link is also not-found. | No blind retry. |