Where to place my customer registration code in the order flow?

Hi, we are using direct payment and klarna app with litium 8 to handle payment for orders in litium.
After payment is completed but before order confirmation is diplayed we need to register the person via an external api and depending on the result of registration we want to display an orderconfirmation or en errormessage.

I want to place code that is called regardless if the customer loads the paymentprovicer successurl or not since for some reason not all customer that use klarna returns to load the checkout. This results in that they wont be registrered and the payment not capured or cancelled.

I also want to display a relevant errormessage in the checkout regarding the failed registration.

Litium accelerator checkout only has a check for cartContext.cart.confirmed. There is no check if the order or paymentstatus really is ok or not before redirecting to the confirmation.

I have tested with the registration in the inittoconfirmedstate transition but the order is not updated before checkoutloaded and redirected to orderconfirmation even if i fetch the order via orderservice in the checkoutcontroller.

Litium version: 8.14.2

Hi Jonas,

I am a bit confused about your text, but you write “I also want to display a relevant error message in the checkout regarding the failed registration” - so I assume you want to stay on checkout if registration of user fails. I also assume from your message, that its a requirement that payment is confirmed for the user registration to take place?

The only idea I have works only if you have some control over the external system with fields and logic:

Register the user with a cart validator when order is placed but have some flag/field on the user when it’s created to mark the registration as “incomplete” in external system. If the registration fails, you return a validation error, and user will stay on checkout page.

If this registration is successful, the order will proceed in klarna/directpay. If the user sticks around, the confirmation page will load as normal.

Then, you could register an event listener for the PaymentAuthorized-event. If triggered, you can mark the user as fully registered in the external system, since the payment is now authorized.

For cleaning up “incomplete” users if the payment is never authorized, you could listen for the PaymentAuthorizedDenied and other such events. Or just have a job that fetches recent orders and checks if payment is not authorized after a certain amount of time, you delete the “incomplete” user in API.

/Martin

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.