Magento – Magento 2 Redirect user to a custom payment method from a custom page

magento-2.1magento2payment-methods

i am trying to redirect a user to a custom offline payment method that i have created form one of my phtml file using a button click.

my payment method name is pay by cash.

I have a template where i am listing all the orders.

I want to redirect user to the Pay by Cash payment method and automatically do a place order by Pay by cash method on button click.

please help ! how i can do that.

Best Answer

in your "method-renderer" you can redirect to your controller action and from there you can render you phtml template :

file location :

Company/Module/view/frontend/web/js/view/payment/method-renderer/paymentname-method.js

code example :

return Component.extend({
       defaults: {
           template: 'compnay_method/payment/paybycash',
                redirectAfterPlaceOrder: false
         },

         /** Returns send check to info */
         getMailingAddress: function() {
             return window.checkoutConfig.payment.checkmo.mailingAddress;
         },
         afterPlaceOrder: function (data, event) {
             // Redirect to your controller action after place order button click
             window.location.replace(url.build('routename/index'));

         }

    });
Related Topic