Jump to content

How to redirect to success page after complete payment


Recommended Posts

Hi,

I created a custom payment module and process the payment. Once complete the payment I need to redirect to success page with proper validation . But its redirecting to login page instead of success page. please check code below and appreciate your support and feedback please

 

    if (isset($response['Transaction']['ResponseCode']) 
            && isset($response['Transaction']['ApprovalCode'])
            && ($response['Transaction']['ResponseCode'] == 0))
            { 
                  $amount = $this->context->cart->getOrderTotal();
                $amount = Tools::ps_round($amount, 2);
                $order = $this->createOrder($amount);
                $URL = Context::getContext()->link->getPageLink(
                    'order-confirmation',
                    true,
                    null,
                    [
                        'id_cart' => (int) $this->context->cart->id,
                        'id_module' => (int) $this->module->id,
                        'id_order' => (int) Order::getIdByCartId($this->context->cart->id),
                        'key' => $this->context->customer->secure_key,
                    ]
                );
                
                Tools::redirect($URL);
            }        

 

        public function createOrder(float $amount): ?Order
    {
        $order = null;

        if ($this->module->active
            && 0 != $this->context->cart->id_customer
            && 0 != $this->context->cart->id_address_delivery
            && 0 != $this->context->cart->id_address_invoice
            && Validate::isLoadedObject($this->context->customer)
            && in_array('EPG', array_column(Module::getPaymentModules(), 'name'))
        ) {
            if ($this->context->cart->orderExists()) {
                $order = new Order(Order::getIdByCartId($this->context->cart->id));
            } elseif ($this->module->validateOrder(
                    (int) $this->context->cart->id,
                    'Payment accepted',
                    $amount,
                    $this->module->displayName,
                    null,
                    [],
                    $this->context->cart->id_currency,
                    false,
                    $this->context->customer->secure_key
                )
                && !empty($this->module->currentOrder)
            ) {
                $order = new Order($this->module->currentOrder);
            }
        }
    
        return $order;
    
        }

 

Appreciate your support please

Link to comment
Share on other sites

I can't able to add SSL because I am developing custom payment module development on my system(localhost).

To inform you that, I am trying to redirecting prestashop success page from same custom module(view folder file) only not from any external page/site. 

Appreciated for your support. Looking for your further support to close the project as am stuck in the final stage

Edited by jafferpg (see edit history)
Link to comment
Share on other sites

@jafferpg@RhoburHi, I'm developing a same payment module as yours in localhost. But I'm new to prestashop 1.7 and I'm stuck at one place. I have made progress till the configuration page. Can you pls let me know how and where, I mean in which file you defined post parameters for request url and how to validate them? Do i have to call those parameters in tpl file or it should be defined in front controller and then whats the process after this? I tried to get some reference from prestashop payment example module but there is nothing about how to handle parameters for request url and it confuses me more. Pls help me pls. 🙏 Anyone's help will be much appreciated.

Edited by pg_dev (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...