Created
September 7, 2022 04:15
-
-
Save daniellizik/c59a344661fa0ddfc64a0d6d279c3550 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
const fetchMachine = Machine({ | |
id: 'payments', | |
initial: 'init', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
init: { | |
on: { | |
INIT: [ | |
{ | |
target: 'fetchingTokenizationScript', | |
cond: 'isNotFiserv' | |
}, | |
{ | |
target: 'doFiservThing', | |
cond: 'isFiserv' | |
} | |
] | |
} | |
}, | |
doFiservThing: { | |
type: 'final', | |
invoke: { | |
src: 'fiservThing' | |
} | |
}, | |
fetchingTokenizationScript: { | |
invoke: { | |
src: 'fetchTokenizationScript', | |
onDone: 'fetchingToken' | |
} | |
}, | |
fetchingToken: { | |
invoke: { | |
src: 'fetchingToken', | |
onDone: 'submittingCart' | |
} | |
}, | |
submittingCart: { | |
invoke: { | |
src: 'submitCart', | |
onDone: 'pollingCheckoutStatus' | |
} | |
}, | |
pollingCheckoutStatus: { | |
invoke: { | |
src: 'poll', | |
onDone: 'afterPolling' | |
} | |
}, | |
afterPolling: { | |
always: [ | |
{ target: 'error', cond: 'isCheckoutError'}, | |
{ target: 'done', cond: 'isCheckoutSuccessful' }, | |
{ target: 'redirect', cond: 'isRedirect' } | |
] | |
}, | |
redirect: { | |
type: 'final', | |
invoke: { | |
src: 'redirect' | |
} | |
}, | |
error: { | |
type: 'final' | |
}, | |
done: { | |
type: 'final' | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment