I'm trying to integrate an online credit card payment service in Magento 2.2, but it's tough to understand all the docs on this topic at first, so I'm looking for some guidance.
What I need to achieve is to post several parameters like
error url etc. to the payment providers URL (form), where the customer can complete the credit card payment.
The provider handles all the security related stuff like storing and processing CC data.
This needs to happen when the customer presses the "Place order" button on checkout if this payment method is selected.
After the payment is complete, the customer should get redirected to the
success URL or
My attempts & research
I've created a working payment method so far and I've created a simple payment gateway based on:
the official docs http://devdocs.magento.com/guides/v2.2/payments-integrations/payment-gateway/payment-gateway-intro.html on how to create a payment gateway.
the official sample payment gateway https://github.com/magento/magento2-samples/tree/master/sample-module-payment-gateway
And I've looked at Paypal Express to see how they do it -> As far as I can tell, it calls a controller in
Module_Paypal/Controllers/Express/AbstractExpress/Start.php with the "Continue to Paypal" button.
Haven't gone into the details of Paypal's approach cause I'm just not sure if this is the right way to go about this...
What is the recommended way to post data and redirect customer to an external Payment processor/provider after an order is placed?
Should I go about it as per the official docs - to create a payment gateway? Or is there a better/easier approach?
If I need to create a payment gateway, do I need to use an authorize or capture command? (taking into account that I only need an order placed, no invoice processing is necessary)
Depending on the approach, I would like some guidance as to how to call the payment provider's payment-form URL, post data to it and redirect the customer to it after the "Place order" button is clicked.
Also any suggestions on how to call
checkout/onepage/successif the transaction was successful for the customer? Or should I redirect to a custom controller if the payment was (un)successful?
There is no complex API documentation, all I have to do is call the payment provider's URL with the
post method and pass some parameters to it.
For example, a simple html form would do the trick like this:
<form name="payment-provider-authorize-form" action="https://payment-provider.com/authorize-form" method="post" > <input type="hidden" name="shop_id" value="$shop_id" /> <input type="hidden" name="order_id" value="$cart_id" /> <input type="hidden" name="amount" value="$total" /> <input type="hidden" name="success_url" value="$success_url" /> ... <input type="submit" value="Buy with Custom Payment provider" /> </form>
I'm currently thinking of:
- redirecting the customer to the payment provider's url with
afterPlaceOrderfunction and getting the post data from system config through
- or redirecting to a custom controller with the
afterPlaceOrderfunction, getting all post parameters there and somehow redirecting to payment provider's url (if this is the way to go, a small code example on how to do this in the controller would be very helpful)
And again I'm still not sure where Magento's Payment gateway commands like
authorize fit into all of this. Do I even need them? Seems like they are meant for more complex integrations and aren't necessary in this situation...
@Joni Jones, could you please expand on your answer to question 4?
How would I post data with
$.mage.redirect(window.checkoutConfig.payment...)? My first thought was using $.post().
Also is the Web API
set-payment-information call really necessary even if I use the