This subscription workflow is to match the use case described in
Build an application for a limited time Subscription (eg a 36 month Phone plan) that satisfies these conditions:
-
When the user signs up, send a welcome email and start a free trial for TrialPeriod.
-
When the TrialPeriod expires, start the billing process.
- If the user cancels during the trial, send a trial cancellation email.
- Billing Process:
- As long as you have not exceeded MaxBillingPeriods, charge the customer for the BillingPeriodChargeAmount.
- Then wait for the next BillingPeriod.
- If the customer cancels during a billing period, send a subscription cancellation email.
- If Subscription has ended normally (exceeded MaxBillingPeriods without cancellation), send a subscription ended email.
- At any point while subscriptions are ongoing, be able to look up and change any customer's amount charged and current status and info.
Of course, this all has to be fault tolerant, scalable to millions of customers, testable, maintainable, and observable.
And controller is a very thin layer of calling iWF client APIs and workflow RPC stub APIs. See subscriptionController.
To start a subscription workflow:
It will return you a workflowId.
The controller is hard coded to start with 20s as trial period, 10s as billing period, $100 as period charge amount for 10 max billing periods
To update the period charge amount :
- Open http://localhost:8803/subscription/updateChargeAmount?workflowId=&newChargeAmount=
To cancel the subscription:
To describe the subscription:
This is a iWF state diagram to visualize the workflow design: