API and webhooks
Subscriptions
Read and cancel subscriptions that Plandalf checkouts created. Look one up by the payment provider's id, the sub_… in webhook payloads. Plandalf reads the state live from the provider, so it's current.
Example
Check a subscription, with a payment link if its renewal failed:
curl "https://admin.plandalf.dev/api/v1/subscriptions/sub_1QExampleAda?include_recovery=true" \
-H "Authorization: Bearer $PLANDALF_API_KEY"
With include_recovery=true, a subscription whose renewal failed comes back with recovery: the open invoice and a link where the customer can pay it. Send that link in your own dunning email or show it in your app.
Cancel at the end of the period, or now:
curl -X POST https://admin.plandalf.dev/api/v1/subscriptions/sub_1QExampleAda/cancel \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"at_period_end": false}'
Plandalf sends subscription.updated or subscription.canceled when the provider confirms the change.
Endpoints
Retrieve a subscription
GET /api/v1/subscriptions/{subscription}
subscription is the payment provider's subscription id (for example Stripe's sub_…), as
sent in webhook payloads. State is read live from the provider. With
include_recovery=true the response adds recovery: the open invoice and payment link
for a subscription whose renewal failed.
Parameters
| Name | In | Type | What it is |
|---|---|---|---|
subscription | path | string | |
include_recovery optional | query | boolean |
curl https://admin.plandalf.dev/api/v1/subscriptions/:subscription \
-H "Authorization: Bearer $PLANDALF_API_KEY"
Response
{
"object": "subscription",
"id": "string",
"status": "string",
"current_period_end": "string",
"cancel_at_period_end": true,
"cancel_at": "string",
"canceled_at": "string",
"ended_at": "string",
"livemode": "string",
"invoice": "string",
"customer": {
"id": 0,
"email": "string",
"name": "string",
"external_id": "string"
},
"items": "string",
"recovery": "string"
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
403 | The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request. |
422 | The request failed validation; errors lists the problems by field. |
Cancel a subscription
POST /api/v1/subscriptions/{subscription}/cancel
Cancels at the end of the current period by default; send at_period_end: false to cancel
immediately. Returns the subscription as it is after the change.
Parameters
| Name | In | Type | What it is |
|---|---|---|---|
subscription | path | string |
Body
| Field | Type | What it is |
|---|---|---|
at_period_end optional | boolean |
curl -X POST https://admin.plandalf.dev/api/v1/subscriptions/:subscription/cancel \
-H "Authorization: Bearer $PLANDALF_API_KEY" \
-H "Content-Type: application/json" \
-d '{"at_period_end":true}'
Response
{
"object": "subscription",
"id": "string",
"status": "string",
"current_period_end": "string",
"cancel_at_period_end": true,
"cancel_at": "string",
"canceled_at": "string",
"ended_at": "string",
"livemode": "string",
"invoice": "string",
"customer": {
"id": 0,
"email": "string",
"name": "string",
"external_id": "string"
},
"items": "string"
}
Errors
| Status | When |
|---|---|
401 | The API key or OAuth token is missing or invalid. |
422 | The request failed validation; errors lists the problems by field. |