public function process_sagepay()
 {
     // pass the card and billing data to a static method in the
     // sagepay class to be formatted and returned.
     $data = SagePay::formatRawData($_POST);
     $validator = new Validator($data);
     $validator->filledIn("BillingFirstnames");
     $validator->filledIn("BillingSurname");
     $validator->filledIn("BillingAddress1");
     $validator->filledIn("BillingCity");
     $validator->filledIn("BillingCountry");
     $validator->filledIn("CardType");
     $validator->filledIn("CardNumber");
     $validator->filledIn("CV2");
     $validator->filledIn("ExpiryDateMonth");
     $validator->filledIn("ExpiryDateYear");
     $validator->filledIn("Amount");
     $errors = $validator->getErrors();
     $id = $validator->getId();
     $error_message = array('BillingFirstnames' => 'First name can not be left blank', 'BillingSurname' => 'Last name can not be left blank', 'BillingAddress1' => 'Address can not be left blank', 'BillingCity' => 'City can not be left blank', 'BillingCountry' => 'Country can not be left blank', 'Amount' => 'Amount can not be left blank', 'CardNumber' => 'Card number can not be left blank', 'ExpiryDateMonth' => 'Expiry month can not be left blank', 'ExpiryDateYear' => 'Expiry year can not be left blank', 'CardType' => 'Card type can not be left blank', 'CV2' => 'CV2 can not be left blank');
     if (!empty($errors)) {
         echo "Error:<br>";
         foreach ($errors as $key => $value) {
             echo $error_message[$key] . "<br>";
         }
         exit;
     }
     $description = isset($_SESSION['SAGEPAY_DATA']['description']) ? $_SESSION['SAGEPAY_DATA']['description'] : '';
     if (!empty($description)) {
         $data['description'] = $description;
     }
     // instantiate the SagePay object, passing it this formatted data.
     $payment = new SagePay($data);
     // execute the payment request
     $payment->execute();
     if ($payment->status == '3dAuth') {
         // SagePay has returned a request for 3DSecure authentication
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['acsurl'] = $payment->acsurl;
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['pareq'] = $payment->pareq;
         // Store the transaction code that you set for passing to 3DSecure
         $_SESSION['payment']['vendorTxCode'] = $payment->vendorTxCode;
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['md'] = $payment->md;
         // set a flag so your code knows to load the 3D Secure page.
         $secure_auth = true;
         echo "3dAuth";
         exit;
     } else {
         if ($payment->status == 'success') {
             // Transaction successful. Redirect to your complete page
             echo "success";
             exit;
         } else {
             echo $_SESSION['error'] = $payment->error;
         }
     }
 }