Skip to content
Proud to collaborate with Microsoft for Startups

subscription.cancellation ​

Tracks scheduled subscription cancellations and handles reactivation

Tracks scheduled subscription cancellations.

States: scheduled → notified (optional) → cancelled (terminal/success) → reactivated (terminal/success) → failed (terminal/fail)

All transitions are driven by Stripe webhooks — the workflow does not perform active DB writes. context.session is not required.

Overview ​

PropertyValue
Workflow typeLinear
LibraryApp-subscription
Version2.0

Triggers ​

SourceEndpoint / EventDescription
WEBHOOKcustomer.subscription.updatedStripe webhook when cancel_at is set
WEBHOOKcustomer.subscription.deletedStripe webhook when subscription is actually cancelled

Input Schema ​

FieldTypeRequiredDefaultDescription
subscription_uuiduuidYes—OrganizationSubscription UUID
organization_uuiduuidYes—Organization UUID
stripe_subscription_refstringYes—Stripe subscription reference
cancel_atstringYes—ISO timestamp when subscription will cancel
cancel_at_timestampintegerNo—Unix timestamp when subscription will cancel
trace_refstringNo—Trace reference for request correlation

Output Schema ​

FieldTypeRequiredDefaultDescription
subscription_uuiduuidNo——
organization_uuiduuidNo——
stripe_subscription_refstringNo——
cancel_atstringNo——
cancel_at_timestampintegerNo——
trace_refstringNo——
scheduled_atstringNo——
notified_atstringNo——
cancelled_atstringNo—ISO timestamp of the actual Stripe cancellation
completed_atstringNo——
keys_revokedjsonNo——
reactivated_atstringNo——
reactivation_reasonstringNo——
notification_sentbooleanNo——
notification_sent_atstringNo——
failed_atstringNo——
failure_reasonstringNo——
failure_typestringNo——
failed_actionstringNo——
failed_at_statestringNo——
failed_stepstringNo——
failed_layerstringNo——
errorstringNo——
error_typestringNo——

States ​

StateInitialTerminalSuccessAuto-advanceDescription
scheduledYesNo——Cancellation scheduled, waiting for cancel_at time
notifiedNoNo——Pre-cancellation notification sent
cancelledNoYesYes—Subscription cancelled at scheduled time
failedNoYesNo—Workflow failed
reactivatedNoYesYes—User reversed the cancellation

State Diagram ​

Transitions ​

FromActionToDescription
scheduledsend_notificationnotifiedSend pre-cancellation notification
scheduledcomplete_cancellationcancelledComplete cancellation from scheduled
notifiedcomplete_cancellationcancelledComplete cancellation from notified
scheduledreactivatereactivatedUser reverses cancellation from scheduled
notifiedreactivatereactivatedUser reverses cancellation from notified
* (any state)failfailedCatch-all failure handler

Outcomes ​

OutcomeTypeDescriptionState Data Keys
cancelledSUCCESSSubscription was cancelled at scheduled timecancelled_at
reactivatedSUCCESSUser reversed the cancellationreactivated_at, reactivation_reason
failedFAILUREWorkflow failed — see failure_reasonfailed_at, failure_reason

Alarms ​

NameTypeStateSeverityDescription
cancellation_failedstate_enteredfailedwarningSubscription cancellation workflow failed

API Usage ​

bash
# Step 1: Start the workflow
POST /api/workflows/start
Content-Type: application/json

{
  "workflow_type": "subscription.cancellation",
  "initial_data": {
    "subscription_uuid": "value",
    "organization_uuid": "value",
    "stripe_subscription_ref": "value",
    "cancel_at": "value"
  }
}

# Step 2: Webhook triggers transition (customer.subscription.updated)
POST /api/workflows/{workflow_id}/transition
Content-Type: application/json

{ "action": "...", ... webhook payload ... }