2

I am developing a module for a payment gateway.

  1. I created module skeleton using module creator provided here.
  2. I used redirection solution given in this.
  3. I wrote custom controller where it is getting redirect.

Now in my custom controller I need to create data to post on the payment gateway and then will post that data to the payment gateway url. Here I need order data which I and not getting in checkout session. I referred other extension they are using similar method but I am not getting any data.

protected function _getOrder()
{
if (!$this->_order) {

    $incrementId = $this->_getCheckout()->getLastRealOrderId();
    var_dump($incrementId);
    $this->_orderFactory = $this->_objectManager->get('Magento\Sales\Model\OrderFactory');
    $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
return $this->_order;
}


protected function _getCheckout() {
    return $this->_objectManager->get('Magento\Checkout\Model\Session');
}
1

I tried the Payment Gateway module generator from the link you provided before, but it did not seem to work as I hope. Perhaps, it may obsolete?

What I ended up doing is to use Magento 2 sample payment gateway code as a base code, then I traced into the workflow of PayPal, particular the Express Checkout where it will redirect the user to PayPal after the user click on checkout, then will be return to the successful page after PayPal payment has been authorized.

In a nutshell, what it does is on the JavaScript method renderer code, it will set up a payment method and then redirect to a controller action "Start", which will construct the payload and make API call to the service endpoint and then redirect the user to the target URL on the payment site with some sort of tokens. The Payment site will then return back to the merchant site controller action "Return", which will validate the result and then place order along with setting relevant payment info/status on that order.

Hope that helps,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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