Last active
August 29, 2015 14:11
-
-
Save simonexmachina/0d938af48a03afce3f47 to your computer and use it in GitHub Desktop.
Edits can be made here: http://code.stypi.com/aexmachina/order-states (but Stypi doesn't support YAML syntax)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root: | |
initialState: unpaid | |
actions: | |
- recomputeState() # throws Exception if 0 > paid || paid > total | |
# see comments on states below | |
- addItem(item) # then recomputeState | |
- payment(amount) # then recomputeState | |
- refund(amount[, transaction]) # then recomputeState | |
# if refunding line items then refund amount may be computed from | |
# adjustedTotal, and do we care what items a manual discount | |
# was applied to? | |
- undo(transaction) # then recomputeState | |
# this may require us to confirm that the parent is the latest | |
# transaction to avoid race conditions | |
unpaid: # total of transactions is 0 | |
partialPaid: # total of transactions is < order total | |
paid: # total of transactions >= order total | |
"order model": | |
attrs: | |
parked | |
computed: | |
hasRefunds | |
total | |
totalPaid | |
"lineitem model": | |
attrs: | |
placed | |
adjustedTotal | |
# this may be a solution for refunding individual items | |
# need to find out whether refunds should be user-controlled | |
"hasMany transactions": | |
# this does not indicate whether a lineitem is partially/fully | |
# paid or refunded - this would require a state machine (which | |
# is conveniently the same as the one above), and is outside scope | |
"transaction model": | |
attrs: | |
references (was parent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment