← All examples
SubscriptionUpgrade
examples/SubscriptionUpgrade.thunder
SubscriptionUpgrade.thunder
1mission SubscriptionUpgrade2use product3use delivery45title "Upgrade a customer to a higher subscription tier"6for BillingCustomer78goal9 Let a customer move to a higher tier, charged correctly and reversibly.1011guarantee the customer is charged at most once per upgrade12 because a double charge on an upgrade is a trust-breaking billing error13 verify idempotent charge test1415never16 charge a customer whose payment method is invalid17 downgrade entitlements before the new charge settles1819never charge a customer whose payment method is invalid20 because a charge that cannot settle becomes a failed payment and a refund cycle21 verify test CanUpgrade2223outcome FasterUpgrades24 "customers complete an upgrade in one step, without contacting support"2526metric upgrade_completion_rate27 baseline 71%28 target 85%29 window 30 days after release3031# An executable decision: run it with `thunder run`, assert it with `thunder test`.32decision CanUpgrade33 inputs34 currentTier35 targetTier36 paymentValid37 outstandingBalance38 rule noPayment39 when paymentValid == false40 return Blocked41 rule owesMoney42 when outstandingBalance > 043 return Blocked44 rule higherTier45 when targetTier > currentTier46 return Allowed47 default48 return NoChange4950# A lifecycle: walk it with `thunder simulate`.51lifecycle UpgradeFlow52 state Requested53 state Charged54 state Active55 state Failed56 transition charge57 from Requested58 to Charged59 transition activate60 from Charged61 to Active62 transition chargeFailed63 from Requested64 to Failed65 terminal Active, Failed6667command ChargeUpgrade68 idempotency_key upgradeId69 timeout 20 seconds70on ChargeUpgradeFailed71 compensate release entitlement hold7273# An outcome contract + the delivery result that measures it: `thunder outcomes`.74outcome_contract UpgradeConversion75 outcome FasterUpgrades76 metric upgrade_completion_rate77 baseline 71%78 target 85%79 window 30 days after release80 owner GrowthPM8182result Q3Upgrades83 measures FasterUpgrades84 metric upgrade_completion_rate85 value 88%86 baseline 71%8788# Tests live in the file , `thunder test` runs them through the deterministic runtime.89test CanUpgrade90 case valid upgrade91 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 092 expect Allowed93 case invalid payment94 given currentTier 1, targetTier 2, paymentValid false, outstandingBalance 095 expect Blocked96 case owes money97 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 2598 expect Blocked99 case same tier100 given currentTier 2, targetTier 2, paymentValid true, outstandingBalance 0101 expect NoChange102103test UpgradeFlow104 scenario happy path105 events charge, activate106 expect Active107 valid108 scenario cannot activate first109 events activate110 invalidDraft syntax. This file is illustrative and does not run yet.
More examples
AlertRoutingApiGatewayBillingServiceCalculateRiskScoreCertificationAttemptCertificationCheckoutCertificationEligibilityCertificationStudyPlanCreateInvoiceCreateStudyPlanCustomerDataRequestDuplicateInvoicePreventionGroundedAnswerIngestClickstreamInvoiceCreatedNetworkEgressPolicyPlaceOrderResearchAgentRunResetPasswordStorefrontStyleTenantIsolationTwelveFactorAgentUploadStudyMaterial