Skip to content

Magento 2 Payment Gateway Method Approach

Overview:

I’m creating my own payment method, this method redirects to an external page where customer needs to place credit card details. This page has SuccessURL (on Success payment action), BackURL (back action) and FailureURL (if payment failed action).

So how should i implement the payment gateway?

  1. First should i use Authorize and then capture separately or should i use sale (authorize & capture) ?

  2. I had already create some kind of payment gateway i did Authorization method that does a call to my API (backoffice) where it creates reference and all payment details. Then i redirect to external page for payment if successful it triggers SuccessURL that redirect to magento store custom controller where it calls capture method. This method checks in my API if reference is paid and redirects to chekout/onepage/success, but i have problem that is when customer decides to pay later the session is no longer active and try’s to call chekout/onepage/success but this page will redirect to empty cart because it will not be the same session as before & the order will already created. How do i fix this, and what if is a guest user?

  3. Instead of doing the approach mention on 2nd point do you guys know a better approach?~

  4. As another approach I was thinking about “forcing payment before placing order
    Ex: Customer places order then is redirected to external payment page
    if succesURL is triggered then comes to a callback and creates and
    pays order, if backURL is triggerd it comes Back to cart since order hasn’t been created the cart will not be empty, if it fails i can redirect to checkout/onepage/failed, what do you guys think? and what Event should i use for this case is there an event where customer click on place order and before creating order i can execute all of this? (some berfore_place_order event)?

  5. In my first approach (2nd point) my payment page is only available for 1 hour in order to check if payment has been paid or it expired should i use and observer or create a cron Job to check my API ? by doing this check then i can change order status from pending to processing or canceld.