Skip to content

Instantly share code, notes, and snippets.

@Waxolunist
Created November 20, 2019 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Waxolunist/f85336e7e191b9fcf008b9553a310328 to your computer and use it in GitHub Desktop.
Save Waxolunist/f85336e7e191b9fcf008b9553a310328 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'sepa',
initial: 'CREATED',
states: {
CREATED: {
meta: {
value: '0101',
},
on: {
VALIDATE: 'ACCOUNT_COVERAGE_CHECK',
},
},
ACCOUNT_COVERAGE_CHECK: {
invoke: [
{
id: 'arctisCoverageCheck',
src: 'arctisCoverageCheck',
onDone: [
{
target: 'ACCOUNT_COVERED',
cond: 'accountIsCovered',
},
{
target: 'ACCOUNT_NOT_COVERED',
cond: 'accountIsNotCovered',
},
],
onError: {
target: 'ERROR',
},
},
],
},
ACCOUNT_NOT_COVERED: {
meta: {
value: '0103',
},
on: {
AMOUNT_CHANGE: 'ACCOUNT_COVERAGE_CHECK',
CANCEL: 'ABORTED',
},
},
ACCOUNT_COVERED: {
meta: {
value: '0102',
},
on: {
DATA_CHANGE: [
{
target: 'RECEIVER_DATA_COLLECTED',
cond: 'receiverDataIsValid',
},
{
target: 'ACCOUNT_COVERED',
cond: 'receiverDataIsNotValid',
},
],
AMOUNT_CHANGE: 'ACCOUNT_COVERAGE_CHECK',
CANCEL: 'ABORTED',
},
},
RECEIVER_DATA_COLLECTED: {
meta: {
value: '0104',
},
on: {
NEXT: 'READY_FOR_PREBOOK',
AMOUNT_CHANGE: [
{
target: 'RECEIVER_DATA_COLLECTED',
cond: 'accountIsCovered',
},
{
target: 'ACCOUNT_NOT_COVERED',
cond: 'accountIsNotCovered',
},
],
DATA_CHANGE: [
{
target: 'RECEIVER_DATA_COLLECTED',
cond: 'receiverDataIsValid',
},
{
target: 'ACCOUNT_COVERED',
cond: 'receiverDataIsNotValid',
},
],
CANCEL: 'ABORTED',
},
},
READY_FOR_PREBOOK: {
invoke: {
id: 'arctisprebook',
src: async (context, event) => {
console.log('arctisprebook');
console.log(context);
console.log(event);
return true;
},
onDone: 'ARCTIS_PREBOOKED',
onError: 'ERROR',
},
},
ARCTIS_PREBOOKED: {
meta: {
value: '0313',
},
on: {
SIGNATURE_OK: [
{
target: 'LEGITIMATION_REQUIRED',
cond: 'legitimationIsRequired',
},
{
target: 'TRANSACTION_AUTHORIZED',
cond: 'legitimationIsNotRequired',
},
],
SIGNATURE_NOK: 'LEGITIMATION_REQUIRED',
CANCEL: 'REJECTED',
},
},
LEGITIMATION_REQUIRED: {
meta: {
value: '0321',
},
on: {
LEGITIMATION_OK: 'TRANSACTION_AUTHORIZED',
LEGITIMATION_NOK: 'REJECTED',
CANCEL: 'REJECTED',
},
},
REJECTED: {
invoke: {
id: 'arctisDeletePrebook',
src: async (context, event) => {
console.log('arctisDeletePrebook');
console.log(context);
console.log(event);
return true;
},
onDone: 'CANCELED',
onError: 'ERROR',
},
},
TRANSACTION_AUTHORIZED: {
meta: {
value: '0322',
},
on: {
NEXT: 'ARCTIS_BOOKING',
CANCEL: 'REJECTED',
},
},
ARCTIS_BOOKING: {
meta: {
value: '0501',
},
invoke: {
id: 'arctisExecute',
src: async (context, event) => {
console.log('arctisExecute');
console.log(context);
console.log(event);
return true;
},
onDone: 'CLOSED',
onError: 'ERROR',
},
},
CLOSED: {
meta: {
value: '0502',
},
type: 'final',
},
ABORTED: {
meta: {
value: '0701',
},
type: 'final',
},
CANCELED: {
meta: {
value: '0702',
},
type: 'final',
},
ERROR: {
meta: {
value: '0901',
},
type: 'final',
},
},
},
{
guards: {
accountIsCovered: (context, event) => {
console.log('accountIsCovered: ' + event.type);
return true;
},
accountIsNotCovered: (context, event) => {
console.log('accountIsNotCovered: ' + event.type);
return false;
},
receiverDataIsValid: (context, event) => {
console.log('receiverDataIsValid: ' + event.type);
return true;
},
receiverDataIsNotValid: (context, event) => {
console.log('receiverDataIsNotValid: ' + event.type);
return false;
},
legitimationIsRequired: (context, event) => {
console.log('legitimationIsRequired: ' + event.type);
return true;
},
legitimationIsNotRequired: (context, event) => {
console.log('legitimationIsNotRequired: ' + event.type);
return false;
},
},
services: {
arctisCoverageCheck: async (context, event) => {
console.log('arctisCoverageCheck: ' + event.type);
return true;
},
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment