Cancel a Subscription
Under construction
Localpayment allows you to cancel active subscriptions when customers no longer wish to continue their recurring payments. This guide details the process for canceling a subscription through Localpayment's API, including immediate cancellations and end-of-billing period options.
Before You Begin
Ensure you have:
Step 1: Cancel a Subscription
To cancel an existing subscription, send a PATCH request to the Cancel a Subscription endpoint.
Key Request Parameters
The request requires several key objects:
| Parameter | Description | Required |
|---|---|---|
status | Must be set to CANCEL to initiate cancellation | ✅ |
Example Request
Below is an example using curl:
curl --request PATCH \
--url https://api.stage.localpayment.com/api/payin/subscriptions/{externalId}/status \
--header 'Authorization: Bearer <your_access_token>' \
--header 'accept: application/json' \
--header 'content-type: application/json'
--data-raw '{
"status": "CANCEL"
}'
Important: Once a subscription is cancelled, it cannot be reactivated. You will need to create a new subscription if the customer wishes to resume service.
Step 2: Handle the Response
Successful Response
A successful cancellation returns the subscription cancellation confirmation:
{
"externalId": "a2966037-52a1-4a73-9173-b682969b34ff",
"internalId": "1ef01791-0e51-4b66-9d45-229895cd49d0",
"status": {
"code": "903",
"description": "CANCELLED",
"detail": "The subscription was canceled - merchant request"
}
}Key Response Fields
| Parameter | Description | Use Case |
|---|---|---|
internalId | Localpayment's unique transaction identifier. | Transaction tracking and support. |
externalId | Your unique reference for the subscription. | Internal reconciliation. |
status.code | Cancellation status code (903 for successful cancellation). | Status monitoring. |
status.description | Human-readable status description. | User interface display. |
status.detail | Detailed cancellation information. | Audit trail. |
Error Response
When a subscription cancellation fails, you'll receive error information::
{
"status": {
"code": "400",
"description": "ERROR",
"detail": "Invalid externalID Subscription Not Found"
}
}Step 3: Track Transaction Status
After cancelling a subscription, monitor the status through these methods:
Webhooks (Recommended)
Receive real-time notifications when transaction status changes. Most efficient for production environments.
Status API Endpoint
Query transaction status programmatically. Useful for polling or recovering lost webhook notifications.
Dashboard View
Visual interface for monitoring transactions. Great for manual oversight and detailed transaction analysis.
Common Status Codes
| Code | Status | Description |
|---|---|---|
400 | ERROR | Cancellation request failed. |
903 | CANCELLED | Subscription has been successfully cancelled. |
Note: For complete status code reference, see the Transaction Status documentation.
Testing Your Integration
Test Scenarios
Verify your integration handles these scenarios:
- Successful Cancellation: Cancel an active subscription with valid credentials.
- Already Cancelled Subscription: Attempt to cancel already cancelled subscription.
- Nonexistent Subscription: Cancel a subscription that doesn't exist.
- Authentication Errors: Cancel with invalid or missing authentication.
- Webhook Notifications: Confirm cancellation webhooks are triggered
Next Steps
After cancelling a subscription, you may need to perform additional actions:
Updated about 11 hours ago
