/** * Check that the payment was successful using "Process Response" API (http://www.paymentexpress.com/Technical_Resources/Ecommerce_Hosted/PxPay.aspx). * * @param SS_HTTPRequest $request Request from the gateway - transaction response * @return PaymentGateway_Result */ public function check($request) { $data = $request->getVars(); $url = $request->getVar('url'); $result = $request->getVar('result'); $userID = $request->getVar('userid'); //Construct the request to check the payment status $request = new PxPayLookupRequest(); $request->setResponse($result); //Get encrypted URL from DPS to redirect the user to $request_string = $this->makeCheckRequest($request, $data); //Obtain output XML $response = new MifMessage($request_string); //Parse output XML $success = $response->get_element_text('Success'); if ($success && is_numeric($success) && $success > 0) { return new PaymentGateway_Success(); } else { if (is_numeric($success) && $success == 0) { return new PaymentGateway_Failure(); } else { return new PaymentGateway_Incomplete(); } } }
/** * 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 redirect_form() { global $pxpay; $request = new PxPayRequest(); $http_host = getenv("HTTP_HOST"); $request_uri = getenv("SCRIPT_NAME"); $server_url = "http://{$http_host}"; #$script_url = "$server_url/$request_uri"; //using this code before PHP version 4.3.4 #$script_url = "$server_url$request_uri"; //Using this code after PHP version 4.3.4 $script_url = version_compare(PHP_VERSION, "4.3.4", ">=") ? "{$server_url}{$request_uri}" : "{$server_url}/{$request_uri}"; # the following variables are read from the form $Quantity = $_REQUEST["Quantity"]; $MerchantReference = $_REQUEST["Reference"]; $Address1 = $_REQUEST["Address1"]; $Address2 = $_REQUEST["Address2"]; $Address3 = $_REQUEST["Address3"]; #Calculate AmountInput $AmountInput = 19.95 * $Quantity; #Generate a unique identifier for the transaction $TxnId = uniqid("ID"); #Set PxPay properties $request->setMerchantReference($MerchantReference); $request->setAmountInput($AmountInput); $request->setTxnData1($Address1); $request->setTxnData2($Address2); $request->setTxnData3($Address3); $request->setTxnType("Purchase"); $request->setCurrencyInput("NZD"); $request->setEmailAddress("*****@*****.**"); $request->setUrlFail($script_url); # can be a dedicated failure page $request->setUrlSuccess($script_url); # can be a dedicated success page $request->setTxnId($TxnId); #The following properties are not used in this case # $request->setEnableAddBillCard($EnableAddBillCard); # $request->setBillingId($BillingId); # $request->setOpt($Opt); #Call makeRequest function to obtain input XML $request_string = $pxpay->makeRequest($request); #Obtain output XML $response = new MifMessage($request_string); #Parse output XML $url = $response->get_element_text("URI"); $valid = $response->get_attribute("valid"); #Redirect to payment page header("Location: " . $url); }
function PxPayResponse($xml) { $msg = new MifMessage($xml); $this->PxPayMessage(); $TS = $msg->get_element_text("C"); $expiryTS = $this->getExpiredTS(); if (strcmp($TS, $expiryTS) < 0) { $this->Success = "0"; $this->i = "Response TS out of range"; return; } $this->setBillingId($msg->get_element_text("t")); $this->setDpsBillingId($msg->get_element_text("u")); $this->setEmailAddress($msg->get_element_text("o")); $this->setMerchantReference($msg->get_element_text("j")); $this->setTxnData1($msg->get_element_text("k")); $this->setTxnData2($msg->get_element_text("l")); $this->setTxnData3($msg->get_element_text("m")); $this->setTxnType($msg->get_element_text("a")); $this->h = $msg->get_element_text("h"); $this->E = $msg->get_element_text("E"); $this->F = $msg->get_element_text("F"); $this->J = $msg->get_element_text("J"); $this->f = $msg->get_element_text("f"); $this->b = $msg->get_element_text("b"); $this->n = $msg->get_element_text("n"); $this->b = $msg->get_element_text("b"); $this->UserId = $msg->get_element_text("UserId"); $this->i = $msg->get_element_text("i"); $this->x = $msg->get_element_text("x"); $this->s = $msg->get_element_text("s"); $this->z = $msg->get_element_text("z"); $this->A = $msg->get_element_text("A"); $this->y = $msg->get_element_text("y"); $this->TS = $msg->get_element_text("C"); }
/** * 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; }
function PxPayResponse($xml) { $msg = new MifMessage($xml); $this->PxPayMessage(); $this->Success = $msg->get_element_text("Success"); $this->setTxnType($msg->get_element_text("TxnType")); $this->CurrencyInput = $msg->get_element_text("CurrencyInput"); $this->setMerchantReference($msg->get_element_text("MerchantReference")); $this->setTxnData1($msg->get_element_text("TxnData1")); $this->setTxnData2($msg->get_element_text("TxnData2")); $this->setTxnData3($msg->get_element_text("TxnData3")); $this->AuthCode = $msg->get_element_text("AuthCode"); $this->CardName = $msg->get_element_text("CardName"); $this->CardHolderName = $msg->get_element_text("CardHolderName"); $this->CardNumber = $msg->get_element_text("CardNumber"); $this->DateExpiry = $msg->get_element_text("DateExpiry"); $this->ClientInfo = $msg->get_element_text("ClientInfo"); $this->TxnId = $msg->get_element_text("TxnId"); $this->setEmailAddress($msg->get_element_text("EmailAddress")); $this->DpsTxnRef = $msg->get_element_text("DpsTxnRef"); $this->BillingId = $msg->get_element_text("BillingId"); $this->DpsBillingId = $msg->get_element_text("DpsBillingId"); $this->AmountSettlement = $msg->get_element_text("AmountSettlement"); $this->CurrencySettlement = $msg->get_element_text("CurrencySettlement"); $this->TxnMac = $msg->get_element_text("TxnMac"); $this->ResponseText = $msg->get_element_text("ResponseText"); }
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(); } }
function PxPayResponse($xml) { $msg = new MifMessage($xml); $this->PxPayMessage(); $TS = $msg->get_element_text("TS"); $expiryTS = $this->getExpiredTS(); if (strcmp($TS, $expiryTS) < 0) { $this->Success = "0"; $this->ResponseText = "Response TS out of range"; return; } $this->setBillingId($msg->get_element_text("BillingId")); $this->setDpsBillingId($msg->get_element_text("DpsBillingId")); $this->setEmailAddress($msg->get_element_text("EmailAddress")); $this->setMerchantReference($msg->get_element_text("MerchantReference")); $this->setTxnData1($msg->get_element_text("TxnData1")); $this->setTxnData2($msg->get_element_text("TxnData2")); $this->setTxnData3($msg->get_element_text("TxnData3")); $this->setTxnType($msg->get_element_text("TxnType")); $this->Success = $msg->get_element_text("Success"); $this->StatusRequired = $msg->get_element_text("StatusRequired"); $this->Retry = $msg->get_element_text("Retry"); $this->AuthCode = $msg->get_element_text("AuthCode"); $this->AmountSettlement = $msg->get_element_text("AmountSettlement"); $this->CurrencySettlement = $msg->get_element_text("CurrencySettlement"); $this->CardName = $msg->get_element_text("CardName"); $this->CurrencyInput = $msg->get_element_text("CurrencyInput"); $this->UserId = $msg->get_element_text("UserId"); $this->ResponseText = $msg->get_element_text("ResponseText"); $this->DpsTxnRef = $msg->get_element_text("DpsTxnRef"); $this->MerchantTxnId = $msg->get_element_text("MerchantTxnId"); $this->TS = $msg->get_element_text("TS"); }
$pxpay = new PxPay_Curl('https://sec.paymentexpress.com/pxpay/pxaccess.aspx', $PxPay_Userid, $PxPay_Key); //Create a new request object $request = new PxPayRequest(); //prepare the url to come back to once payment has been complete $http_host = getenv('HTTP_HOST'); //localhost. if online than domain name $folders = getenv('SCRIPT_NAME'); $urlToComeBackTo = 'http://' . $http_host . $folders; //loopthrough cart and calculate the grand total $grandTotal = 0; foreach ($_SESSION['cart'] as $cartItem) { $grandTotal += $cartItem['quantity'] * $cartItem['price']; } //prepare data for PxPay $request->setAmountInput($grandTotal); $request->setTxnType('Purchase'); //transaction type $request->setCurrencyInput('NZD'); $request->setUrlFail(PROJECT_ROOT . 'payment-response.php'); $request->setUrlSuccess(PROJECT_ROOT . 'payment-response.php'); $request->setTxnData1('Nehal Patel'); $request->setTxnData2('20 Kent Terrace, Wellington, NZ'); $request->setTxnData3('Somthing else'); //Prepare the request string out of the request data $requestString = $pxpay->makeRequest($request); //send the request to be processed $response = new MifMessage($requestString); //extract the url so we can redirect the user $urlToGoTo = $response->get_element_text('URI'); //redirect the user header('Location: ' . $urlToGoTo);
foreach ($_SESSION['cart'] as $product) { $productID = $product['id']; $quantity = $product['quantity']; $price = $product['price']; $sql = "INSERT INTO ordered_products VALUES(NULL, {$productID}, {$orderID}, {$quantity}, {$price})"; $dbc->query($sql); } // Include the pxpay library require 'PxPay_Curl.inc.php'; // Create instance if the pxpay class $pxpay = new PxPay_Curl('https://sec.paymentexpress.com/pxpay/pxaccess.aspx', PXPAY_USER, PXPAY_KEY); // Create instancce of request object $request = new PxPayRequest(); // get the text values of the city and suburb for the transaction // Populate the request with transaction details $request->setAmountInput($grandTotal); $request->setTxnType('Purchase'); $request->setCurrencyInput('NZD'); $request->setUrlSuccess('http://localhost/~jasana.mael/shopping-cart/transaction-success.php'); $request->setUrlFail('http://localhost/~jasana.mael/shopping-cart/transaction-fail.php'); $request->setTxnData1($_POST['full-name']); $request->setTxnData2($_POST['phone']); $request->setTxnData3($_POST['email']); // Convert the request object into XML $requestString = $pxpay->makeRequest($request); // Send the request away and wait for a response $response = new MifMessage($requestString); // Extract the URl from the response and redirect the user $url = $response->get_element_text('URI'); // Redirect our visitor header('Location: ' . $url);