Last active
October 15, 2021 13:29
-
-
Save sfarthin/a902cdd165ca538727fe6c2f3f496917 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
const payAdvanceService = { | |
orchInitiatePayout: async () => null, | |
orchInitiateRepayment: async () => (send) => { | |
// send({ type: 'initiatedFullAchRepayment' }); | |
}, | |
}; | |
const machine = Machine({ | |
type: 'parallel', | |
context: { | |
failedPayouts: 0, | |
}, | |
states: { | |
payadvance: { | |
initial: 'none_requested', | |
states: { | |
none_requested: { | |
on: { | |
requestPayAdvance: { | |
target: 'payout', | |
actions: assign({ | |
amountCents: () => 12500, | |
}), | |
}, | |
}, | |
}, | |
payout: { | |
initial: 'requesting', | |
states: { | |
requesting: { | |
invoke: { | |
src: payAdvanceService.orchInitiatePayout, | |
onDone: { | |
target: 'in_progress', | |
actions: assign({ | |
payoutTransactionId: () => `${Date.now()}`, | |
}), | |
}, | |
}, | |
}, | |
in_progress: {}, | |
failed: {}, | |
}, | |
on: { | |
successfulPayoutWebhook: { | |
target: 'repayment', | |
actions: assign({ | |
payoutReceiptId: () => `${Date.now()}`, | |
}), | |
}, | |
failedPayoutWebhook: { | |
target: 'payout.failed', | |
actions: assign({ | |
failedPayouts: (c) => c.failedPayouts + 1, | |
}), | |
}, | |
foundSuccessfulStuckPayout: { | |
target: 'repayment', | |
actions: assign({ | |
payoutReceiptId: () => `${Date.now()}`, | |
}), | |
}, | |
foundFailedStuckPayout: { | |
target: 'payout.failed', | |
actions: assign({ | |
failedPayouts: (c) => c.failedPayouts + 1, | |
}), | |
}, | |
}, | |
}, | |
repayment: { | |
initial: 'ready', | |
states: { | |
ready: { | |
initial: 'paid_out', | |
states: { | |
paid_out: {}, | |
delayed: {}, | |
failed: {}, | |
}, | |
on: { | |
manualRepayment: { | |
target: 'initiating_repayment', | |
}, | |
autoRepayment: { | |
target: 'initiating_repayment', | |
}, | |
}, | |
}, | |
initiating_repayment: { | |
invoke: { | |
src: payAdvanceService.orchInitiateRepayment, | |
}, | |
on: { | |
initiatedFullDebitRepayment: { | |
target: ['in_progress.method.debit', 'in_progress.amount.full'], | |
}, | |
initiatedPartialDebitRepayment: { | |
target: ['in_progress.method.debit', 'in_progress.amount.partial'], | |
}, | |
initiatedFullAchRepayment: { | |
target: ['in_progress.method.ach', 'in_progress.amount.full'], | |
}, | |
initiatedPartialAchRepayment: { | |
target: ['in_progress.method.ach', 'in_progress.amount.partial'], | |
}, | |
}, | |
}, | |
in_progress: { | |
type: 'parallel', | |
states: { | |
method: { | |
states: { | |
ach: {}, | |
debit: {}, | |
}, | |
}, | |
amount: { | |
states: { | |
partial: {}, | |
full: {}, | |
}, | |
}, | |
}, | |
}, | |
uncollectable: {}, | |
repaid: {}, | |
}, | |
on: { | |
stripeChargePartialPaymentHook: { | |
target: 'repayment.ready.delayed', | |
}, | |
stripeChargeFullPaymentHook: { | |
target: 'repayment.repaid', | |
}, | |
stripeChargeFailedPaymentHook: { | |
target: 'repayment.ready.failed', | |
}, | |
}, | |
}, | |
}, | |
on: { | |
setTipAmount: { actions: assign({ tipAmmount: () => 5 }) }, | |
failedPayoutWebhook: { | |
target: 'payadvance.payout.failed', | |
}, | |
successfulPayoutWebhook: {}, | |
sawRepaymentTransaction: {}, | |
sawIncomeTransaction: {}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment