Reactor and webhook

I'm trying out reactor, specifically for a payment flow. Before it, using stripity stripe, I created a session Stripe.Checkout.Session.create, redirected external session url. Then there's a webhook controller that constructs an event Stripe.Webhook.construct_event. how would that work using reactor flow? :thinkies: I'm guessing capture payment step should handle the webhook part, but I'm not understanding how would I plug the two? Is this even a valid use case for reactor 😬
Solution:
You could have a resource that you call actions on that runs the reactor and saves the state after it halted and than have an update action that you can call that than runs the next part of the reactor with the saved state. and use the session id as the id for the resource
Jump to solution
14 Replies
ken-kost
ken-kostOP4mo ago
when user clicks order part of the flow would have to be executed, then the payment is handled on the stripe side, then the flow continues over the webhook.? does this even make sense? 😄 wait, maybe the solution is to have two flows? 🤔 one or triggering the order, second for handling the order. maybe that? :thinkies:
barnabasj
barnabasj4mo ago
you can halt a reactor after a step you get an back the current state of the reactor and you can continue the reactor with that at a later point.
ken-kost
ken-kostOP4mo ago
interesting... how would I get it in the webhook controller thou? for instance the create session gives a session id which I store in the order and through that id in the webhook controller I can get the appropriate order and update it. wait a minute... there's Reactor.Req 🤯 could I use that to replace the post "/webhook", WebhookController, :handle? probably not 🤔 yea, I'm just confused. in any case, if the key is the session id, then somehow I would have to get the state through that? is that even possible without doing something crazy? is my use case even valid for one reactor flow? or should I split it or have only one that starts on the webhook? looking for advice 🙏
Solution
barnabasj
barnabasj4mo ago
You could have a resource that you call actions on that runs the reactor and saves the state after it halted and than have an update action that you can call that than runs the next part of the reactor with the saved state. and use the session id as the id for the resource
barnabasj
barnabasj4mo ago
It's been a while since I did a stripe checkout and the last time I did it I just used Oban Jobs to do the processing no reactor
ken-kost
ken-kostOP4mo ago
interesting. thank you for the tips. 🙇 I was able to execute my first reactor flow 🎉 it's only from order id -> order -> session but I think I'll just construct another flow that starts from session id -> order -> other work maybe I'll combine them later using your idea if it's gonna make sense. I'm really digging the reactor 😎
ken-kost
ken-kostOP4mo ago
that hook wasn't even in use 🤦‍♂️ I'm such an idiot. but it's fine, my plan still works, stripe triggers the success route where I can begin a new flow
jart
jart4mo ago
This is great news. I’m glad that the new documentation is helping.
ken-kost
ken-kostOP4mo ago
it really helps to get into it
jart
jart4mo ago
Regarding the web hook I think I prefer the two reactor solution but if you really need to be able to undo then you could have a step that subscribes to a pubsub topic and have it sit in receive with a timeout that works (maybe like 5 minutes?) and have the controller publish the webhook payload
ken-kost
ken-kostOP4mo ago
yeah, I'm going with two, thanks for confirming 🤠
jart
jart4mo ago
That suggestion seems pretty brittle now that I read it back.
ken-kost
ken-kostOP4mo ago
since the middle is handled by stripe...
jart
jart4mo ago
I’ve definitely found that lots of small reactors is the way to go because you can compose them.

Did you find this page helpful?