18 define(
'DPS_LOG_FILE_PREFIX',
'dps_transactions_account_');
40 private static $_URL =
'https://sec.paymentexpress.com/pxpost.aspx';
48 private static $_test_account = Array(
49 'username' =>
'SquizLabsDev',
50 'password' =>
'd25wdfs6',
82 private $_card_number;
95 private $_card_expiry_date;
101 private $_card_start_date;
107 private $_card_issue_number;
120 private $_street_address;
133 private $_standard_policy = 0;
139 private $_test_mode = TRUE;
145 private $_log_file_name;
159 private $_success = FALSE;
167 private static $_TEST_CARD_NUMBERS = Array(
168 '4111111111111119' =>
'VISA',
169 '5431111111111111' =>
'MasterCard',
170 '371111111111114' =>
'Amex',
171 '36000000000008' =>
'Diners',
172 '4999999999999202' =>
'VISA(Declined)',
189 $this->_client = $client;
190 $this->_password = $password;
191 $this->_test_mode = $test_mode;
192 $this->_log_file_name = DPS_LOG_FILE_PREFIX.$this->_client.($test_mode?
'_test' :
'_live');
210 $this->_card_number = $card_no;
225 $this->_card_name = $name;
241 $this->_card_expiry_date = $month.$year;
256 $this->_card_start_date = $month.$year;
271 $this->_card_issue_number = $issue_no;
286 $this->_card_cv2 = $cv2;
302 $this->_street_address = $address;
317 $this->_postcode = $postcode;
336 $this->_amount = sprintf(
'%01.2f',$amount);
350 $this->_currency = $currency;
365 $this->_standard_policy = $policy;
380 return $this->_response;
394 $this->_sendRequest();
395 return $this->_success;
407 private function _sendRequest()
410 $this->_logRequest();
413 $client = $this->_test_mode ? self::$_test_account[
'username']: $this->_client;
414 $password = $this->_test_mode ? self::$_test_account[
'password']: $this->_password;
415 $enableAvs = ($this->_standard_policy != 0) ? 1 : 0;
416 $cmdDoTxnTransaction =
'';
417 $cmdDoTxnTransaction .=
"<Txn>";
418 $cmdDoTxnTransaction .=
"<PostUsername>$client</PostUsername>";
419 $cmdDoTxnTransaction .=
"<PostPassword>$password</PostPassword>"; #Insert your DPS Password here
420 $cmdDoTxnTransaction .=
"<Amount>$this->_amount</Amount>";
421 $cmdDoTxnTransaction .=
"<InputCurrency>$this->_currency</InputCurrency>";
422 $cmdDoTxnTransaction .=
"<CardHolderName>$this->_card_name</CardHolderName>";
423 $cmdDoTxnTransaction .=
"<CardNumber>$this->_card_number</CardNumber>";
424 $cmdDoTxnTransaction .=
"<DateExpiry>$this->_card_expiry_date</DateExpiry>";
425 $cmdDoTxnTransaction .=
"<TxnType>Purchase</TxnType>";
426 $cmdDoTxnTransaction .=
"<MerchantReference></MerchantReference>";
427 $cmdDoTxnTransaction .=
"<Cvc2>$this->_card_cv2</Cvc2>";
428 $cmdDoTxnTransaction .=
"<EnableAvsData>".$enableAvs.
"</EnableAvsData>";
429 $cmdDoTxnTransaction .=
"<AvsAction>$this->_standard_policy</AvsAction>";
430 $cmdDoTxnTransaction .=
"</Txn>";
434 'POSTFIELDS' => $cmdDoTxnTransaction,
435 'RETURNTRANSFER' => 1,
436 'SSL_VERIFYPEER' => 1,
437 'SSL_VERIFYHOST' => 2,
441 $details = fetch_url(self::$_URL, $options);
443 $this->_parse_xml($details[
'response']);
446 $this->_logResponse();
451 function _parse_xml($data)
453 $xml_parser = xml_parser_create();
454 xml_parse_into_struct($xml_parser, $data, $vals, $index);
455 xml_parser_free($xml_parser);
459 foreach ($vals as $xml_elem) {
460 if ($xml_elem[
'type'] ==
'open') {
461 if (array_key_exists(
'attributes',$xml_elem)) {
462 list($level[$xml_elem[
'level']],$extra) = array_values($xml_elem[
'attributes']);
465 $level[$xml_elem[
'level']] = $xml_elem[
'tag'];
468 if ($xml_elem[
'type'] ==
'complete') {
470 $php_stmt =
'$params';
472 while($start_level < $xml_elem[
'level']) {
473 $php_stmt .=
'[$level['.$start_level.
']]';
476 $php_stmt .=
'[$xml_elem[\'tag\']] = isset($xml_elem[\'value\']) ? $xml_elem[\'value\'] : \'\';';
482 $success = $params[
'TXN'][
'SUCCESS'];
483 $responseTxt = $params[
'TXN'][
'RESPONSETEXT'];
484 $DPSTxnRef = $params[
'TXN'][
'DPSTXNREF'];
485 $this->_success = $success == 1 ? 1 : FALSE;
487 $this->_response[
'TRANSACTION'] = $DPSTxnRef;
488 $this->_response[
'TIME'] = time();
489 $this->_response[
'STATUS'] = $responseTxt;
503 return self::$_TEST_CARD_NUMBERS;
514 private function _logRequest()
516 $message =
"\nRequest\n";
517 $message .=
'Card holder name: '.$this->_card_name.
"\n";
518 $message .=
'Card number: '.substr($this->_card_number, -4).
"\n";
519 $message .=
'Amount: '.$this->_amount.
' '.$this->_currency.
"\n";
520 $this->_log($message);
531 private function _logResponse()
533 $message =
"\nResponse\n";
534 $message .=
'Transaction: '.$this->_response[
'TRANSACTION'].
"\n";
535 $message .=
'Time: '.$this->_response[
'TIME'].
"\n";
536 $message .=
'Status: '.$this->_response[
'STATUS'].
"\n";
537 $this->_log($message);
552 private function _log($message, $level = E_USER_NOTICE, $encode=FALSE)
554 log_write($message, $this->_log_file_name, $level, $encode);