Skip to content

Instantly share code, notes, and snippets.

@daniellizik
Created September 7, 2022 04:15
Show Gist options
  • Save daniellizik/c59a344661fa0ddfc64a0d6d279c3550 to your computer and use it in GitHub Desktop.
Save daniellizik/c59a344661fa0ddfc64a0d6d279c3550 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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