Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
utransact_processor.inc
1 <?php
18 define('UTRANSACT_LOG_FILE', 'utransact_transactions');
19 define('MAX_TRANSACTION_PROCESS_ATTEMPT', 5);
20 
21 require_once dirname(__FILE__).'/transaction_dataset.inc';
22 
34 {
35 
41  private $_bgas_url;
42 
43 
49  private $_transactions_url;
50 
51 
57  private $_services_url;
58 
59 
65  private $_bgas_client;
66 
67 
73  private $_transactions_client;
74 
75 
81  private $_services_client;
82 
83 
92  private $_auth_token;
93 
94 
100  private $_auth_bgas_header_ns = "http://www.paymentgateway.co.nz/pgservice/Bgas.asmx";
101 
102 
108  private $_auth_transactions_header_ns = "http://www.paymentgateway.co.nz/pgservice/Transactions.asmx";
109 
110 
116  private $_auth_services_header_ns = "http://www.paymentgateway.co.nz/pgservice/Services.asmx";
117 
118 
124  private $_card_types;
125 
126 
132  private $_test_card_numbers = Array (
133  "4111111111111111" => "Visa Card Test",
134  "5555555555554444" => "MasterCard Card Test",
135  "492" => "Invalid Card Test",
136  );
137 
138 
143  private $_username;
144 
145 
150  private $_password;
151 
152 
157  private $_reference_no;
158 
159 
164  private $_credit_card;
165 
166 
171  private $_credit_card_cv2;
172 
173 
178  private $_expiry_month;
179 
180 
185  private $_expiry_year;
186 
187 
192  private $_card_holder_name;
193 
194 
199  private $_merchant_id;
200 
201 
206  private $_payment_model;
207 
208 
213  private $_first_name;
214 
219  private $_surname;
220 
221 
226  private $_email;
227 
228 
233  private $_address_line_1;
234 
235 
240  private $_address_line_2;
241 
242 
247  private $_suburb;
248 
249 
254  private $_city;
255 
256 
261  private $_postcode;
262 
263 
268  private $_cart_items = Array();
269 
270 
275  private $_response = Array();
276 
277 
278 
289  function __construct($username, $password, $bgas_url, $transactions_url, $services_url)
290  {
291  $this->_username = $username;
292  $this->_password = $password;
293 
294  $this->_bgas_url = $bgas_url;
295  $this->_transactions_url = $transactions_url;
296  $this->_services_url = $services_url;
297 
298  $this->_bgas_client = new SoapClient($this->_bgas_url, array('trace' => 1));
299  $this->_transactions_client = new SoapClient($this->_transactions_url, array('trace' => 1));
300  $this->_services_client = new SoapClient( $this->_services_url, array('trace' => 1));
301 
302  $this->_log_file_name = UTRANSACT_LOG_FILE;
303 
305 
306  }//end constructor
307 
308 
315  public function process()
316  {
317  $transaction_handle = isset($_SESSION['UTRANSACT_TRANSACTION_HANDLE']) ? $_SESSION['UTRANSACT_TRANSACTION_HANDLE'] : FALSE;
318 
319  if (!$transaction_handle) {
320  // Cannot proceed without transaction handler
321  $this->_response['STATUS'] = "FAIL";
322  $this->_response['MESSAGE'] = "Couldn't find transaction handle in session";
323 
324  $this->_log("Couldn't find transaction handle in the session for the transaction ref ".$this->_reference_no);
325  return FALSE;
326  }
327 
328 
329  if (empty($this->_cart_items)) {
330  // Cart is empty, nothing to process
331  $this->_response['STATUS'] = "FAIL";
332  $this->_response['MESSAGE'] = "Cart items not found in session";
333 
334  $this->_log("Cart items not found in session for transaction ref ".$this->_reference_no);
335  return FALSE;
336  }
337 
338  // First set the UTransact authentication token
339  if (!$this->_refreshAuthToken()) {
340  $this->_response['STATUS'] = "FAIL";
341  $this->_response['MESSAGE'] = translate('utransact_problem_while_processing', $this->_reference_no);
342 
343  $this->_log("Cannot acquire Utransact bga authentication token");
344 
345  return FALSE;
346  }
347 
348  // Create a transaction dataset for this tranaction
349  $transaction_table = new Transaction_Dataset();
350 
351  // Populate transaction row
352  $transaction_table->addTransactionRow(
353  $this->_reference_no,
354  empty($this->_credit_card_cv2) ? $this->_credit_card : $this->_credit_card.','.$this->_credit_card_cv2,
355  $this->_expiry_year.'/'.$this->_expiry_month,
356  $this->_card_holder_name,
357  $this->_merchant_id,
358  $this->_payment_model
359  );
360 
361  // Populate purchaser row
362  $transaction_table->addPurchaserRow(
363  $this->_first_name,
364  $this->_surname,
365  $this->_email,
366  $this->_address_line_1,
367  $this->_address_line_2,
368  $this->_suburb,
369  $this->_city,
370  $this->_postcode
371  );
372 
373  // Populate line_item row
374  foreach($this->_cart_items as $item) {
375  $transaction_table->addLineItemRow(
376  $item["ApplicationUsername"],
377  $item["Name"],
378  $item["Description"],
379  $item["Quantity"],
380  $item["RefundType"],
381  $item["RefundExpiryDate"],
382  $item["Amount"],
383  $item["ProductCode"],
384  $item["FinancialCode"],
385  $item["FinancialValues"],
386  $item["AdditionalInfo"]
387  );
388  }//end for
389 
390  // Once line_item table is populated, empty the cart
391  $this->clearCart();
392 
393  // New transaction dataset
394  $new_transaction_dataset = $transaction_table->getTransactionDatasetXML();
395 
396  // Get the authentication header for soap request to payment gateway
397  $transaction_auth_header = $this->_getAuthSoapHeader($this->_auth_transactions_header_ns);
398 
399  $process_attempt_count = 1;
400  $transaction_response = null;
401 
402  while (empty($transaction_response)) {
403 
404  // Process the transaction
405  try {
406  // First check if transaction already exists
407  $transaction_exists_response = $this->_transactions_client->__soapCall(
408  'TransactionExists',
409  Array(
410  'parameters' => Array(
411  'bgaName' => $this->_username,
412  'referenceId' => $this->_reference_no,
413  ),
414  ),
415  Array('uri' => ''),
416  $transaction_auth_header
417  );
418 
419 
420  if (isset($transaction_exists_response->TransactionExistsResult) && $transaction_exists_response->TransactionExistsResult) {
421  $transaction_result = $transaction_exists_response->TransactionExistsResult;
422  break;
423 
424  } else {
425  // Process the new transaction
426  $transaction_response = $this->_transactions_client->__soapCall(
427  'ProcessTransaction',
428  Array(
429  'parameters' => Array(
430  'transactionHandle' => $transaction_handle,
431  'transaction' => Array(
432  'any' => $new_transaction_dataset,
433  ),
434  ),
435  ),
436  Array('uri' => ''),
437  $transaction_auth_header
438  );
439  $transaction_result = isset($transaction_response->ProcessTransactionResult->any) ? $transaction_response->ProcessTransactionResult->any : '';
440  }
441 
442  } catch (SoapFault $fault) {
443  $this->_response['STATUS'] = "FAIL";
444  $this->_response['MESSAGE'] = $fault->getMessage()."<br>".translate('utransact_problem_while_processing', $this->_reference_no);
445 
446  $this->_log($fault->getMessage());
447  return FALSE;
448 
449  } catch (BusinessRuleException $e) {
450  $this->_response['STATUS'] = "FAIL";
451  $this->_response['MESSAGE'] = translate('utransact_problem_while_processing', $this->_reference_no);
452 
453  $this->_log("ERROR: Transaction expection occured for transaction ref ".$this->_reference_no.": ".$e->getMessage());
454  return FALSE;
455 
456  } catch (TransactionException $e) {
457  $this->_response['STATUS'] = "FAIL";
458  $this->_response['MESSAGE'] = translate('utransact_problem_while_processing', $this->_reference_no);
459 
460  $this->_log("ERROR: Transaction expection occured for transaction ref ".$this->_reference_no.": ".$e->getMessage());
461  return FALSE;
462 
463  } catch (CoreUnavailableException $e) {
464 
465  // Core is not available
466  $this->_log("ERROR: Attempt #$process_attempt_count, Core not available while processing transaction ".$this->_reference_no." :".$e->getMessage());
467 
468  // Maximum attempts made, quitting now
469  if ($process_attempt_count > MAX_TRANSACTION_PROCESS_ATTEMPT) {
470  $this->_response['STATUS'] = "FAIL";
471  $this->_response['MESSAGE'] = translate('utransact_core_not_available_for_processing', $this->_reference_no);
472 
473  return FALSE;
474  }
475 
476  // Maximum attempt count not reached yet, try again to process the transaction
477  $process_attempt_count++;
478  }
479 
480  }//end while
481 
482 
483  // If new transaction was processed then check for error(s) in response, if any
484  $transaction_errors = $this->_getTransactionErrors($transaction_result);
485 
486  $transaction_successful = FALSE;
487 
488  // If there was error processing transaction, then transaction was unsuccessful
489  if (!empty($transaction_errors)) {
490 
491  $error_str ='';
492  foreach($transaction_errors as $error_id => $error_msg) {
493  $error_str .= $error_msg."<br>";
494  }
495 
496  $status = 'FAIL';
497  $message = $error_str;
498 
499  $this->_log("ERROR: Error occured while processing transaction ref ".$this->_reference_no." : ".$message);
500 
501  } else {
502 
503  try {
504  // Get the Transaction details just processed
505  $transaction_details_response = $this->_transactions_client->__soapCall(
506  'GetDetails',
507  Array(
508  'parameters' => Array(
509  'bgaName' => $this->_username,
510  'referenceId' => $this->_reference_no,
511  ),
512  ),
513  Array('uri' => ''),
514  $transaction_auth_header
515  );
516  } catch (SoapFault $fault) {
517  // Transaction completed, but couldn't obtained the details
518  $this->_log("ERROR: Transaction ref ".$this->_reference_no." completed, but couldn't obtain details: ".$e->getMessage());
519  }
520 
521  if (isset($transaction_details_response->GetDetailsResult->any)) {
522 
523  $transaction_info = $this->_getTransactionDetails($transaction_details_response->GetDetailsResult->any);
524 
525  $status = $transaction_info['Status'];
526  $message = "Transaction successfull";
527 
528  $this->_response['AMOUNT'] = $transaction_info['Amount'];
529  $this->_response['GST'] = $transaction_info['GST'];
530  $this->_response['INVOICE_NUMBER'] = $transaction_info['InvoiceNumber'];
531  $this->_response['UTRANSACT_REFERENCE'] = $transaction_info['uTransactRef'];
532  $this->_response['MERCHANT_ID'] = $transaction_info['MerchantId'];
533  $this->_response['DATE'] = $transaction_info['Date'];
534  $this->_response['PAYMENT_GATEWAY_XML'] = $transaction_details_response->GetDetailsResult->any;
535 
536  } else {
537  // Transaction completed, but couldn't obtain the details
538  $status = "UNKNOWN";
539  $message = translate('utransact_cannot_obtain_transaction_details', $this->_reference_no);
540 
541  $this->_log("ERROR: Couldn't get transaction ref ".$this->_reference_no." details");
542  }
543 
544  $transaction_successful = TRUE;
545  }
546 
547  $this->_response['REFERENCE'] = $this->_reference_no;
548  $this->_response['STATUS'] = $status;
549  $this->_response['MESSAGE'] = $message;
550 
551  // Log this transaction
552  $this->_logRequest();
553  $this->_logResponse();
554 
555  return $transaction_successful;
556 
557  }//end process()
558 
559 
560 
570  {
571  $auth_header = $this->_getAuthSoapHeader($this->_auth_transactions_header_ns);
572 
573  if (!$auth_header) {
574  $this->_response['STATUS'] = "FAIL";
575  $this->_response['MESSAGE'] = "Cannot obtain payment gateway authentication soap header";
576 
577  $this->_log("Cannot obtain authentication soap header");
578  return FALSE;
579  }
580 
581  // Get the transaction handle from the webservice
582  try {
583  $transaction_handle = $this->_transactions_client->__soapCall(
584  'RequestTransactionHandle',
585  Array(),
586  Array('uri' => ''),
587  $auth_header
588  );
589  } catch(SoapFault $fault){
590  $this->_log($fault->getMessage());
591 
592  if (isset($_SESSION['UTRANSACT_AUTH_TOKEN'])) unset($_SESSION['UTRANSACT_AUTH_TOKEN']);
593 
594  return FALSE;
595  }
596 
597  return isset($transaction_handle->RequestTransactionHandleResult) ? $transaction_handle->RequestTransactionHandleResult : FALSE;
598 
599  }//end getTransactionHandle()
600 
601 
610  function _refreshAuthToken()
611  {
612  // If token is not found, try to get it from session
613  if (empty($this->_auth_token)) {
614  $this->_auth_token = isset($_SESSION['UTRANSACT_AUTH_TOKEN']) ? $_SESSION['UTRANSACT_AUTH_TOKEN'] : '';
615  }
616 
617  // If we have token already then check if its still valid
618  if (!empty($this->_auth_token)) {
619 
620  try {
621  $soap_response = $this->_services_client->__soapCall(
622  'isValidLogin',
623  Array('parameters' =>
624  Array(
625  'authCookie' => $this->_auth_token,
626  ),
627  )
628  );
629  } catch(SoapFault $fault){
630  $this->_log($fault->getMessage());
631  return FALSE;
632  }
633 
634  // If its valid then we're fine, we don't require new one
635  if (isset($soap_response->IsValidLoginResult) && $soap_response->IsValidLoginResult) {
636  return TRUE;
637  }
638  }
639 
640  // Token has not been set or has expired
641  try{
642  $auth_token = $this->_bgas_client->__soapCall(
643  'LoginBga',
644  Array('parameters' => Array(
645  'username' => $this->_username,
646  'password' => $this->_password,
647  )
648  )
649  );
650  }catch(SoapFault $fault){
651  $this->_log($fault->getMessage());
652  return FALSE;
653  }
654 
655  // Extract the bga authenticaitn token from the response soap header
656  $response_xml = $this->_bgas_client->__getLastResponse();
657  preg_match("|<BgaAuthToken>(.*?)</BgaAuthToken>|i", $response_xml, $bga_token_match);
658 
659  $auth_token = isset($bga_token_match[1]) ? $bga_token_match[1] : '';
660 
661  if (!$auth_token) {
662  $this->_log("BgaAuthToken not found in LoginBga() response");
663  return FALSE;
664  }
665 
666  // Store the authentication token in session so that we don't have to re-login each time for every soap request
667  $this->_auth_token = $auth_token;
668  $_SESSION['UTRANSACT_AUTH_TOKEN'] = $this->_auth_token;
669 
670  return TRUE;
671 
672  }//end _refreshAuthToken()
673 
674 
683  function _getAuthSoapHeader($namespace)
684  {
685  // Refresh (or set if not already) the UTransact authentication token
686  if (!$this->_refreshAuthToken()) {
687  $this->_response['STATUS'] = "FAIL";
688  $this->_response['MESSAGE'] = "Cannot acquire Utransact bga authentication token";
689  return FALSE;
690  }
691 
692  // Reuse BGA token as User token
693  $soap_header_data = "
694  <PgWebServiceAuthToken".(empty($namespace) ? ">" : " xmlns='".$namespace."'>")."
695  <BgaAuthToken>".$this->_auth_token."</BgaAuthToken>
696  <UserAuthToken>".$this->_auth_token."</UserAuthToken>
697  </PgWebServiceAuthToken>";
698 
699 
700  $soap_header_var = @new SoapVar($soap_header_data, XSD_ANYXML);
701  $soap_header = @new SoapHeader($namespace, "PgWebServiceAuthToken", $soap_header_var);
702 
703  return $soap_header;
704 
705  }//end _getAuthSoapHeader()
706 
707 
715  {
716  $auth_header = $this->_getAuthSoapHeader($this->_auth_bgas_header_ns);
717 
718  if (!$auth_header) {
719  $this->_response['STATUS'] = "FAIL";
720  $this->_response['MESSAGE'] = "Cannot obtain list of credit card supported by payement gateway";
721 
722  $this->_card_types = Array();
723 
724  return FALSE;
725  }
726 
727  try {
728  $cards_dataset = $this->_bgas_client->__soapCall(
729  'GetSupportedCreditCards',
730  Array(),
731  Array('uri' => ''),
732  $auth_header
733  );
734  } catch(SoapFault $fault){
735  $this->_log($fault->getMessage());
736  return FALSE;
737  }
738 
739  preg_match_all('|<Id>(.*?)</Id>.*?<Name>(.*?)</Name>|msi', $cards_dataset->GetSupportedCreditCardsResult->any, $card_matches);
740 
741  $card_list = Array();
742  foreach((isset($card_matches[1]) ? $card_matches[1] : Array()) as $key => $card_id) {
743  $card_list[$card_id] = isset($card_matches[2][$key]) ? $card_matches[2][$key] : $card_id;
744  }
745 
746  $this->_card_types = $card_list;
747 
748  return TRUE;
749 
750  }//end _setSupportedCreditCardTypes()
751 
752 
760  {
761  $auth_header = $this->_getAuthSoapHeader($this->_auth_transactions_header_ns);
762 
763  if (!$auth_header) {
764  $this->_log("Cannot obtain authetication header while attempting to get GST rate from payment gateway");
765  return FALSE;
766  }
767 
768  try {
769  $gst_rate_response = $this->_transactions_client->__soapCall(
770  'GetGstRate',
771  Array(),
772  Array('uri' => ''),
773  $auth_header
774  );
775  } catch(SoapFault $fault){
776  $this->_log($fault->getMessage());
777  return FALSE;
778  }
779 
780  return isset($gst_rate_response->GetGstRateResult) ? $gst_rate_response->GetGstRateResult : FALSE;
781 
782  }//end getTransactionGstRate()
783 
784 
793  function _getTransactionErrors($result)
794  {
795  if (empty($result)) {
796  return Array(translate('utransact_empty_response_while_processing', $this->_reference_no));
797  }
798 
799  preg_match_all('|<ErrorCode>(.*?)</ErrorCode>.*?<DisplayMessage>(.*?)</DisplayMessage>|i',$result, $error_match);
800 
801  // No error message in response
802  if (!isset($error_match[1][0])) return Array();
803 
804  $errors = Array();
805  foreach($error_match[1] as $index => $error_code) {
806  $errors[$error_code] = isset($error_match[2][$index]) ? $error_match[2][$index] : '';
807  }
808 
809  return $errors;
810 
811  }//end _getTransactionErrors()
812 
813 
823  {
824  if (empty($result)) {
825  return translate('utransact_empty_response_while_processing', $this->_reference_no);
826  }
827 
828  preg_match('|<InvoiceNumber>(.*?)</InvoiceNumber>|',$result, $match);
829 
830  return isset($match[1]) ? $match[1] : '' ;
831 
832  }//end _getTransactionInvoiceNumber()
833 
834 
843  function _getTransactionDetails($result)
844  {
845  if (empty($result)) {
846  return Array(translate('utransact_empty_response_while_processing', $this->_reference_no));
847  }
848 
849  $details = Array();
850 
851  // Extrace the following details from the transaction response
852  foreach(Array('ReferenceId', 'InvoiceNumber', 'Date', 'Status', 'Amount' , 'GST', 'uTransactRef', 'MerchantId') as $field) {
853  $match = Array();
854 
855  preg_match("|<Transaction xmlns.*?<$field>(.*?)</$field>.*?</Transaction>|msi", $result, $match);
856  $details[$field] = isset($match[1]) ? $match[1] : '' ;
857  }
858 
859  return $details;
860 
861  }//end _getTransactionDetails()
862 
863 
872  function getResponse()
873  {
874  return $this->_response;
875 
876  }//end getResponse()
877 
878 
886  {
887  return $this->_webservice_transactions_url;
888 
889 
890  }//end getWebserviceTransactionsURL()
891 
892 
899  public function getWebserviceServicesURL()
900  {
901  return $this->_webservice_services_url;
902 
903 
904  }//end getWebserviceServicesURL()
905 
906 
915  public function setCreditCard($credit_card_no)
916  {
917  $this->_credit_card = $credit_card_no;
918 
919  }//end setCreditCard
920 
921 
930  public function setCreditCardCV2($cv2)
931  {
932  $this->_credit_card_cv2 = $cv2;
933 
934  }//end setCreditCardCV2
935 
936 
937 
946  public function setTransactionReferenceNo($reference_no)
947  {
948  $this->_reference_no = $reference_no;
949 
950  }//end setTransactionReferenceNo
951 
952 
961  public function setCardExpiryMonth($month)
962  {
963  $this->_expiry_month = strtoupper($month);
964 
965  }//end setExipryMonth
966 
967 
976  public function setCardExpiryYear($year)
977  {
978  $this->_expiry_year = $year;
979 
980  }//end setExipryYear
981 
982 
991  public function setCardHolderName($card_holder_name)
992  {
993  $this->_card_holder_name = $card_holder_name;
994 
995  }//end setCardHolderName
996 
997 
1006  public function setMerchantId($merchant_id)
1007  {
1008  $this->_merchant_id = $merchant_id;
1009 
1010  }//end setMerchantId
1011 
1012 
1021  public function setPaymentModel($model)
1022  {
1023  $this->_payment_model = $model;
1024 
1025  }//end setPaymentModel
1026 
1027 
1034  public function getTransactionReferenceNo()
1035  {
1036  return $this->_reference_no;
1037 
1038  }//end getTransactionReferenceNo()
1039 
1040 
1047  public function getCreditCard()
1048  {
1049  return $this->_credit_card;
1050 
1051  }//end getSurname
1052 
1053 
1060  public function getCreditCardCV2($cv2)
1061  {
1062  return $this->_credit_card_cv2;
1063 
1064  }//end setCreditCardCV2
1065 
1066 
1073  public function getExpiryDate()
1074  {
1075  return $this->_expiry_date;
1076 
1077  }//end getExipryDate
1078 
1079 
1086  public function getCardHolderName()
1087  {
1088  return $this->_card_holder_name;
1089 
1090  }//end getCardHolderName
1091 
1092 
1099  public function getMerchantId()
1100  {
1101  return $this->_merchant_id;
1102 
1103  }//end getMerchantId
1104 
1105 
1112  public function getPaymentModel()
1113  {
1114  return $this->_payment_model;
1115 
1116  }//end getPaymentModel
1117 
1118 
1127  public function setFirstName($first_name)
1128  {
1129  $this->_first_name = $first_name;
1130 
1131  }//end setFirstName
1132 
1133 
1142  public function setSurname($surname)
1143  {
1144  $this->_surname = $surname;
1145 
1146  }//end setSurname
1147 
1148 
1157  public function setEmail($email)
1158  {
1159  $this->_email = $email;
1160 
1161  }//end setEmail
1162 
1163 
1172  public function setAddressLine1($address_1)
1173  {
1174  $this->_address_line_1 = $address_1;
1175 
1176  }//end setAddressLine1
1177 
1178 
1187  public function setAddressLine2($address_2)
1188  {
1189  $this->_address_line_2 = $address_2;
1190 
1191  }//end setAddressLine2
1192 
1193 
1202  public function setSuburb($suburb)
1203  {
1204  $this->_suburb = $suburb;
1205 
1206  }//end setEmail
1207 
1208 
1217  public function setCity($suburb)
1218  {
1219  $this->_city= $suburb;
1220 
1221  }//end setEmail
1222 
1223 
1232  public function setPostcode($postcode)
1233  {
1234  $this->_postcode = $postcode;
1235 
1236  }//end setEmail()
1237 
1238 
1245  public function getFirstName()
1246  {
1247  return $this->_first_name;
1248 
1249  }//end getFirstName()
1250 
1251 
1258  public function getSurname()
1259  {
1260  return $this->_surname;
1261 
1262  }//end getSurname()
1263 
1264 
1271  public function getEmail()
1272  {
1273  return $this->_email;
1274 
1275  }//end getEmail()
1276 
1277 
1284  public function getAddressLine1()
1285  {
1286  return $this->_address_line_1;
1287 
1288  }//end getAddressLine1()
1289 
1290 
1297  public function getAddressLine2()
1298  {
1299  return $this->_address_line_2;
1300 
1301  }//end getAddressLine2()
1302 
1303 
1310  public function getSuburb()
1311  {
1312  return $this->_suburb;
1313 
1314  }//end getEmail()
1315 
1316 
1323  public function getCity()
1324  {
1325  return $this->_city;
1326 
1327  }//end getEmail()
1328 
1329 
1336  public function getPostcode()
1337  {
1338  return $this->_postcode;
1339 
1340  }//end getEmail()
1341 
1342 
1351  public function setReferenceId($ref_id)
1352  {
1353  $this->_reference_id = $ref_id;
1354 
1355  }//end setReferenceId
1356 
1357 
1366  public function setApplicationUserName($username)
1367  {
1368  $this->_application_username = $username;
1369 
1370  }//end setApplicaitonUsername
1371 
1372 
1381  public function setName($name)
1382  {
1383  $this->_name = $name;
1384 
1385  }//end setName
1386 
1387 
1396  public function setDescription($description)
1397  {
1398  $this->_description = $description;
1399 
1400  }//end setDescription
1401 
1402 
1411  public function setQuantity($quantity)
1412  {
1413  $this->_quantity = $quantity;
1414 
1415  }//end setQuantity
1416 
1417 
1426  public function setRefundType($refund_type)
1427  {
1428  $this->_refund_type = $refund_type;
1429 
1430  }//end setRefundType
1431 
1432 
1441  public function setRefundExpiryDate($refund_expiry_date)
1442  {
1443  $this->_refund_expiry_date = $refund_expiry_date;
1444 
1445  }//end setRefundExpiryDate
1446 
1447 
1456  public function setProductCode($product_code)
1457  {
1458  $this->_product_code = $product_code;
1459 
1460  }//end setProductCode
1461 
1462 
1471  public function setFinancialCode($financial_code)
1472  {
1473  $this->_financial_code = $financial_code;
1474 
1475  }//end setFinancialCode
1476 
1477 
1486  public function setFinancialValues($financial_values)
1487  {
1488  $this->_financial_values = $financial_values;
1489 
1490  }//end setFinancialValues
1491 
1492 
1501  public function setAdditionalInfo($additional_info)
1502  {
1503  $this->_additional_info = $additional_info;
1504 
1505  }//end setAdditionalInfo
1506 
1507 
1526  function addCartItem($application_username, $name, $description, $quantity, $refund_type, $refund_expiry_date, $amount, $product_code, $financial_code, $financial_values, $additional_info)
1527  {
1528  $cart_item = Array(
1529  "ApplicationUsername" => $application_username,
1530  "Name" => $name,
1531  "Description" => $description,
1532  "Quantity" => $quantity,
1533  "RefundType" => $refund_type,
1534  "RefundExpiryDate" => $refund_expiry_date,
1535  "Amount" => $amount,
1536  "ProductCode" => $product_code,
1537  "FinancialCode" => $financial_code,
1538  "FinancialValues" => $financial_values,
1539  "AdditionalInfo" => $additional_info,
1540  );
1541 
1542 
1543  $this->_cart_items[] = $cart_item;
1544 
1545  return TRUE;
1546 
1547  }
1548 
1549 
1556  function clearCart()
1557  {
1558  $this->_cart_items = Array();
1559  }
1560 
1561 
1568  function getCartItems()
1569  {
1570  return $this->_cart_items;
1571  }
1572 
1573 
1580  public function getCardExpiryMonth($month)
1581  {
1582  return $this->_expiry_month;
1583 
1584  }//end getExipryMonth
1585 
1586 
1593  public function getCardExpiryYear($year)
1594  {
1595  return $this->_expiry_year;
1596 
1597  }//end getExipryYear
1598 
1599 
1606  function getCardTypes()
1607  {
1608  return $this->_card_types;
1609 
1610  }//end getCardTypes()
1611 
1612 
1620  {
1621  return $this->_test_card_numbers;
1622 
1623  }//end getTestCardNumbers()
1624 
1625 
1632  private function _logRequest()
1633  {
1634  $message = "\nRequest:\n";
1635  $message .= 'Time: '.date('r')."\n";
1636  $message .= 'Card holder name: '.$this->_card_holder_name."\n";
1637  $message .= 'Card number: ****-****-****-'.substr($this->_credit_card, -4)."\n";
1638  $message .= 'Amount: '.array_get_index($this->_response, 'AMOUNT', '')."\n";
1639  $this->_log($message);
1640 
1641  }//end _logRequest()
1642 
1643 
1650  private function _logResponse()
1651  {
1652  $message = "\nResponse:\n";
1653  $message .= 'Transaction Ref: '.$this->_reference_no."\n";
1654  $message .= 'Invoice No.: '.array_get_index($this->_response, 'INVOICE_NUMBER', '')."\n";
1655  $message .= 'UTransct Ref: '.array_get_index($this->_response, 'UTRANSACT_REFERENCE', '')."\n";
1656  $message .= 'Merchant Id: '.array_get_index($this->_response, 'MERCHANT_ID', '')."\n";
1657  $message .= 'Time: '.array_get_index($this->_response, 'DATE', date('r'))."\n";
1658  $message .= 'Status: '.array_get_index($this->_response, 'STATUS', '')."\n";
1659  $message .= 'Message: '.array_get_index($this->_response, 'MESSAGE', '')."\n";
1660  $this->_log($message);
1661 
1662  }//end _logResponse()
1663 
1664 
1675  private function _log($message, $level = E_USER_NOTICE, $encode=FALSE)
1676  {
1677  log_write($message, $this->_log_file_name, $level, $encode);
1678 
1679  }//end log()
1680 
1681 
1682 }//end class
1683 
1684 ?>