local/modules/Klikandpay/Controller/KlikandpayFrontController.php
/**
     * Method used to change the status of an order when the payment
     * is accepted and if the marchant has configured a dynamic url
     * in the Klik & Pay's backoffice
     *
     * @return none
     */
Method used to change the status of an order when the payment
is accepted and if the marchant has configured a dynamic url
in the Klik & Pay's backoffice

@return none
Method used to change the status of an order when the payment is accepted and if the marchant has configured a dynamic url in the Klik & Pay ' s backoffice @return none
public function confirmAction()
    {
        try {
            $commande = $this->getRequest()->query->get('commande');
            $numxkp = $this->getRequest()->query->get('NUMXKP');
            $response = $this->getRequest()->query->get('RESPONSE');
            $montantxkp = $this->getRequest()->query->get('MONTANTXKP');
            if( empty($numxkp) || $response !== '00' )
            {
                throw new \Exception('Error with return parameters from Klik & Pay.');
            }
            $order = $this->findOrder($commande);
            $klikandpay = new Klikandpay();
            $parameters = $klikandpay->getParameters($montantxkp - $order->getPostage(), $order->getCustomer());
            $hash = $klikandpay->getHash($parameters, $order->getRef());
            if($hash !== $commande)
            {
                throw new \Exception("The secure hash does not match: " . $hash . " <> " . $commande);
            }
            if($order->getStatusId() !== OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId())
            {
                throw new \Exception("This order was already been paid: " . $order->getStatusId());
            }
            $event = new OrderEvent($order);
            $event->setStatus(OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID)->getId());
            $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS,$event);
            $order->setTransactionRef($numxkp);
            $order->save();
            $event = new KlikandpayReturnEvent(
                $this->getRequest()->query->get('DEVISEXKP'),
                $this->getRequest()->query->get('IPXKP'),
                $montantxkp,
                $numxkp,
                $order->getId(),
                $this->getRequest()->query->get('PAIEMENT'),
                $this->getRequest()->query->get('PAYSBXKP'),
                $this->getRequest()->query->get('PAYSRXKP'),
                $this->getRequest()->query->get('SCOREXKP'),
                $commande
            );
            $this->dispatch('action.createKlikandpayReturn', $event);
        } catch (\Exception $e) {
            $log = Tlog::getInstance();
            $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
            $log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, THELIA_ROOT."log".DS."log-klikandpay.txt");
            $log->error(sprintf('Klik&Pay confirmation page => URL: %s <> message: %s', $this->getRequest()->getUri() , $e->getMessage()));
            $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
        }
        die();
    }
public function confirmAction ( ) { try { $ commande = $ this -> getRequest ( ) -> query -> get ( 'commande' ) ; $ numxkp = $ this -> getRequest ( ) -> query -> get ( 'NUMXKP' ) ; $ response = $ this -> getRequest ( ) -> query -> get ( 'RESPONSE' ) ; $ montantxkp = $ this -> getRequest ( ) -> query -> get ( 'MONTANTXKP' ) ; if ( empty ( $ numxkp ) || $ response !== '00' ) { throw new \ Exception ( 'Error with return parameters from Klik & Pay.' ) ; } $ order = $ this -> findOrder ( $ commande ) ; $ klikandpay = new Klikandpay ( ) ; $ parameters = $ klikandpay -> getParameters ( $ montantxkp - $ order -> getPostage ( ) , $ order -> getCustomer ( ) ) ; $ hash = $ klikandpay -> getHash ( $ parameters , $ order -> getRef ( ) ) ; if ( $ hash !== $ commande ) { throw new \ Exception ( " The secure hash does not match:  " . $ hash . "  <>  " . $ commande ) ; } if ( $ order -> getStatusId ( ) !== OrderStatusQuery :: create ( ) -> findOneByCode ( OrderStatus :: CODE_NOT_PAID ) -> getId ( ) ) { throw new \ Exception ( " This order was already been paid:  " . $ order -> getStatusId ( ) ) ; } $ event = new OrderEvent ( $ order ) ; $ event -> setStatus ( OrderStatusQuery :: create ( ) -> findOneByCode ( OrderStatus :: CODE_PAID ) -> getId ( ) ) ; $ this -> dispatch ( TheliaEvents :: ORDER_UPDATE_STATUS , $ event ) ; $ order -> setTransactionRef ( $ numxkp ) ; $ order -> save ( ) ; $ event = new KlikandpayReturnEvent ( $ this -> getRequest ( ) -> query -> get ( 'DEVISEXKP' ) , $ this -> getRequest ( ) -> query -> get ( 'IPXKP' ) , $ montantxkp , $ numxkp , $ order -> getId ( ) , $ this -> getRequest ( ) -> query -> get ( 'PAIEMENT' ) , $ this -> getRequest ( ) -> query -> get ( 'PAYSBXKP' ) , $ this -> getRequest ( ) -> query -> get ( 'PAYSRXKP' ) , $ this -> getRequest ( ) -> query -> get ( 'SCOREXKP' ) , $ commande ) ; $ this -> dispatch ( 'action.createKlikandpayReturn' , $ event ) ; } catch ( \ Exception $ e ) { $ log = Tlog :: getInstance ( ) ; $ log -> setDestinations ( " \\ Thelia \\ Log \\ Destination \\ TlogDestinationFile " ) ; $ log -> setConfig ( " \\ Thelia \\ Log \\ Destination \\ TlogDestinationFile " , 0 , THELIA_ROOT . " log " . DS . " log-klikandpay.txt " ) ; $ log -> error ( sprintf ( 'Klik&Pay confirmation page => URL: %s <> message: %s' , $ this -> getRequest ( ) -> getUri ( ) , $ e -> getMessage ( ) ) ) ; $ log -> setDestinations ( " \\ Thelia \\ Log \\ Destination \\ TlogDestinationRotatingFile " ) ; } die ( ) ; }
Method used to change the status of an order when the payment
 is accepted and if the marchant has configured a dynamic url
 in the Klik & Pay's backoffice
Method used to change the status of an order when the payment is accepted and if the marchant has configured a dynamic url in the Klik & Pay ' s backoffice
// GET // Klik&Pay Transaction Number is mandatory and the response from Klik & Pay has to be equal to '00' // Retrieve the order // Hash (Total without shipping) // Verify if we can trust the transaction // Verify if we can trust the transaction // Set order status as PAID // Save Transaction number from Klik & Pay // Save all the return values from Klikandpay // Configure LOG for Klikandpay // Get log back to previous state // We don't need to render the view