How would I implement this exact logic in M2 with the new gateway API? https://github.com/ergopalpatel/Magento_Payment_Gateway_Skeleton


  1. Customer selects a custom payment method
  2. When 'Place Order' is clicked, customer is redirected to the external payment page with some additional POST data
  3. Payment page redirects on success/failure back to a specified magento controller, which processes the result

I had a look around and found that \Magento\Payment\Model\Method\Cc is deprecated and that you should use the gateway api. I read the articles by Max Pronko and https://www.maxpronko.com/blog/magento-2-payment-gateway-api and tried to analyze the sample magento module and Braintree module, but I just can't wrap my head around those, either too much or too little going on.

Where do I even start if I want to implement this flow with redirects? Is there a comprehensive documentation somewhere or a module implemented on the gateway API that does exactly what I need?


I dug into the Magento_Payment code and it seems like this kind flow is not supported at all, classes implementing the Magento\Payment\Gateway\Http\ClientInterface, which handle the requests and responses, seems to be only working with synchronous requests against a webapi.

So what are the options then? Use deprecated components?


Seems like using the Magento\Payment\Model\MethodInterface (which has an @api annotation, so I'm hoping it won't get deprecated anytime soon) and implementing your own logic for redirects/validations etc is the way to go as of now.

  • github.com/ergopalpatel/Magento_Payment_Gateway_Skeleton is not a Payment Gateway in Magento way. Please, look into Magento Payment Gateway sample module github.com/magento/magento2-samples/tree/master/…, also, you can find some details in magento.stackexchange.com/questions/121012/…
    – joni jones
    Commented Nov 18, 2016 at 17:12
  • I've already seen all those resources, the gateway api does not work with redirects and asynchronous requests, or I didn't figure out how to make it work, that's where I need help.
    – Eduard
    Commented Nov 18, 2016 at 19:41
  • Actually works, for example, Braintree has async requests to retrieve payment nonce or process additional validation, Braintree Paypal uses redirects for guest checkout.
    – joni jones
    Commented Nov 19, 2016 at 14:34
  • @Eduard, Kindly if you build your module structure, can share the code ?
    – Jsparo30
    Commented Aug 17, 2017 at 14:08
  • @Jsparo30 did you find any sollution for this
    – Mujahidh
    Commented Oct 23, 2018 at 10:53

1 Answer 1


In order to implement custom payment module with redirect you have to implement the following logic:

  1. Create Frontend logic responsible for rendering custom payment method with "Place Order" button.
  2. Configure payment method for "initialisation" during placing order, so Order will be placed with "Pending Payment" status.
  3. Once "place order" logic is executed and order is saved via default JavaScript Payment component you have to send WebAPI POST request to backend server (in case you need to send HTTP POST to a payment method before redirecting customer).

You should implement whole Payment Gateway infrastructure of classes:

  • Builders classes for pre-populating POST parameters for request
  • Handlers for processing response from payment gateway
  • Validators for verifying response from payment gateway
  • Custom commands in case GatewayCommand does not work for you and you need own processing logic when sending request to a payment provider.
  • New Magento/Payment/Model/Method/Adapter class is now a centric for payment integrations, it is a must have to configure it with custom commands.


  1. Retrieve result to custom JavaScript component from Web API call execution and then redirect Customer to a Payment page.
  2. Create controllers, 1 for success and second one for failure in case Payment provider allows to set 2 URLs for each state. If not, create 1 controller where depending on a validation and additional logic you need to add in order to change status and create "capture" or "authorise" payment render different layout updates "custompayment_success" or "custompayment_error".

Few clarifications:

  • Class Magento\Payment\Model\Method\Cc is indeed deprecated and should not be used.
  • Interface Magento\Payment\Gateway\Http\ClientInterface should be used for sending background requests to a payment gateway. There is even 2 implementations for ClientInterface

Should you have any questions please let me know.

  • can you please share redirect code?
    – Abdul
    Commented Apr 28, 2017 at 5:31
  • how to manage default magento 2 the Terms and Conditions checkbox value which has to be passed to the "set-payment-information" before redirecting to the external payment gateway ? Commented Oct 18, 2018 at 13:15
  • @MaxPronko should js component redirecting to external service contain any special logic for security reasons? Commented Jun 3, 2019 at 8:26
  • It should, in case Payment Service Provider gives some security features like token or authorization.
    – Max Pronko
    Commented Jun 4, 2019 at 14:11
  • @MaxPronko you mean from magento I should request external payment api for some token and redirect with it in params to this external payment page? Commented Jun 5, 2019 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.