public function callback($request)
    {
        $this->extend('onBeforeCallback');
        
        $data = $this->request->postVars();
        $status = "error";
        $order_id = 0;
        $payment_id = 0;

        $error_url = Controller::join_links(
            Director::absoluteBaseURL(),
            Payment_Controller::config()->url_segment,
            'complete',
            'error'
        );

        $vars = array(
            "SiteConfig" => SiteConfig::current_site_config(),
            "RedirectURL" => $error_url
        );

        // Check if CallBack data exists and install id matches the saved ID
        if (
            isset($data) && // Data and order are set
            (isset($data['instId']) && isset($data['cartId']) && isset($data['transStatus']) && isset($data["callbackPW"])) && // check required
            $this->payment_gateway->InstallID == $data['instId'] && // The current install ID matches the postback ID
            $this->payment_gateway->ResponsePassword == $data["callbackPW"]
        ) {
            $order_id = $data['cartId'];
            $payment_id = $data['transId'];
            $status = $data['transStatus'];
            
            $success_url = Controller::join_links(
                Director::absoluteBaseURL(),
                Payment_Controller::config()->url_segment,
                'complete',
                $order_id
            );

            if ($data['transStatus'] == 'Y') {
                $status = 'paid';
                $vars["RedirectURL"] = $success_url;
            } else {
                $status = 'failed';
            }
        } else {
            return $this->httpError(500);
        }
        
        $payment_data = ArrayData::array_to_object(array(
            "OrderID" => $order_id,
            "PaymentProvider" => "WorldPay",
            "PaymentID" => $payment_id,
            "Status" => $status,
            "GatewayData" => $data
        ));
        
        $this
            ->setPaymentData($payment_data)
            ->customise($vars);
        
        $this->extend('onAfterCallback');
        
        return $this->renderWith(array("Worldpay_callback"));
    }
public function callback($request)
    {
        $this->extend('onBeforeCallback');
        
        $data = $this->request->postVars();
        $status = "error";
        $order_id = 0;
        $payment_id = 0;

        $error_url = Controller::join_links(
            Director::absoluteBaseURL(),
            Payment_Controller::config()->url_segment,
            'complete',
            'error'
        );

        $vars = array(
            "SiteConfig" => SiteConfig::current_site_config(),
            "RedirectURL" => $error_url
        );

        // Check if CallBack data exists and install id matches the saved ID
        if (
            isset($data) && // Data and order are set
            (isset($data['instId']) && isset($data['cartId']) && isset($data['transStatus']) && isset($data["callbackPW"])) && // check required
            $this->payment_gateway->InstallID == $data['instId'] && // The current install ID matches the postback ID
            $this->payment_gateway->ResponsePassword == $data["callbackPW"]
        ) {
            $order_id = $data['cartId'];
            $payment_id = $data['transId'];
            $status = $data['transStatus'];
            
            $success_url = Controller::join_links(
                Director::absoluteBaseURL(),
                Payment_Controller::config()->url_segment,
                'complete',
                $order_id
            );

            if ($data['transStatus'] == 'Y') {
                $status = 'paid';
                $vars["RedirectURL"] = $success_url;
            } else {
                $status = 'failed';
            }
        } else {
            return $this->httpError(500);
        }
        
        $payment_data = ArrayData::array_to_object(array(
            "OrderID" => $order_id,
            "PaymentProvider" => "WorldPay",
            "PaymentID" => $payment_id,
            "Status" => $status,
            "GatewayData" => $data
        ));
        
        $this
            ->setPaymentData($payment_data)
            ->customise($vars);
        
        $this->extend('onAfterCallback');
        
        return $this->renderWith(array("Worldpay_callback"));
    }
public function callback ( $ request ) { $ this -> extend ( 'onBeforeCallback' ) ; $ data = $ this -> request -> postVars ( ) ; $ status = "error" ; $ order_id = 0 ; $ payment_id = 0 ; $ error_url = Controller :: join_links ( Director :: absoluteBaseURL ( ) , Payment_Controller :: config ( ) -> url_segment , 'complete' , 'error' ) ; $ vars = array ( "SiteConfig" => SiteConfig :: current_site_config ( ) , "RedirectURL" => $ error_url ) ; // Check if CallBack data exists and install id matches the saved ID if ( isset ( $ data ) && // Data and order are set ( isset ( $ data [ 'instId' ] ) && isset ( $ data [ 'cartId' ] ) && isset ( $ data [ 'transStatus' ] ) && isset ( $ data [ "callbackPW" ] ) ) && // check required $ this -> payment_gateway -> InstallID == $ data [ 'instId' ] && // The current install ID matches the postback ID $ this -> payment_gateway -> ResponsePassword == $ data [ "callbackPW" ] ) { $ order_id = $ data [ 'cartId' ] ; $ payment_id = $ data [ 'transId' ] ; $ status = $ data [ 'transStatus' ] ; $ success_url = Controller :: join_links ( Director :: absoluteBaseURL ( ) , Payment_Controller :: config ( ) -> url_segment , 'complete' , $ order_id ) ; if ( $ data [ 'transStatus' ] == 'Y' ) { $ status = 'paid' ; $ vars [ "RedirectURL" ] = $ success_url ; } else { $ status = 'failed' ; } } else { return $ this -> httpError ( 500 ) ; } $ payment_data = ArrayData :: array_to_object ( array ( "OrderID" => $ order_id , "PaymentProvider" => "WorldPay" , "PaymentID" => $ payment_id , "Status" => $ status , "GatewayData" => $ data ) ) ; $ this -> setPaymentData ( $ payment_data ) -> customise ( $ vars ) ; $ this -> extend ( 'onAfterCallback' ) ; return $ this -> renderWith ( array ( "Worldpay_callback" ) ) ; }
Retrieve and process order data from the request
Retrieve and process order data from the request