I am creating my own payment method which should redirect user to the payment gateway of a bank after placing order. How can I do it?

  • Please create sales order place after observer and do your redirection. First that order will be in pending status after the payment you need to change that payment to processing. Commented Nov 30, 2017 at 7:46
  • Did you find the perfect solution to it ? If yes please let me know as the one i have created doesn't pass the default TnC value to the "set-payment-information" Commented Oct 18, 2018 at 13:17

1 Answer 1


This is the observer code to redirect to that payment gateway.

public function execute(\Magento\Framework\Event\Observer $observer)
    $orderId = $observer->getEvent()->getOrderIds();
    $base_url = $this->_storeManager->getStore()->getBaseUrl();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId[0]);
    $payment = $order->getPayment();
    $method = $payment->getMethodInstance();
    $methodTitle = $method->getTitle();
    $order_data= $order->getData();
    $status = $this->checkoutSession->getLastOrderStatus();

    $increment_id = $order_data['increment_id'];
    $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');

My Controller having load layout and render layout only please find my phtml file for that controller it'll auto submit and redirect to payment gateway,

<form action="<?php echo $this->getModeurl();?>" id="custom_payment" method="post">
    <input type="hidden" name="action" value="pay" />
    <input type="hidden" name="currency" value="<?php echo $this->getOrderdetails('order_currency_code');?>" />
    <input type="hidden" name="version" value="2.0" />
    <input type="hidden" name="item_name_<?php echo $i ?>" value="<?php echo $item['name'] ?>" />
    <input type="hidden" name="item_description_<?php echo $i ?>" value="<?php echo $item['description'] ?>" />
    <input type="hidden" name="item_quantity_<?php echo $i ?>" value="<?php echo round($item['quantity']) ?>" />
    <input type="hidden" name="item_amount_<?php echo $i ?>" value="<?php echo $item['price'] ?>" /> 
    <input type="hidden" name="merchant" value="<?php echo $this->getMerchant();?>" />
    <input type="hidden" name="ref_id" value="<?php echo $this->getOrderdetails('increment_id');?>" />
    <input type="hidden" name="delivery_charge" value="<?php echo $this->getOrderdetails('shipping_amount');?>" />
    <input type="hidden" name="tax_amount" value="<?php echo $this->getOrderdetails('tax_amount');?>" />
    <input type="hidden" name="total_amount" value="<?php echo $this->getOrderdetails('grand_total');?>" />
    <input type="hidden" name="str_url" value="" />
    <input type="hidden" name="success_url" value="" />
    <input type="hidden" name="cancel_url" value="http://YourWebSite" />
    <input type="hidden" name="signature" value="<?php echo $this->getSignatureHash();?>"/>
    <input type="hidden" name="signature_algorithm" value="sha1" />
    <h3>Please wait we are redirecting to Smoovpay.....</h3>
<script type="text/javascript">
    var paymentform = document.getElementById('custom_payment');
    window.onload = paymentform.submit();
  • thanks for your answer. It seems like you are redirecting user to my own stores's url How am I supposed to communicate with payment gateway's API.
    – P S
    Commented Nov 30, 2017 at 8:16
  • For that i written code in my own controller , I don't know which payment your using. I did like it'll redirect to my own controller in that controller i formed payment params that one redirect to payment gateway Commented Nov 30, 2017 at 9:02
  • Could you please share a small snippet of your controller code.
    – P S
    Commented Nov 30, 2017 at 9:11
  • Check the update above, Create corresponding block and controller i just added phtml file for redirection. Still have clarification means tell me Commented Nov 30, 2017 at 9:25
  • Thank you I checked it. Have you done payment method in which credit card info are entered in checkout page?
    – P S
    Commented Nov 30, 2017 at 9:28

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.