← All examples
SubscriptionUpgrade
examples/SubscriptionUpgrade.intent
SubscriptionUpgrade.intent
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 settles1819outcome FasterUpgrades20 "customers complete an upgrade in one step, without contacting support"2122metric upgrade_completion_rate23 baseline 71%24 target 85%25 window 30 days after release2627# An executable decision: run it with `intent run`, assert it with `intent test`.28decision CanUpgrade29 inputs30 currentTier31 targetTier32 paymentValid33 outstandingBalance34 rule noPayment35 when paymentValid == false36 return Blocked37 rule owesMoney38 when outstandingBalance > 039 return Blocked40 rule higherTier41 when targetTier > currentTier42 return Allowed43 default44 return NoChange4546# A lifecycle: walk it with `intent simulate`.47lifecycle UpgradeFlow48 state Requested49 state Charged50 state Active51 state Failed52 transition charge53 from Requested54 to Charged55 transition activate56 from Charged57 to Active58 transition chargeFailed59 from Requested60 to Failed61 terminal Active, Failed6263command ChargeUpgrade64 idempotency_key upgradeId65 timeout 20 seconds66on ChargeUpgradeFailed67 compensate release entitlement hold6869# An outcome contract + the delivery result that measures it: `intent outcomes`.70outcome_contract UpgradeConversion71 outcome FasterUpgrades72 metric upgrade_completion_rate73 baseline 71%74 target 85%75 window 30 days after release76 owner GrowthPM7778result Q3Upgrades79 measures FasterUpgrades80 metric upgrade_completion_rate81 value 88%82 baseline 71%8384# Tests live in the file , `intent test` runs them through the deterministic runtime.85test CanUpgrade86 case valid upgrade87 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 088 expect Allowed89 case invalid payment90 given currentTier 1, targetTier 2, paymentValid false, outstandingBalance 091 expect Blocked92 case owes money93 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 2594 expect Blocked95 case same tier96 given currentTier 2, targetTier 2, paymentValid true, outstandingBalance 097 expect NoChange9899test UpgradeFlow100 scenario happy path101 events charge, activate102 expect Active103 valid104 scenario cannot activate first105 events activate106 invalidDraft syntax. This file is illustrative and does not run yet.