0

I am trying to convert an existing custom third party payment module for Magento 1.x to Magento 2.0.

However, when comes to redirecting the user to the third party payment gateway, the getOrderPlaceRedirectUrl in my Model\SomeName.php doesn't seems like working. Some suggested that replacing some codes in the /view/frontend/web/js/view/payment/method-renderer/SomeName-method.js for the redirect function.

Would like to clarify is it true that getOrderPlaceRedirectUrl doesn't work in Magento 2.0. Many thanks.

0
  1. view/frontend/web/js/view/payment/method-renderer/SomeName-method.js

    /*browser:true*/
    /*global define*/
    define(
         [
            'jquery',
            'Magento_Checkout/js/view/payment/default',
            'Magento_Checkout/js/model/payment/additional-validators'
        ],
        function ($, Component, additionalValidators) {
            'use strict';
            return Component.extend({
                defaults: {
                    template: 'Test_Payment/payment/default'
                },
                getInstructions: function () {
                    return window.checkoutConfig.payment.instructions[this.item.method];
                },
                getPaymentIcon: function(){
                    return window.checkoutConfig.payment.icon[this.item.method];
                },
                afterPlaceOrder: function () {
                    $.mage.redirect('/test/checkout/redirect');
                },
            });
        }
    );
    
  2. create controller\checkout\redirect.php

    public function execute()
    {
        try {
            $order = $this->_getCheckoutSession()->getLastRealOrder();
    
            $method = $order->getPayment()->getMethod();
    
            $methodInstance = $this->_paymentHelper->getMethodInstance($method);
            if ($methodInstance instanceof \Test\Payment\Model\Paymentmethod\Paymentmethod) {
                $redirectUrl = $methodInstance->startTransaction($order, $this->_url);
                $this->_redirect($redirectUrl);
            } else {
                throw new Error('Method is not a Test payment method');
            }
    
        } catch (\Exception $e) {
            $this->messageManager->addException($e, __('Something went wrong, please try again later'));
            $this->_logger->critical($e);
            $this->_getCheckoutSession()->restoreQuote();
            $this->_redirect('checkout/cart');
        }
    }
    

Hope Help..

|improve this answer|||||
  • Not work then also use this ...magento.stackexchange.com/questions/94480/… – Magento2 Devloper Jun 30 '16 at 8:07
  • /browser:true/ /global define/ define( [ 'jquery', 'Magento_Checkout/js/view/payment/default', ... Component.extend({ defaults: { template: 'Test_Payment/payment/default' }, getInstructions: function () { return window.checkoutConfig.payment.instructions[this.item.method]; }, getPaymentIcon: function(){ return window.checkoutConfig.payment.icon[this.item.method]; }, afterPlaceOrder: function () { $.mage.redirect('/test/checkout/redirect'); }, }); } ); where do i place this? in the /method-renderer/SomeName-method.js? – Tine Jun 30 '16 at 8:36
  • yes. method-renderer/SomeName-method.js – Magento2 Devloper Jun 30 '16 at 12:52
  • hi i have encounter a new problem, feel free to have a look stackoverflow.com/questions/38319940/… – Tine Jul 12 '16 at 4:30
  • delete var folder..then check, – Magento2 Devloper Jul 12 '16 at 4:44

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.