/**
  * Executed in form submission *before* anything
  * goes out to DPS.
  */
 public function processPayment($data, $form)
 {
     // generate a unique transaction ID
     $this->TxnID = DPSHostedPayment::generate_txn_id();
     $this->write();
     // generate request from thirdparty pxpayment classes
     $request = $this->prepareRequest($data);
     // decorate request (if necessary)
     $this->extend('prepareRequest', $request);
     // set currency
     $this->Currency = $request->getInputCurrency();
     // submit payment request to get the URL for redirection
     $pxpay = new PxPay(self::$pxPay_Url, self::$pxPay_Userid, self::$pxPay_Key);
     $request_string = $pxpay->makeRequest($request);
     $response = new MifMessage($request_string);
     $valid = $response->get_attribute("valid");
     // set status to pending
     if ($valid) {
         $this->Status = 'Pending';
         $this->write();
     }
     // MifMessage was clobbering ampersands on some environments; SimpleXMLElement is more robust
     $xml = new SimpleXMLElement($request_string);
     $urls = $xml->xpath('//URI');
     $url = $urls[0] . '';
     header("Location: " . $url);
     die;
 }
 /**
  * Executed in form submission *before* anything
  * goes out to DPS.
  */
 public function processPayment($data, $form)
 {
     // generate a unique transaction ID
     $this->TxnID = DPSHostedPayment::generate_txn_id();
     $this->write();
     // generate request from thirdparty pxpayment classes
     $request = $this->prepareRequest($data);
     // decorate request (if necessary)
     $this->extend('prepareRequest', $request);
     // set currency
     $this->Amount->Currency = $request->getInputCurrency();
     // submit payment request to get the URL for redirection
     $pxpay = new PxPay(self::$pxPay_Url, self::$pxPay_Userid, self::$pxPay_Key);
     $request_string = $pxpay->makeRequest($request);
     $response = new MifMessage($request_string);
     $url = $response->get_element_text("URI");
     $valid = $response->get_attribute("valid");
     // set status to pending
     if ($valid) {
         $this->Status = 'Pending';
         $this->write();
     }
     //provide iframe with payment gateway form in it
     if (self::$use_iframe) {
         return new Payment_Processing(array('Content' => "<iframe src =\"{$url}\" width=\"100%\" height=\"380\" frameborder=\"0\" name=\"payframe\"><a href=\"{$url}\">" . _t('DPSHostedPayment.CLICKHERE', "click here to pay") . "</a></iframe>"));
     }
     Director::redirect($url);
     return new Payment_Processing();
 }
 function doDPSHostedPayment($inputs, $payment)
 {
     $request = new PxPayRequest();
     foreach ($inputs as $element => $value) {
         $funcName = 'set' . $element;
         $request->{$funcName}($value);
     }
     // submit payment request to get the URL for redirection
     $pxpay = new PxPay(self::$pxPay_Url, self::$pxPay_Userid, self::$pxPay_Key);
     $request_string = $pxpay->makeRequest($request);
     $response = new MifMessage($request_string);
     $valid = $response->get_attribute("valid");
     if ($valid) {
         // MifMessage was clobbering ampersands on some environments; SimpleXMLElement is more robust
         $xml = new SimpleXMLElement($request_string);
         $urls = $xml->xpath('//URI');
         $url = $urls[0] . '';
         DB::getConn()->transactionEnd();
         if (self::$mode == "Unit_Test_Only") {
             return $url;
         } else {
             header("Location: " . $url);
             die;
         }
     } else {
         $payment->Message = "Invalid Request String";
         $payment->write();
     }
 }