Hi I'm in the process of adding a custom payment ...
# support
a
Hi I'm in the process of adding a custom payment method, which requires the user to be redirected to the payment gateway for payment capture. A quick description of the happy-path workflow - which I believe is fairly common - is: 1. Developer posts details of transaction to payment gateway along with
notification_url
and
return_url
2. If the transaction is successful the payment gateway POSTs to
notification_url
3. If the payment gateway receives a
200
from above POST it redirects the user to
return_url
Solidus provides an easy way to write a custom payment method by allowing - among other things - the developer to add a partial for the custom payment method. This works really well for on site payments or payments that will be captured manually. In my case I've setup it up like this: • In the partial I'm overriding the
checkout_form_payment
form's
action
attribute to point to the payment gateway's site instead of the
checkout_controller
• I've added a custom controller which serves as the endpoint for the payment gateway's
notification_url
where I capture payment source details and progress the state of the
order
like it would have happened in the original
checkout_controller
• I return the user to the
/checkout/confirm
(since this is the next state) page via the
return_url
upon successful transaction My issues with that workflow are: • capturing the payment happens before the user has "confirmed" the order, so a scenario can play out where the user successfully completes the transaction on the payment gateway's site, closes their browser, and then the order isn't really "completed" • I can take another path and simply update the order all the way to "completed" when the payment gateway sends notification of a successful transaction, but then the user doesn't get to "confirm" the order after reviewing it (we skip the
/checkout/confirm
page) Ideally I would like to only redirect to the payment gateway when the user confirms the order. As far as I can tell there is no "neat and tidy" way of overriding the confirmation portion of the checkout workflow like the payment method part. I know I could just override the entire
_confirm
partial, but as I would like to add the payment gateway as a gem for others to use, I'm guessing this isn't necessarily the best route to take. Could anyone shed any advice on a better way to handle this kind of off-site custom payment method? Thanks!
c
👋 You can customize checkout by removing confirm step https://edgeguides.solidus.io/cookbook/redefining-checkout-steps or just process the offsite payment after user click on confirm button
a
Thanks. I've had a look at those options. I'd prefer not to remove a step as I want to create the custom payment method as a gem, so I don't want to mess with Solidus code too much. The problem with doing something after the confirmation step is that the order is already marked as complete at this point (unless you mess with the Solidus code again), and I'd prefer to have the confirmation+payment done together, though it seems like the only way I'm going to get that is by overriding the
confirm
partial. I'll dig around a little more.
c
I mean that you can do your process before send the request to confirm the order. You can add some js to prevent send the confirm request when click on the button, do your offsite process and then send confirm request and complete order
a
Hmm, yeah that's what I'm aiming for. Where would one add that js though? I assume I'd have to override the
confirm
partial as opposed to adding an additional step. On second thought, perhaps I could add an additional step, have the new step's partial just render the
confirm
partial but with the overriding js included, and then mark the order as completed on successful transaction.
c
You can add your js in your assets folder and make it execute if the button is present (I think it has a class or id which you can use to find if present). If you add a new step, this step will render your step partial and do transitions to other steps according your customizations in order's state machine