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.

1 Answer 1

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..

5
  • Not work then also use this ...magento.stackexchange.com/questions/94480/… Jun 30, 2016 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, 2016 at 8:36
  • yes. method-renderer/SomeName-method.js Jun 30, 2016 at 12:52
  • hi i have encounter a new problem, feel free to have a look stackoverflow.com/questions/38319940/…
    – Tine
    Jul 12, 2016 at 4:30
  • delete var folder..then check, Jul 12, 2016 at 4:44

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.