17 require_once dirname(__FILE__).
'/../../payment_gateway/payment_gateway.inc';
18 require_once dirname(__FILE__).
'/esec_processor_integration_interface.inc';
44 function __construct($assetid=0)
47 parent::__construct($assetid);
64 if (!parent::_createAdditional($link))
return FALSE;
81 if (is_null($default_content)) {
82 $default_content = translate(
'default_bodycopy_content');
85 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
87 $copy_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
89 $bodycopy->setAttrValue(
'name',
'Display Format');
90 $args = Array(
'content' => $default_content);
91 if ($bodycopy->create($copy_link, $args)) {
92 $child_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getLink($bodycopy->id, SQ_LINK_TYPE_2,
'bodycopy_div');
93 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($child_bodycopy[
'minorid'],
'attributes');
110 $page_links = parent::_getAllowedLinks();
111 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 2,
'exclusive' => TRUE);
132 $keywords = parent::getAvailableKeywords();
134 $keywords[
'credit_card_number'] =
'Credit Card Number';
135 $keywords[
'credit_card_expiry_year'] =
'Credit Card Expiry Year';
136 $keywords[
'credit_card_expiry_month'] =
'Credit Card Expiry Month';
137 $keywords[
'credit_card_name'] =
'Name on card';
138 $keywords[
'credit_card_ccv'] =
'Credit Card CCV field';
139 $keywords[
'credit_card_type_selector'] =
'Credit Card Type Selector';
140 $keywords[
'submit_button'] =
'Submit Button';
141 $keywords[
'cancel_button'] =
'Cancel Button';
142 $keywords[
'reset_button'] =
'Reset Button';
143 $keywords[
'transaction_amount'] =
'Transaction Amount';
144 $keywords[
'processing_error'] =
'Processing Error (empty if no error)';
164 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
177 $amount = array_get_index($_SESSION,
'SQ_ECOM_AMOUNT', 0);
179 $card_info = array_get_index($_REQUEST, $this->
getPrefix().
'_card', FALSE);
180 $action = array_get_index($_REQUEST, $this->
getPrefix().
'_action', FALSE);
181 if ($action ==
'Cancel') {
184 }
else if (empty($amount)) {
185 unset($_SESSION[
'SQ_ECOM_AMOUNT']);
189 }
else if ($card_info) {
193 unset($_SESSION[
'SQ_ECOM_AMOUNT']);
216 if (is_null($bodycopy))
return;
218 $keywords = $bodycopy->getKeywords();
219 $replacements = Array();
220 foreach ($keywords as $word) {
223 $bodycopy->setKeywordReplacements($replacements);
226 $datapath = sq_web_path(
'data').
'/asset_types/payment_gateway_esec/files';
229 if ($this->
attr(
'test_mode')) {
230 echo
'<h2 class="gateway-test-mode" style="color: white; background-color: #C00; padding: 5px">TEST MODE</h2>';
234 <script src=
"<?php echo $datapath; ?>/loader.js"></script>
236 var Loader =
new Loader(
'<?php echo $card; ?>',
'#FFFFFF',
'Processing Transaction...',
'<?php echo $datapath; ?>/loader.gif');
239 <form method=
"post" action=
"<?php echo $this->getURL(); ?>" onsubmit=
"Loader.show();">
241 $bodycopy->printBody();
256 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'',
'major');
257 if (empty($link))
return $null;
258 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
272 $amount = array_get_index($_SESSION,
'SQ_ECOM_AMOUNT', 0);
275 $card_types = $Esec->getCardTypes();
278 $Esec->setAmount($amount);
279 $amount = $Esec->getAmount();
282 $card = $prefix.
'_card';
286 $form_contents_select =
'';
287 foreach ($card_types as $type) {
288 $form_contents_select .=
'<option value="'.$type.
'>'.$type.
'</option>';
292 if ($this->
attr(
'test_mode')) {
294 $form_contents .=
'<h2 style="color: white; background-color: grey; padding: 5px">TEST MODE</h2>';
296 $test_card_numbers = $Esec->getTestCardNumbers();
297 $card_number =
'<select name="'.$card.
'[number]">';
298 foreach ($test_card_numbers as $number => $label) {
299 $card_number .=
'<option value="'.$number.
'>'.$number.
'</option>';
301 $card_number .=
'</select>';
303 $card_number =
'<input name="'.$card.
'[number]" autocomplete="off" />';
307 if (array_get_index($this->_tmp,
'is_error', FALSE)) {
308 $form_contents .=
'<h2 style="color: red; ">Error '.$this->_tmp[
'error_message'].
'</h2>';
311 $message = $this->
attr(
'message');
313 $datapath = sq_web_path(
'data').
'/asset_types/payment_gateway_esec/files';
315 $own_url = $this->
getURL();
319 <script src=
"<?php echo $datapath; ?>/loader.js"></script>
321 var Loader =
new Loader(
'<?php echo $card; ?>',
'#FFFFFF',
'Processing Transaction...',
'<?php echo $datapath; ?>/loader.gif');
324 <form method=
"post" action=
"<?php echo $own_url; ?>" onsubmit=
"Loader.show();">
325 <div><?php echo $message; ?></div>
326 <div style=
"background-color: #CCC; padding: 5px"><strong>$<?php echo $amount; ?></strong> Australian Dollars are
about to be debited from your credit card</div>
327 <table cellpadding=
"5">
329 <td align=
"right">Name on Card</td>
330 <td><input name=
"<?php echo $card; ?>[name]" autocomplete=
"off" /></td>
333 <td align=
"right">Number</td>
334 <td><?php echo $card_number; ?></td>
337 if ($this->
attr(
'display_ccv')) {
340 <td align=
"right">CCV</td>
341 <td><input name=
"<?php echo $card; ?>[ccv]" size=
'4' autocomplete=
"off" /> - from the back of your credit card</td>
347 <td align=
"right">Expiry Date (MM/YY)</td>
348 <td><input name=
"<?php echo $card; ?>[month]" size=
"2" autocomplete=
"off" /> / <input name=
"<?php echo $card; ?>[year]" size=
"2" autocomplete=
"off" /></td>
351 <td align=
"right">Type</td>
353 <select name=
"<?php echo $card; ?>[type]">
354 <?php echo $form_contents_select; ?>
360 <td><input
type=
"submit" value=
" Pay " /><input type=
"reset" value=
"Reset" /><input type=
"submit" name=
"<?php echo $prefix; ?>_action" value=
"Cancel" /></td>
365 $form_contents .= ob_get_clean();
368 return $form_contents;
383 if (!$card_info)
return FALSE;
385 $ref_no = $_SESSION[
'SQ_ECOM_REF_NO'];
386 $amount = $_SESSION[
'SQ_ECOM_AMOUNT'];
390 $Esec->setAmount($amount);
391 $Esec->setReference($ref_no);
392 $Esec->setMerchant($this->
attr(
'merchant_id'));
393 $Esec->setCardNumber($card_info[
'number']);
394 $Esec->setCCV(array_get_index($card_info,
'ccv',
''));
395 $Esec->setCardType($card_info[
'type']);
396 $Esec->setCardExpiryMonth($card_info[
'month']);
397 $Esec->setCardExpiryYear($card_info[
'year']);
398 $Esec->setCardName($card_info[
'name']);
400 if ($this->
attr(
'test_mode')) $Esec->setTest();
402 $success = $Esec->process();
405 $response = $Esec->getResponse();
406 if (!empty($response[
'REFERENCE'])) {
407 $_SESSION[
'SQ_ECOM_REF_NO'] = $response[
'REFERENCE'];
411 $this->_tmp[
'is_error'] = TRUE;
412 $this->_tmp[
'error_message'] = $response[
'MESSAGE_CODE'].
' '.$response[
'MESSAGE'];
414 $status = $Esec->explainStatus();
415 if ($this->
attr(
'test_mode')) {
416 $status =
'!!!ATTENTION!!! TEST MODE (transaction not performed) -- '.$status;
419 $response[
'STATUS'] = $status;
422 $cardlength = strlen($card_info[
'number']);
423 if ($cardlength < 16) {
424 for ($i = 0; $i < $cardlength - 4; $i++) {
427 $cardno .= substr($card_info[
'number'], $i);
429 $cardno =
'****-****-****-'.substr($card_info[
'number'],12);
431 $response[
'CARDNO'] = $cardno;
432 $response[
'TIME'] = date(
'r');
433 $response[
'AMOUNT'] = $amount;
435 $_SESSION[
'SQ_ECOM_RESPONSE'] = $response;
455 if ($state ==
'SUCCESS') {
456 $back_url = array_get_index($_SESSION,
'SQ_ECOM_SUCCESS_URL');
457 unset($_SESSION[
'SQ_ECOM_SUCCESS_URL']);
459 }
else if ($state ==
'CANCEL') {
460 $back_url = array_get_index($_SESSION,
'SQ_ECOM_CANCEL_URL');
461 unset($_SESSION[
'SQ_ECOM_CANCEL_URL']);
464 if (is_null($back_url)) {
465 trigger_error(
'Unknown caller reference');
467 header(
'Location: '.$back_url);
484 $card = $prefix.
'_card';
487 if ($this->
attr(
'test_mode')) {
488 $test_card_numbers = $this->_esec->getTestCardNumbers();
489 $card_number =
'<select name="'.$card.
'[number]">';
490 foreach ($test_card_numbers as $number => $label) {
491 $card_number .=
'<option value="'.$number.
'" >'.$number.
'</option>';
493 $card_number .=
'</select>';
495 $card_number =
'<input name="'.$card.
'[number]" autocomplete="off" />';
513 $string =
'<input name="'.$card.
'[name]" autocomplete="off" />';
529 $string =
'<input name="'.$card.
'[ccv]" size="4" autocomplete="off" />';
546 $card_types = $this->_esec->getCardTypes();
549 echo
'<select name="'.$card.
'[type]">';
550 foreach ($card_types as $type) {
551 echo
'<option value="'.$type.
'">'.$type.
'</option>';
556 return ob_get_clean();
569 $amount = array_get_index($_SESSION,
'SQ_ECOM_AMOUNT', 0);
570 $this->_esec->setAmount($amount);
571 $amount = $this->_esec->getAmount();
586 if (array_get_index($this->_tmp,
'is_error', FALSE)) {
587 return '<span class="payment-gateway-transaction-error">'.$this->_tmp[
'error_message'].
'</span>';
606 $string =
'<input name="'.$card.
'[year]" size="2" autocomplete="off" />';
623 $string =
'<input name="'.$card.
'[month]" size="2" autocomplete="off" />';
637 $button_text = $this->
attr(
'submit_text');
638 if (empty($button_text)) $button_text =
'Submit';
639 return '<input type="submit" value="'.$button_text.
'" />';
652 $button_text = $this->
attr(
'reset_text');
653 if (empty($button_text)) $button_text =
'Reset';
654 return '<input type="reset" value="'.$button_text.
'" />';
667 $button_text = $this->
attr(
'cancel_text');
668 if (empty($button_text)) $button_text =
'Cancel';
669 return '<input type="submit" name="'.$this->getPrefix().
'_action" value="'.$button_text.
'" />';