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?
Magento 2.1.5 – Redirect User to Payment Gateway After Order
checkoutmagento2.1.5paymentpayment-gatewaypayment-methods
Best Answer
This is the observer code to redirect to that payment gateway.
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="http://127.0.0.1/payment/smoovpay/index/response" /> <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> </form> <script type="text/javascript"> //<![CDATA[ var paymentform = document.getElementById('custom_payment'); window.onload = paymentform.submit(); //]]> </script>