Skip to content
Proud to collaborate with Microsoft for Startups

subscription.sync ​

Reconciles a single OrganizationSubscription against a Stripe payload and dispatches downstream workflows when the diff implies a richer business event (cancellation, dunning, plan change, recovery).

Reconcile one OrganizationSubscription against a Stripe payload.

Overview ​

PropertyValue
Workflow typeLinear
LibraryApp-subscription
Version1.0

Triggers ​

SourceEndpoint / EventDescription
WEBHOOKcustomer.subscription.updatedStatus / plan / cancel_at changes
WEBHOOKcustomer.subscription.deletedStripe-side termination
WEBHOOKinvoice.payment_failedTriggers dunning dispatch

Input Schema ​

FieldTypeRequiredDefaultDescription
organization_uuiduuidYes—Owning organization UUID
subscription_uuiduuidYes—OrganizationSubscription UUID
stripe_event_datajsonYes—Stripe Subscription object (or compatible projection)
sourcestringNo—webhook
event_typestringNo—Stripe event.type when source=webhook
trace_refstringNo—Trace reference for request correlation

Output Schema ​

FieldTypeRequiredDefaultDescription
organization_uuiduuidNo——
subscription_uuiduuidNo——
stripe_event_datajsonNo——
sourcestringNo——
event_typestringNo——
trace_refstringNo——
started_atstringNo——
loaded_atstringNo——
db_snapshotjsonNo——
stripe_snapshotjsonNo——
is_noopbooleanNo—True when DB and Stripe already agreed; nothing was written
applied_changesjsonNo—Map of column → new value written to OrganizationSubscription
applied_atstringNo——
dispatchedjsonNo—List of {workflow_type, workflow_uuid} entries spawned downstream
dispatched_atstringNo——
paid_rbac_releasejsonNo—Paid RBAC actor release gate for an ended platform subscription (canceled / unpaid / incomplete_expired): decision, and the subscription.actor-rbac-seat.resize release run when owed
diffjsonNo—Full diff payload: changes map + derived flags (plan_changed, cancellation_scheduled, entered_dunning, recovered, terminated)
stripe_subscription_refstringNo—Stripe subscription reference seen on this run
completed_atstringNo——
failed_atstringNo——
failure_reasonstringNo——
failure_typestringNo——
failed_actionstringNo——
failed_at_statestringNo——
failed_stepstringNo——
failed_layerstringNo——
errorstringNo——
error_typestringNo——

States ​

StateInitialTerminalSuccessAuto-advanceDescription
initiatedYesNo—load_currentSync request received
applyingNoNo—dispatchWriting the merged state to OrganizationSubscription
diffingNoNo—applyComputing diff between DB and Stripe
dispatchingNoNo—completeConditionally spawning downstream workflows
loadingNoNo—compute_diffLoading current DB row
completedNoYesYes—Sync completed
failedNoYesNo—Sync failed

State Diagram ​

Transitions ​

FromActionToDescription
initiatedload_currentloadingLoad DB row
loadingcompute_diffdiffingCompute diff
diffingapplyapplyingApply diff to DB (no-op when is_noop)
applyingdispatchdispatchingDispatch downstream
dispatchingcompletecompletedMark complete
* (any state)failfailedCatch-all failure handler

Outcomes ​

OutcomeTypeDescriptionState Data Keys
completedSUCCESSSync run terminated. state_data.is_noop=True means DB and Stripe already agreed; otherwise applied_changes and dispatched record what was done.is_noop, applied_changes, dispatched, completed_at
failedFAILURESync failed — see failure_reasonfailed_at, failure_reason

Business Errors ​

CodeMessage Template
SUBSCRIPTION_NOT_FOUNDOrganizationSubscription {subscription_uuid} not found
STRIPE_PAYLOAD_INVALIDStripe event payload is empty or missing required fields

Alarms ​

NameTypeStateSeverityDescription
sync_failedstate_enteredfailedwarningsubscription.sync run reached FAILED

API Usage ​

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

{
  "workflow_type": "subscription.sync",
  "initial_data": {
    "organization_uuid": "value",
    "subscription_uuid": "value",
    "stripe_event_data": "value"
  }
}

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

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