18 require_once dirname(__FILE__).
'/../../payment_gateway/payment_gateway.inc';
19 require_once dirname(__FILE__).
'/sagepay_processor.inc';
21 define(
'MIN_LINE_IN_ADDRESS', 1);
22 define(
'MAX_LINE_IN_ADDRESS', 3);
43 private $_redirect_info = NULL;
49 private $_pass_through_vars = NULL;
60 parent::__construct($assetid);
77 if (!parent::_createAdditional($link))
return FALSE;
79 return ($this->
_createBodycopy(
'display_format', translate(
'default_bodycopy_content')) && $this->
_createBodycopy(
'card_holder_verification', translate(
'card_holder_verification_bodycopy_content')));
95 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
97 $copy_link = Array(
'asset' => &$this,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1,
'value' => $link_value);
99 $bodycopy->setAttrValue(
'name', ucwords(str_replace(
'_',
' ', $link_value)));
100 $args = Array(
'content' => $content);
101 if ($bodycopy->create($copy_link, $args)) {
102 $child_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getLink($bodycopy->id, SQ_LINK_TYPE_2,
'bodycopy_div');
103 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($child_bodycopy[
'minorid'],
'attributes');
120 $page_links = parent::_getAllowedLinks();
121 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 2,
'exclusive' => TRUE);
142 $keywords = parent::getAvailableKeywords();
144 $keywords[
'card_name'] =
'Name on Card';
145 $keywords[
'card_number'] =
'Card Number';
146 $keywords[
'card_start_month'] =
'Card Start Month';
147 $keywords[
'card_start_month_select'] =
'Card Start Month Select';
148 $keywords[
'card_start_year'] =
'Card Start Year';
149 $keywords[
'card_start_year_select_XX'] =
'Card Start Year Select';
150 $keywords[
'card_expiry_month'] =
'Card Expiry Month';
151 $keywords[
'card_expiry_month_select'] =
'Card Expiry Month Select';
152 $keywords[
'card_expiry_year'] =
'Card Expiry Year';
153 $keywords[
'card_expiry_year_select_XX'] =
'Card Expiry Year Select';
154 $keywords[
'card_issue_number'] =
'Card Issue Number';
155 $keywords[
'card_cv2'] =
'Card CV2';
156 $keywords[
'card_type'] =
'Card Type';
158 $keywords[
'billing_first_names'] =
'Billing First Names';
159 $keywords[
'billing_surname'] =
'Billing Surname';
160 $keywords[
'billing_address1_X'] =
'Billing Address1 (X: 1 - 3)';
161 $keywords[
'billing_address2_X'] =
'Billing Address2 (X: 1 - 3)';
162 $keywords[
'billing_city'] =
'Billing City';
163 $keywords[
'billing_postcode'] =
'Billing Postcode';
164 $keywords[
'billing_country'] =
'Billing Country';
165 $keywords[
'billing_state'] =
'Billing State';
166 $keywords[
'billing_phone'] =
'Billing Phone';
168 $keywords[
'delivery_first_names'] =
'Delivery First Names';
169 $keywords[
'delivery_surname'] =
'Delivery Surname';
170 $keywords[
'delivery_address1_X'] =
'Delivery Address1 (X: 1 - 3)';
171 $keywords[
'delivery_address2_X'] =
'Delivery Address2 (X: 1 - 3)';
172 $keywords[
'delivery_city'] =
'Delivery City';
173 $keywords[
'delivery_postcode'] =
'Delivery Postcode';
174 $keywords[
'delivery_country'] =
'Delivery Country';
175 $keywords[
'delivery_state'] =
'Delivery State';
176 $keywords[
'delivery_phone'] =
'Delivery Phone';
178 $keywords[
'transaction_amount'] =
'Transaction Amount';
179 $keywords[
'processing_error'] =
'Processing Error (empty if no error)';
180 $keywords[
'submit_button'] =
'Submit Button';
181 $keywords[
'cancel_button'] =
'Cancel Button';
182 $keywords[
'reset_button'] =
'Reset Button';
183 $keywords[
'card_holder_verification_form'] =
'Card Holder Verification Form';
203 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
224 if (0 === strpos($keyword,
'card_start_year_select_')) {
225 $period = substr($keyword, 23);
226 if (is_numeric($period)) {
230 }
else if (0 === strpos($keyword,
'card_expiry_year_select_')) {
231 $period = substr($keyword, 24);
232 if (is_numeric($period)) {
236 }
else if (0 === strpos($keyword,
'billing_address1_')) {
237 $line = (int)substr($keyword, 17);
238 if (($line >= MIN_LINE_IN_ADDRESS) && ($line <= MAX_LINE_IN_ADDRESS)) {
242 }
else if (0 === strpos($keyword,
'billing_address2_')) {
243 $line = (int)substr($keyword, 17);
244 if (($line >= MIN_LINE_IN_ADDRESS) && ($line <= MAX_LINE_IN_ADDRESS)) {
248 }
else if (0 === strpos($keyword,
'delivery_address1_')) {
249 $line = (int)substr($keyword, 18);
250 if (($line >= MIN_LINE_IN_ADDRESS) && ($line <= MAX_LINE_IN_ADDRESS)) {
254 }
else if (0 === strpos($keyword,
'delivery_address2_')) {
255 $line = (int)substr($keyword, 18);
256 if (($line >= MIN_LINE_IN_ADDRESS) && ($line <= MAX_LINE_IN_ADDRESS)) {
261 $replacement = parent::getKeywordReplacement($keyword);
279 if (array_get_index($_GET,
'unknown_referer', FALSE)) {
280 trigger_error(
'Unknown caller reference');
285 if (array_get_index($_GET,
'error_message', FALSE)) {
286 $this->_setError($_GET[
'error_message']);
290 $is_in_frame = FALSE;
292 if (empty($_POST[
'PaRes']) || empty($_POST[
'MD'])) {
294 $amount = array_get_index($_SESSION,
'SQ_ECOM_AMOUNT', 0);
295 $card_info = array_get_index($_REQUEST, $this->
getPrefix().
'_card', FALSE);
296 $action = array_get_index($_REQUEST, $this->
getPrefix().
'_action', FALSE);
298 if ($action ==
'Cancel') {
301 }
else if (empty($amount)) {
302 unset($_SESSION[
'SQ_ECOM_AMOUNT']);
304 if (isset($_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS'])) {
305 unset($_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS']);
312 }
else if ($card_info) {
317 if ($success === 2) {
319 $_SESSION[
'SQ_ECOM_MD'] = md5($this->_redirect_info[
'MD']);
326 }
else if (!empty($_SESSION[
'SQ_ECOM_MD']) && (md5($_POST[
'MD']) == $_SESSION[
'SQ_ECOM_MD'])) {
329 unset($_SESSION[
'SQ_ECOM_MD']);
331 if ($success === FALSE) {
333 $this->_redirectParent($this->
getURL().
'?error_message='.urlencode($this->_tmp[
'error_message'][0]));
338 if ($success === 1) {
339 unset($_SESSION[
'SQ_ECOM_AMOUNT']);
341 if (isset($_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS'])) {
342 unset($_SESSION[
'SQ_ECOM_PASS_THROUGH_VARS']);
369 if (is_null($bodycopy))
return;
371 $keywords = $bodycopy->getKeywords();
372 $replacements = Array();
373 foreach ($keywords as $word) {
376 $bodycopy->setKeywordReplacements($replacements);
379 if ($link_value ==
'display_format') {
381 $datapath = sq_web_path(
'data').
'/asset_types/payment_gateway_sagepay/files';
384 if ($this->
attr(
'run_mode') !=
'Live') {
385 echo
'<h2 class="gateway-test-mode" style="color: white; background-color: #C00; padding: 5px">'.strtoupper($this->
attr(
'run_mode')).
' MODE</h2>';
389 <script src=
"<?php echo $datapath; ?>/loader.js"></script>
391 var Loader =
new Loader(
'<?php echo $card; ?>',
'#FFFFFF',
'Processing Transaction...',
'<?php echo $datapath; ?>/loader.gif');
394 <form method=
"post" action=
"<?php echo $this->getURL(); ?>" onsubmit=
"Loader.show();">
396 $bodycopy->printBody();
400 $bodycopy->printBody();
414 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $link_value);
415 if (empty($link))
return NULL;
416 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
432 if (!$card_info)
return FALSE;
434 $amount = $_SESSION[
'SQ_ECOM_AMOUNT'];
439 if (empty($amount)) {
440 $this->_setError(translate(
'sagepay_amount_not_specified'));
442 $processor->setAmount($amount, $this->
attr(
'currency'));
450 $processor->setMerchantReference(md5(session_id().time()));
453 $_SESSION[
'SQ_ECOM_REF_NO'] = $processor->getMerchantReference();
459 if (empty($card_info[
'name'])) {
460 $this->_setError(translate(
'sagepay_card_name_not_specified'));
462 $processor->setCardName($card_info[
'name']);
466 if (empty($card_info[
'number'])) {
467 $this->_setError(translate(
'sagepay_card_number_not_specified'));
469 $card_info[
'number'] = str_replace(Array(
' ',
"\t"),
'', $card_info[
'number']);
470 $processor->setCardNumber($card_info[
'number']);
474 if ($this->_isValidDate(array_get_index($card_info,
'expiry_month',
''), array_get_index($card_info,
'expiry_year',
''))) {
475 $processor->setCardExpiryDate($card_info[
'expiry_month'], $card_info[
'expiry_year']);
477 $this->_setError(translate(
'sagepay_expiry_date_invalid'));
481 if (!empty($card_info[
'start_month']) || !empty($card_info[
'start_year'])) {
482 if ($this->_isValidDate(array_get_index($card_info,
'start_month',
''), array_get_index($card_info,
'start_year',
''))) {
483 $processor->setCardStartDate($card_info[
'start_month'], $card_info[
'start_year']);
485 $this->_setError(translate(
'sagepay_start_date_invalid'));
490 if (!empty($card_info[
'issue_number'])) {
491 if ($this->_isValidIssueNumber($card_info[
'issue_number'])) {
492 $processor->setCardIssueNumber($card_info[
'issue_number']);
494 $this->_setError(translate(
'sagepay_issue_number_invalid'));
499 if (!empty($card_info[
'cv2'])) {
500 if ($this->_isValidCV2($card_info[
'cv2'], $card_info[
'type'])) {
501 $processor->setCardCV2($card_info[
'cv2']);
503 $this->_setError(translate(
'sagepay_card_cv2_invalid'));
508 if (empty($card_info[
'type'])) {
509 $this->_setError(translate(
'sagepay_card_type_not_specified'));
511 $processor->setCardType($card_info[
'type']);
515 $billing_first_names = array_get_index($card_info,
'billing_first_names',
'');
516 if ($billing_first_names !=
'') {
517 $processor->setBillingFirstnames($billing_first_names);
521 $billing_surname = array_get_index($card_info,
'billing_surname',
'');
522 if ($billing_surname !=
'') {
523 $processor->setBillingSurname($billing_surname);
528 $billing_address1 = trim(array_get_index($card_info,
'billing_address1_'.MIN_LINE_IN_ADDRESS,
''));
529 for ($i = MIN_LINE_IN_ADDRESS + 1; $i <= MAX_LINE_IN_ADDRESS; $i++) {
530 $line = array_get_index($card_info,
"billing_address1_$i",
'');
531 if (trim($line) !=
'') {
532 $billing_address1 .=
", $line";
535 if ($billing_address1 !=
'') {
536 $billing_addr .= $billing_address1.
"\n";
537 $processor->setBillingAddress1($billing_address1);
541 $billing_address2 = trim(array_get_index($card_info,
'billing_address2_'.MIN_LINE_IN_ADDRESS,
''));
542 for ($i = MIN_LINE_IN_ADDRESS + 1; $i <= MAX_LINE_IN_ADDRESS; $i++) {
543 $line = array_get_index($card_info,
"billing_address2_$i",
'');
544 if (trim($line) !=
'') {
545 $billing_address2 .=
", $line";
548 if ($billing_address2 !=
'') {
549 $billing_addr .= $billing_address2.
"\n";
550 $processor->setBillingAddress2($billing_address2);
554 $billing_city = array_get_index($card_info,
'billing_city',
'');
555 if ($billing_city !=
'') {
556 $billing_addr .= $billing_city.
"\n";
557 $processor->setBillingCity($billing_city);
561 $billing_state = array_get_index($card_info,
'billing_state',
'');
562 if ($billing_state !=
'') {
563 $billing_addr .= $billing_state.
"\n";
564 $processor->setBillingState($billing_state);
568 $billing_postcode = array_get_index($card_info,
'billing_postcode',
'');
569 if ($billing_postcode !=
'') {
570 $billing_addr .= $billing_postcode.
"\n";
571 $processor->setBillingPostcode($billing_postcode);
575 if ((array_get_index($card_info,
'billing_country',
'') !=
'') || (array_get_index($card_info,
'delivery_country',
'') !=
'')) {
576 global $standards_lists_countries;
577 require_once SQ_FUDGE_PATH.
'/standards_lists/countries.inc';
581 $billing_country_code = array_get_index($card_info,
'billing_country',
'');
582 if ($billing_country_code !=
'') {
583 $billing_country = array_get_index($standards_lists_countries, $billing_country_code, strtoupper($billing_country_code));
584 $billing_addr .= $billing_country.
"\n";
585 $processor->setBillingCountry($billing_country_code);
589 $billing_phone = array_get_index($card_info,
'billing_phone',
'');
590 if ($billing_phone !=
'') {
591 $billing_addr .=
'Phone: '.$billing_phone.
"\n";
592 $processor->setBillingPhone($billing_phone);
595 if ($this->
attr(
'delivery_addr_is_billing_addr')) {
596 $delivery_str =
'billing_';
598 $delivery_str =
'delivery_';
602 $delivery_first_names = array_get_index($card_info, $delivery_str.
'first_names',
'');
603 if ($delivery_first_names !=
'') {
604 $processor->setDeliveryFirstnames($delivery_first_names);
608 $delivery_surname = array_get_index($card_info, $delivery_str.
'surname',
'');
609 if ($delivery_surname !=
'') {
610 $processor->setDeliverySurname($delivery_surname);
615 $delivery_address1 = trim(array_get_index($card_info, $delivery_str.
'address1_'.MIN_LINE_IN_ADDRESS,
''));
616 for ($i = MIN_LINE_IN_ADDRESS + 1; $i <= MAX_LINE_IN_ADDRESS; $i++) {
617 $line = array_get_index($card_info,
"{$delivery_str}address1_$i",
'');
618 if (trim($line) !=
'') {
619 $delivery_address1 .=
", $line";
622 if ($delivery_address1 !=
'') {
623 $delivery_addr .= $delivery_address1.
"\n";
624 $processor->setDeliveryAddress1($delivery_address1);
628 $delivery_address2 = trim(array_get_index($card_info, $delivery_str.
'address2_'.MIN_LINE_IN_ADDRESS,
''));
629 for ($i = MIN_LINE_IN_ADDRESS + 1; $i <= MAX_LINE_IN_ADDRESS; $i++) {
630 $line = array_get_index($card_info,
"{$delivery_str}address2_$i",
'');
631 if (trim($line) !=
'') {
632 $delivery_address2 .=
", $line";
635 if ($delivery_address2 !=
'') {
636 $delivery_addr .= $delivery_address2.
"\n";
637 $processor->setDeliveryAddress2($delivery_address2);
641 $delivery_city = array_get_index($card_info, $delivery_str.
'city',
'');
642 if ($delivery_city !=
'') {
643 $delivery_addr .= $delivery_city.
"\n";
644 $processor->setDeliveryCity($delivery_city);
648 $delivery_state = array_get_index($card_info, $delivery_str.
'state',
'');
649 if ($delivery_state !=
'') {
650 $delivery_addr .= $delivery_state.
"\n";
651 $processor->setDeliveryState($delivery_state);
655 $delivery_postcode = array_get_index($card_info, $delivery_str.
'postcode',
'');
656 if ($delivery_postcode !=
'') {
657 $delivery_addr .= $delivery_postcode.
"\n";
658 $processor->setDeliveryPostcode($delivery_postcode);
662 $delivery_country_code = array_get_index($card_info, $delivery_str.
'country',
'');
663 if ($delivery_country_code !=
'') {
664 $delivery_country = array_get_index($standards_lists_countries, $delivery_country_code, strtoupper($delivery_country_code));
665 $delivery_addr .= $delivery_country.
"\n";
666 $processor->setDeliveryCountry($delivery_country_code);
670 $delivery_phone = array_get_index($card_info, $delivery_str.
'phone',
'');
671 if ($delivery_phone !=
'') {
672 $delivery_addr .=
'Phone: '.$delivery_phone.
"\n";
673 $processor->setDeliveryPhone($delivery_phone);
678 $processor->setDescription($this->
attr(
'description'));
681 $processor->setTransactionTypePayment();
684 if ($this->
attr(
'threeds_enabled')) {
685 $processor->setThreeDSecure();
689 if ($this->
attr(
'avscv2_enabled')) {
690 $processor->setAVSCV2();
692 if (empty($card_info[
'cv2'])) {
693 $this->_setError(translate(
'sagepay_card_cv2_not_specified'));
696 if ($billing_first_names ==
'') {
697 $this->_setError(translate(
'sagepay_billing_first_names_not_specified'));
699 if ($billing_surname ==
'') {
700 $this->_setError(translate(
'sagepay_billing_surname_not_specified'));
702 if ($billing_address1 ==
'') {
703 $this->_setError(translate(
'sagepay_billing_address1_not_specified'));
705 if ($billing_city ==
'') {
706 $this->_setError(translate(
'sagepay_billing_city_not_specified'));
708 if ($billing_postcode ==
'') {
709 $this->_setError(translate(
'sagepay_billing_postcode_not_specified'));
711 if ($billing_country_code ==
'') {
712 $this->_setError(translate(
'sagepay_billing_country_not_specified'));
714 if (($billing_country_code ==
'us') && ($billing_state ==
'')) {
715 $this->_setError(translate(
'sagepay_billing_state_not_specified'));
718 if (!$this->
attr(
'delivery_addr_is_billing_addr')) {
719 if ($delivery_first_names ==
'') {
720 $this->_setError(translate(
'sagepay_delivery_first_names_not_specified'));
722 if ($delivery_surname ==
'') {
723 $this->_setError(translate(
'sagepay_delivery_surname_not_specified'));
725 if ($delivery_address1 ==
'') {
726 $this->_setError(translate(
'sagepay_delivery_address1_not_specified'));
728 if ($delivery_city ==
'') {
729 $this->_setError(translate(
'sagepay_delivery_city_not_specified'));
731 if ($delivery_postcode ==
'') {
732 $this->_setError(translate(
'sagepay_delivery_postcode_not_specified'));
734 if ($delivery_country_code ==
'') {
735 $this->_setError(translate(
'sagepay_delivery_country_not_specified'));
737 if (($delivery_country_code ==
'us') && ($delivery_state ==
'')) {
738 $this->_setError(translate(
'sagepay_delivery_state_not_specified'));
744 $var_name = $this->
attr(
'giftaid_var_name');
745 if (!empty($var_name)) {
746 $gift_aid = $this->_getPassThroughVariable($var_name, FALSE);
747 if ($gift_aid !== FALSE){
748 $gift_aid = strtolower($gift_aid);
749 if (($gift_aid ==
'1') || ($gift_aid ==
'yes') || ($gift_aid ==
'true')) {
750 $processor->setGiftAidPayment();
760 $success = $processor->process();
763 $response = $processor->getResponse();
768 $_SESSION[
'SQ_ECOM_FORMATTED_CARD_NUMBER'] = $this->_getFormattedCardNumber($card_info[
'number']);
770 $_SESSION[
'SQ_ECOM_ORDER_BILLING_NAME'] =
"$billing_first_names $billing_surname";
771 $_SESSION[
'SQ_ECOM_ORDER_BILLING_ADDR'] = $billing_addr;
772 $_SESSION[
'SQ_ECOM_ORDER_DELIVERY_NAME'] =
"$delivery_first_names $delivery_surname";
773 $_SESSION[
'SQ_ECOM_ORDER_DELIVERY_ADDR'] = $delivery_addr;
775 $billing_state_str =
'';
776 if ($billing_state !=
'') {
777 $billing_state_str = <<<HEREDOC
779 <state><![CDATA[{$this->_getCDATAAllowedString($billing_state)}]]></state>
783 $delivery_state_str =
'';
784 if ($delivery_state !=
'') {
785 $delivery_state_str = <<<HEREDOC
787 <state><![CDATA[{$this->_getCDATAAllowedString($delivery_state)}]]></state>
791 $_SESSION[
'SQ_ECOM_ORDER_PAYMENT_GATEWAY_XML'] = <<<HEREDOC
795 <first_names><![CDATA[{$this->_getCDATAAllowedString($billing_first_names)}]]></first_names>
796 <surname><![CDATA[{$this->_getCDATAAllowedString($billing_surname)}]]></surname>
797 <address1><![CDATA[{$this->_getCDATAAllowedString($billing_address1)}]]></address1>
798 <address2><![CDATA[{$this->_getCDATAAllowedString($billing_address2)}]]></address2>
799 <city><![CDATA[{$this->_getCDATAAllowedString($billing_city)}]]></city>$billing_state_str
800 <postcode><![CDATA[{$this->_getCDATAAllowedString($billing_postcode)}]]></postcode>
801 <country><![CDATA[{$this->_getCDATAAllowedString($billing_country)}]]></country>
802 <country_code><![CDATA[{$this->_getCDATAAllowedString($billing_country_code)}]]></country_code>
803 <phone><![CDATA[{$this->_getCDATAAllowedString($billing_phone)}]]></phone>
806 <first_names><![CDATA[{$this->_getCDATAAllowedString($delivery_first_names)}]]></first_names>
807 <surname><![CDATA[{$this->_getCDATAAllowedString($delivery_surname)}]]></surname>
808 <address1><![CDATA[{$this->_getCDATAAllowedString($delivery_address1)}]]></address1>
809 <address2><![CDATA[{$this->_getCDATAAllowedString($delivery_address2)}]]></address2>
810 <city><![CDATA[{$this->_getCDATAAllowedString($delivery_city)}]]></city>$delivery_state_str
811 <postcode><![CDATA[{$this->_getCDATAAllowedString($delivery_postcode)}]]></postcode>
812 <country><![CDATA[{$this->_getCDATAAllowedString($delivery_country)}]]></country>
813 <country_code><![CDATA[{$this->_getCDATAAllowedString($delivery_country_code)}]]></country_code>
814 <phone><![CDATA[{$this->_getCDATAAllowedString($delivery_phone)}]]></phone>
822 if ($success === 2) {
823 $this->_redirect_info = $response;
826 $this->_setTransactionResult($success, $response);
847 $success = $processor->authorize($_SESSION[
'SQ_ECOM_REF_NO'], $md, $pares);
850 $response = $processor->getResponse();
852 $this->_setTransactionResult($success, $response);
868 private function _setTransactionResult($success, $response)
870 if ($success === FALSE) {
871 $this->_setError($response[
'STATUS']);
873 if ($this->
attr(
'run_mode') !=
'Live') {
874 $response[
'STATUS'] =
'!!!ATTENTION!!! '.strtoupper($this->
attr(
'run_mode')).
' MODE (transaction not performed) -- '.$response[
'STATUS'];
878 if (isset($_SESSION[
'SQ_ECOM_FORMATTED_CARD_NUMBER'])) {
879 $card_no = $_SESSION[
'SQ_ECOM_FORMATTED_CARD_NUMBER'];
880 unset($_SESSION[
'SQ_ECOM_FORMATTED_CARD_NUMBER']);
883 $response[
'CARDNO'] = $card_no;
884 $response[
'AMOUNT'] = $_SESSION[
'SQ_ECOM_AMOUNT'];
887 if (isset($_SESSION[
'SQ_ECOM_ORDER_BILLING_NAME'])) {
888 $billing_name = $_SESSION[
'SQ_ECOM_ORDER_BILLING_NAME'];
889 unset($_SESSION[
'SQ_ECOM_ORDER_BILLING_NAME']);
891 $response[
'BILLING_NAME'] = $billing_name;
894 if (isset($_SESSION[
'SQ_ECOM_ORDER_BILLING_ADDR'])) {
895 $billing_addr = $_SESSION[
'SQ_ECOM_ORDER_BILLING_ADDR'];
896 unset($_SESSION[
'SQ_ECOM_ORDER_BILLING_ADDR']);
898 $response[
'BILLING_ADDR'] = $billing_addr;
901 if (isset($_SESSION[
'SQ_ECOM_ORDER_DELIVERY_NAME'])) {
902 $delivery_name = $_SESSION[
'SQ_ECOM_ORDER_DELIVERY_NAME'];
903 unset($_SESSION[
'SQ_ECOM_ORDER_DELIVERY_NAME']);
905 $response[
'DELIVERY_NAME'] = $delivery_name;
908 if (isset($_SESSION[
'SQ_ECOM_ORDER_DELIVERY_ADDR'])) {
909 $delivery_addr = $_SESSION[
'SQ_ECOM_ORDER_DELIVERY_ADDR'];
910 unset($_SESSION[
'SQ_ECOM_ORDER_DELIVERY_ADDR']);
912 $response[
'DELIVERY_ADDR'] = $delivery_addr;
915 if (isset($_SESSION[
'SQ_ECOM_ORDER_PAYMENT_GATEWAY_XML'])) {
916 $addresses_xml = $_SESSION[
'SQ_ECOM_ORDER_PAYMENT_GATEWAY_XML'];
917 unset($_SESSION[
'SQ_ECOM_ORDER_PAYMENT_GATEWAY_XML']);
919 $response[
'PAYMENT_GATEWAY_XML'] = $addresses_xml;
921 $_SESSION[
'SQ_ECOM_RESPONSE'] = $response;
935 private function _getFormattedCardNumber($card_number)
937 $card_no = $card_number;
938 $card_len = strlen($card_no);
939 if ($card_len == 16) {
940 $card_no =
'****-****-****-'.substr($card_no, -4);
942 $card_no = str_pad(substr($card_no, -4), $card_len,
'*', STR_PAD_LEFT);
962 if ($state ==
'SUCCESS') {
963 $back_url = array_get_index($_SESSION,
'SQ_ECOM_SUCCESS_URL');
964 }
else if ($state ==
'CANCEL') {
965 $back_url = array_get_index($_SESSION,
'SQ_ECOM_CANCEL_URL');
968 unset($_SESSION[
'SQ_ECOM_SUCCESS_URL']);
969 unset($_SESSION[
'SQ_ECOM_CANCEL_URL']);
971 if (is_null($back_url)) {
973 $this->_redirectParent($this->
getURL().
'?unknown_referer=1');
975 trigger_error(
'Unknown caller reference');
980 $this->_redirectParent($back_url);
982 header(
'Location: '.$back_url);
998 private function _redirectParent($url)
1000 $string = <<<HEREDOC
1001 <script
type=
"text/javascript">
1002 if (parent !=
self) {
1003 parent.location =
"{$url}";
1023 $string =
'<input name="'.$card.
'[name]" autocomplete="off" />';
1038 $card = $prefix.
'_card';
1041 if ($this->
attr(
'run_mode') !=
'Live') {
1043 $card_number =
'<select name="'.$card.
'[number]">';
1044 foreach ($test_card_numbers as $number => $label) {
1045 $card_number .=
'<option value="'.$number.
'" >'.$label.
'</option>';
1047 $card_number .=
'</select>';
1049 $card_number =
'<input name="'.$card.
'[number]" autocomplete="off" />';
1052 return $card_number;
1067 $string =
'<input name="'.$card.
'[start_month]" size="2" autocomplete="off" />';
1084 $string =
'<select name="'.$card.
'[start_month]">';
1085 $string .=
'<option value="" >--</option>';
1086 for ($i = 1; $i <= 12; $i++) {
1087 $month = sprintf(
'%02s', $i);
1088 $string .=
'<option value="'.$month.
'" >'.$month.
'</option>';
1090 $string .=
'</select>';
1107 $string =
'<input name="'.$card.
'[start_year]" size="2" autocomplete="off" />';
1124 $string =
'<select name="'.$card.
'[start_year]">';
1125 $string .=
'<option value="" >----</option>';
1126 $year = date(
'Y') - $period;
1127 for ($i = 0; $i <= $period; $i++) {
1128 $string .=
'<option value="'.substr($year, -2).
'" >'.$year.
'</option>';
1131 $string .=
'</select>';
1148 $string =
'<input name="'.$card.
'[expiry_month]" size="2" autocomplete="off" />';
1165 $string =
'<select name="'.$card.
'[expiry_month]">';
1166 $string .=
'<option value="" >--</option>';
1167 for ($i = 1; $i <= 12; $i++) {
1168 $month = sprintf(
'%02s', $i);
1169 $string .=
'<option value="'.$month.
'" >'.$month.
'</option>';
1171 $string .=
'</select>';
1188 $string =
'<input name="'.$card.
'[expiry_year]" size="2" autocomplete="off" />';
1205 $string =
'<select name="'.$card.
'[expiry_year]">';
1206 $string .=
'<option value="" >----</option>';
1208 for ($i = 0; $i <= $period; $i++) {
1209 $string .=
'<option value="'.substr($year, -2).
'" >'.$year.
'</option>';
1212 $string .=
'</select>';
1229 $string =
'<input name="'.$card.
'[issue_number]" size="4" autocomplete="off" />';
1246 $string =
'<input name="'.$card.
'[cv2]" size="4" autocomplete="off" />';
1265 $selected_card_types = explode(
'|', $this->
attr(
'supported_card_types'));
1268 echo
'<select name="'.$card.
'[type]">';
1269 foreach ($selected_card_types as $type) {
1270 echo
'<option value="'.$type.
'">'.$available_card_types[$type].
'</option>';
1275 return ob_get_clean();
1290 text_box($card.
'[billing_first_names]', $this->_getDefaultInputFromPassThroughAttribute(
'firstname_var_name'));
1292 return ob_get_clean();
1307 text_box($card.
'[billing_surname]', $this->_getDefaultInputFromPassThroughAttribute(
'surname_var_name'));
1309 return ob_get_clean();
1326 text_box($card.
"[billing_address1_$line]", $this->_getDefaultInputFromPassThroughAttribute(
'addr1_var_name', $line));
1328 return ob_get_clean();
1345 text_box($card.
"[billing_address2_$line]", $this->_getDefaultInputFromPassThroughAttribute(
'addr2_var_name', $line));
1347 return ob_get_clean();
1362 text_box($card.
'[billing_city]', $this->_getDefaultInputFromPassThroughAttribute(
'city_var_name'));
1364 return ob_get_clean();
1379 text_box($card.
'[billing_postcode]', $this->_getDefaultInputFromPassThroughAttribute(
'postcode_var_name'));
1381 return ob_get_clean();
1394 global $standards_lists_countries;
1395 require_once SQ_FUDGE_PATH.
'/standards_lists/countries.inc';
1399 combo_box($card.
'[billing_country]', $standards_lists_countries, FALSE, $this->_getDefaultInputFromPassThroughAttribute(
'country_var_name'));
1401 return ob_get_clean();
1415 $string =
'<input name="'.$card.
'[billing_state]" />';
1430 $string =
'<input name="'.$card.
'[billing_phone]" autocomplete="off" />';
1446 $this->
_delivery_textbox($card.
'[delivery_first_names]', $this->_getDefaultInputFromPassThroughAttribute(
'firstname_var_name'));
1448 return ob_get_clean();
1463 $this->
_delivery_textbox($card.
'[delivery_surname]', $this->_getDefaultInputFromPassThroughAttribute(
'surname_var_name'));
1465 return ob_get_clean();
1482 $this->
_delivery_textbox($card.
"[delivery_address1_$line]", $this->_getDefaultInputFromPassThroughAttribute(
'addr1_var_name', $line));
1484 return ob_get_clean();
1501 $this->
_delivery_textbox($card.
"[delivery_address2_$line]", $this->_getDefaultInputFromPassThroughAttribute(
'addr2_var_name', $line));
1503 return ob_get_clean();
1518 $this->
_delivery_textbox($card.
'[delivery_city]', $this->_getDefaultInputFromPassThroughAttribute(
'city_var_name'));
1520 return ob_get_clean();
1535 $this->
_delivery_textbox($card.
'[delivery_postcode]', $this->_getDefaultInputFromPassThroughAttribute(
'postcode_var_name'));
1537 return ob_get_clean();
1552 $name = $card.
'[delivery_country]';
1553 $value = $this->_getDefaultInputFromPassThroughAttribute(
'country_var_name');
1554 if ($this->
attr(
'hide_delivery_addr')) {
1555 hidden_field($name, $value);
1557 global $standards_lists_countries;
1558 require_once SQ_FUDGE_PATH.
'/standards_lists/countries.inc';
1560 combo_box($name, $standards_lists_countries, FALSE, $value);
1563 return ob_get_clean();
1577 $string =
'<input name="'.$card.
'[delivery_state]" />';
1592 $string =
'<input name="'.$card.
'[delivery_phone]" />';
1606 $amount = array_get_index($_SESSION,
'SQ_ECOM_AMOUNT', 0);
1622 return '<span class="payment-gateway-transaction-error">'.$this->getErrorMessage().
'</span>';
1638 $button_text = $this->
attr(
'submit_text');
1639 if (empty($button_text)) $button_text =
'Submit';
1641 return '<input type="submit" value="'.$button_text.
'" />';
1654 $button_text = $this->
attr(
'reset_text');
1655 if (empty($button_text)) $button_text =
'Reset';
1657 return '<input type="reset" value="'.$button_text.
'" />';
1670 $button_text = $this->
attr(
'cancel_text');
1671 if (empty($button_text)) $button_text =
'Cancel';
1673 return '<input type="submit" name="'.$this->getPrefix().
'_action" value="'.$button_text.
'" />';
1686 $string = <<<HEREDOC
1687 <form name=
"PARequestForm" action=
"{$this->_redirect_info['ACS_URL']}" method=
"POST">
1688 <input type=
"hidden" name=
"PaReq" value=
"{$this->_redirect_info['PAREQ_MESSAGE']}">
1689 <input type=
"hidden" name=
"TermUrl" value=
"{$this->getURL()}">
1690 <input type=
"hidden" name=
"MD" value=
"{$this->_redirect_info['MD']}">
1692 <iframe name=
"ACSframe" width=
"390" height=
"400" frameborder=
"0">
1693 <b>Your browser does not support iframes</b>
1695 <script type=
"text/javascript">
1696 window.onload =
function()
1698 document.PARequestForm.target =
"ACSframe";
1699 document.PARequestForm.submit();
1716 private function _setError($err_message)
1718 $this->_tmp[
'is_error'] = TRUE;
1721 $errs = explode(
',', $err_message);
1722 foreach ($errs as $err_str) {
1723 $err_details = explode(
':', $err_str, 2);
1724 if (isset($err_details[1]) && !empty($err_details[1])) {
1725 $this->_tmp[
'error_message'][] = trim($err_details[1]);
1727 $this->_tmp[
'error_message'][] = $err_details[0];
1742 private function _isValidDate($month, $year)
1746 $two_digits_pattern =
'/^\d{2}$/';
1748 if (preg_match($two_digits_pattern, $month) && preg_match($two_digits_pattern, $year)) {
1750 if ((0 < $month) && ($month < 13)) {
1768 private function _isValidIssueNumber($issue_no)
1772 $pattern =
'/^\d{1,2}$/';
1774 if (preg_match($pattern, $issue_no)) {
1792 private function _isValidCV2($cv2, $card_type)
1796 if ($card_type ==
'AMEX') {
1801 $pattern =
'/^\d{'.$digit_no.
'}$/';
1803 if (preg_match($pattern, $cv2)) {
1820 private function _getPassThroughVariable($var_name, $default)
1822 if (is_null($this->_pass_through_vars)) {
1823 $this->_pass_through_vars = array_get_index($_SESSION,
'SQ_ECOM_PASS_THROUGH_VARS', Array());
1826 return array_get_index($this->_pass_through_vars, $var_name, $default);
1840 private function _getDefaultInputFromPassThroughAttribute($attr_name, $line =
'')
1843 $var_name = $this->
attr($attr_name).$line;
1844 if (!empty($var_name)) {
1845 $result = $this->_getPassThroughVariable($var_name,
'');
1860 private function _getCDATAAllowedString($text)
1863 $search = Array(
'<![CDATA[',
']]>');
1864 $replace = Array(
'<![CDATA[',
']]>');
1866 return str_replace($search, $replace, $text);
1882 if ($this->
attr(
'hide_delivery_addr')) {
1883 hidden_field($name, $value);
1885 text_box($name, $value);
1899 return array_get_index($this->_tmp,
'is_error', FALSE);
1913 $errors = array_get_index($this->_tmp,
'error_message', Array());
1914 foreach ($errors as $error) {
1915 $err_message .=
"<li>$error </li>";
1918 return '<ul>'.$err_message.
'</ul>';