public function process($data) { //Construct the request $request = new PxPayRequest(); $request->setAmountInput($data['Amount']); $request->setCurrencyInput($data['Currency']); //Set PxPay properties if (isset($data['Reference'])) { $request->setMerchantReference($data['Reference']); } if (isset($data['EmailAddress'])) { $request->setEmailAddress($data['EmailAddress']); } $request->setUrlFail($this->cancelURL); $request->setUrlSuccess($this->returnURL); //Generate a unique identifier for the transaction $request->setTxnId(uniqid('ID')); $request->setTxnType('Purchase'); //Get encrypted URL from DPS to redirect the user to $request_string = $this->makeProcessRequest($request, $data); //Obtain output XML $response = new MifMessage($request_string); //Parse output XML $url = $response->get_element_text('URI'); $valid = $response->get_attribute('valid'); //If this is a fail or incomplete (cannot reach gateway) then mark payment accordingly and redirect to payment if ($valid && is_numeric($valid) && $valid == 1) { //Redirect to payment page Controller::curr()->redirect($url); } else { if (is_numeric($valid) && $valid == 0) { return new PaymentGateway_Failure(); } else { return new PaymentGateway_Incomplete(); } } }
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); }
$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);
function startPaymentProcess() { if (!$this->TxnId) { $this->TxnId = uniqid("ID"); } $request = new PxPayRequest(); #Set PxPay properties if ($this->MerchantReference) { $request->setMerchantReference($this->MerchantReference); } else { user_error("error in DpsPxPayComs::startPaymentProcess, MerchantReference not set. ", E_USER_WARNING); } if ($this->AmountInput) { $request->setAmountInput($this->AmountInput); } else { user_error("error in DpsPxPayComs::startPaymentProcess, AmountInput not set. ", E_USER_WARNING); } if ($this->TxnData1) { $request->setTxnData1($this->TxnData1); } if ($this->TxnData2) { $request->setTxnData2($this->TxnData2); } if ($this->TxnData3) { $request->setTxnData3($this->TxnData3); } if ($this->TxnType) { $request->setTxnType($this->TxnType); } else { user_error("error in DpsPxPayComs::startPaymentProcess, TxnType not set. ", E_USER_WARNING); } if ($this->CurrencyInput) { $request->setCurrencyInput($this->CurrencyInput); } else { user_error("error in DpsPxPayComs::startPaymentProcess, CurrencyInput not set. ", E_USER_WARNING); } if ($this->EmailAddress) { $request->setEmailAddress($this->EmailAddress); } if ($this->UrlFail) { $request->setUrlFail($this->UrlFail); } else { user_error("error in DpsPxPayComs::startPaymentProcess, UrlFail not set. ", E_USER_WARNING); } if ($this->UrlSuccess) { $request->setUrlSuccess($this->UrlSuccess); } else { user_error("error in DpsPxPayComs::startPaymentProcess, UrlSuccess not set. ", E_USER_WARNING); } if ($this->TxnId) { $request->setTxnId($this->TxnId); } if ($this->EnableAddBillCard) { $request->setEnableAddBillCard($this->EnableAddBillCard); } if ($this->BillingId) { $request->setBillingId($this->BillingId); } /* TODO: $request->setEnableAddBillCard($EnableAddBillCard); $request->setBillingId($BillingId); $request->setOpt($Opt); */ #Call makeRequest function to obtain input XML $request_string = $this->PxPayObject->makeRequest($request); #Obtain output XML $this->response = new MifMessage($request_string); #Parse output XML $url = $this->response->get_element_text("URI"); //$valid = $this->response->get_attribute("valid"); #Redirect to payment page return $url; }