Created
November 17, 2020 15:16
-
-
Save palra/7a2914e6c5c8971dcc93e313ca364460 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const paymentIntent = { | |
id: 'payment_intent', | |
initial: 'requires_payment_method', | |
states: { | |
requires_payment_method: { | |
on: { | |
STRIPE_PAYMENT_METHOD_SENT: 'processing', | |
STRIPE_PAYMENT_CANCELLED: 'cancelled', | |
} | |
}, | |
processing: { | |
on: { | |
STRIPE_PAYMENT_AUTHORIZED: 'authorized', | |
STRIPE_PAYMENT_DECLINED: 'requires_payment_method', | |
STRIPE_PAYMENT_CANCELLED: 'cancelled', | |
} | |
}, | |
authorized: { | |
entry: send('PAYMENT_AUTHORIZED'), | |
on: { | |
STRIPE_PAYMENT_CONFIRMED: 'confirmed', | |
STRIPE_PAYMENT_CANCELLED: 'cancelled', | |
} | |
}, | |
confirmed: { | |
type: 'final', | |
entry: sendParent('PAYMENT_CONFIRMED'), | |
}, | |
cancelled: { | |
type: 'final', | |
entry: sendParent('PAYMENT_CANCELLED'), | |
}, | |
} | |
} | |
const bid = Machine({ | |
id: 'bid', | |
initial: 'waiting_authorization', | |
states: { | |
waiting_authorization: { | |
on: { | |
PAYMENT_AUTHORIZED: 'placed' | |
}, | |
...paymentIntent, | |
}, | |
placed: { | |
on: { | |
BID_OUTDATED: 'outdated', | |
}, | |
}, | |
outdated: { | |
type: 'final', | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment