Skip to main content
IntentLang
← All examples

SubscriptionUpgrade

examples/SubscriptionUpgrade.intent

SubscriptionUpgrade.intent
1mission SubscriptionUpgrade
2use product
3use delivery
4
5title "Upgrade a customer to a higher subscription tier"
6for BillingCustomer
7
8goal
9 Let a customer move to a higher tier, charged correctly and reversibly.
10
11guarantee the customer is charged at most once per upgrade
12 because a double charge on an upgrade is a trust-breaking billing error
13 verify idempotent charge test
14
15never
16 charge a customer whose payment method is invalid
17 downgrade entitlements before the new charge settles
18
19outcome FasterUpgrades
20 "customers complete an upgrade in one step, without contacting support"
21
22metric upgrade_completion_rate
23 baseline 71%
24 target 85%
25 window 30 days after release
26
27# An executable decision: run it with `intent run`, assert it with `intent test`.
28decision CanUpgrade
29 inputs
30 currentTier
31 targetTier
32 paymentValid
33 outstandingBalance
34 rule noPayment
35 when paymentValid == false
36 return Blocked
37 rule owesMoney
38 when outstandingBalance > 0
39 return Blocked
40 rule higherTier
41 when targetTier > currentTier
42 return Allowed
43 default
44 return NoChange
45
46# A lifecycle: walk it with `intent simulate`.
47lifecycle UpgradeFlow
48 state Requested
49 state Charged
50 state Active
51 state Failed
52 transition charge
53 from Requested
54 to Charged
55 transition activate
56 from Charged
57 to Active
58 transition chargeFailed
59 from Requested
60 to Failed
61 terminal Active, Failed
62
63command ChargeUpgrade
64 idempotency_key upgradeId
65 timeout 20 seconds
66on ChargeUpgradeFailed
67 compensate release entitlement hold
68
69# An outcome contract + the delivery result that measures it: `intent outcomes`.
70outcome_contract UpgradeConversion
71 outcome FasterUpgrades
72 metric upgrade_completion_rate
73 baseline 71%
74 target 85%
75 window 30 days after release
76 owner GrowthPM
77
78result Q3Upgrades
79 measures FasterUpgrades
80 metric upgrade_completion_rate
81 value 88%
82 baseline 71%
83
84# Tests live in the file , `intent test` runs them through the deterministic runtime.
85test CanUpgrade
86 case valid upgrade
87 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 0
88 expect Allowed
89 case invalid payment
90 given currentTier 1, targetTier 2, paymentValid false, outstandingBalance 0
91 expect Blocked
92 case owes money
93 given currentTier 1, targetTier 2, paymentValid true, outstandingBalance 25
94 expect Blocked
95 case same tier
96 given currentTier 2, targetTier 2, paymentValid true, outstandingBalance 0
97 expect NoChange
98
99test UpgradeFlow
100 scenario happy path
101 events charge, activate
102 expect Active
103 valid
104 scenario cannot activate first
105 events activate
106 invalid
Draft syntax. This file is illustrative and does not run yet.