PageRenderTime 32ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/includes/modules/payment/secpay.php

https://github.com/chrish123/oscommerce2
PHP | 188 lines | 148 code | 28 blank | 12 comment | 25 complexity | def6b5b601dfb84bd113497e4b6df196 MD5 | raw file
  1. <?php
  2. /*
  3. $Id$
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2003 osCommerce
  7. Released under the GNU General Public License
  8. */
  9. class secpay {
  10. var $code, $title, $description, $enabled;
  11. // class constructor
  12. function secpay() {
  13. global $order;
  14. $this->code = 'secpay';
  15. $this->title = MODULE_PAYMENT_SECPAY_TEXT_TITLE;
  16. $this->description = MODULE_PAYMENT_SECPAY_TEXT_DESCRIPTION;
  17. $this->sort_order = MODULE_PAYMENT_SECPAY_SORT_ORDER;
  18. $this->enabled = ((MODULE_PAYMENT_SECPAY_STATUS == 'True') ? true : false);
  19. if ((int)MODULE_PAYMENT_SECPAY_ORDER_STATUS_ID > 0) {
  20. $this->order_status = MODULE_PAYMENT_SECPAY_ORDER_STATUS_ID;
  21. }
  22. if (is_object($order)) $this->update_status();
  23. $this->form_action_url = 'https://www.secpay.com/java-bin/ValCard';
  24. }
  25. // class methods
  26. function update_status() {
  27. global $order;
  28. if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_SECPAY_ZONE > 0) ) {
  29. $check_flag = false;
  30. $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_SECPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  31. while ($check = tep_db_fetch_array($check_query)) {
  32. if ($check['zone_id'] < 1) {
  33. $check_flag = true;
  34. break;
  35. } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  36. $check_flag = true;
  37. break;
  38. }
  39. }
  40. if ($check_flag == false) {
  41. $this->enabled = false;
  42. }
  43. }
  44. }
  45. function javascript_validation() {
  46. return false;
  47. }
  48. function selection() {
  49. return array('id' => $this->code,
  50. 'module' => $this->title);
  51. }
  52. function pre_confirmation_check() {
  53. return false;
  54. }
  55. function confirmation() {
  56. return false;
  57. }
  58. function process_button() {
  59. global $order, $currencies, $currency;
  60. switch (MODULE_PAYMENT_SECPAY_CURRENCY) {
  61. case 'Default Currency':
  62. $sec_currency = DEFAULT_CURRENCY;
  63. break;
  64. case 'Any Currency':
  65. default:
  66. $sec_currency = $currency;
  67. break;
  68. }
  69. switch (MODULE_PAYMENT_SECPAY_TEST_STATUS) {
  70. case 'Always Fail':
  71. $test_status = 'false';
  72. break;
  73. case 'Production':
  74. $test_status = 'live';
  75. break;
  76. case 'Always Successful':
  77. default:
  78. $test_status = 'true';
  79. break;
  80. }
  81. $process_button_string = tep_draw_hidden_field('merchant', MODULE_PAYMENT_SECPAY_MERCHANT_ID) .
  82. tep_draw_hidden_field('trans_id', STORE_NAME . date('Ymdhis')) .
  83. tep_draw_hidden_field('amount', number_format($order->info['total'] * $currencies->get_value($sec_currency), $currencies->currencies[$sec_currency]['decimal_places'], '.', '')) .
  84. tep_draw_hidden_field('bill_name', $order->billing['firstname'] . ' ' . $order->billing['lastname']) .
  85. tep_draw_hidden_field('bill_addr_1', $order->billing['street_address']) .
  86. tep_draw_hidden_field('bill_addr_2', $order->billing['suburb']) .
  87. tep_draw_hidden_field('bill_city', $order->billing['city']) .
  88. tep_draw_hidden_field('bill_state', $order->billing['state']) .
  89. tep_draw_hidden_field('bill_post_code', $order->billing['postcode']) .
  90. tep_draw_hidden_field('bill_country', $order->billing['country']['title']) .
  91. tep_draw_hidden_field('bill_tel', $order->customer['telephone']) .
  92. tep_draw_hidden_field('bill_email', $order->customer['email_address']) .
  93. tep_draw_hidden_field('ship_name', $order->delivery['firstname'] . ' ' . $order->delivery['lastname']) .
  94. tep_draw_hidden_field('ship_addr_1', $order->delivery['street_address']) .
  95. tep_draw_hidden_field('ship_addr_2', $order->delivery['suburb']) .
  96. tep_draw_hidden_field('ship_city', $order->delivery['city']) .
  97. tep_draw_hidden_field('ship_state', $order->delivery['state']) .
  98. tep_draw_hidden_field('ship_post_code', $order->delivery['postcode']) .
  99. tep_draw_hidden_field('ship_country', $order->delivery['country']['title']) .
  100. tep_draw_hidden_field('currency', $sec_currency) .
  101. tep_draw_hidden_field('callback', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false) . ';' . tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL', false)) .
  102. tep_draw_hidden_field(tep_session_name(), tep_session_id()) .
  103. tep_draw_hidden_field('options', 'test_status=' . $test_status . ',dups=false,cb_post=true,cb_flds=' . tep_session_name());
  104. return $process_button_string;
  105. }
  106. function before_process() {
  107. global $HTTP_POST_VARS;
  108. if ($HTTP_POST_VARS['valid'] == 'true') {
  109. if ($remote_host = getenv('REMOTE_HOST')) {
  110. if ($remote_host != 'secpay.com') {
  111. $remote_host = gethostbyaddr($remote_host);
  112. }
  113. if ($remote_host != 'secpay.com') {
  114. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, tep_session_name() . '=' . $HTTP_POST_VARS[tep_session_name()] . '&payment_error=' . $this->code, 'SSL', false, false));
  115. }
  116. } else {
  117. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, tep_session_name() . '=' . $HTTP_POST_VARS[tep_session_name()] . '&payment_error=' . $this->code, 'SSL', false, false));
  118. }
  119. }
  120. }
  121. function after_process() {
  122. return false;
  123. }
  124. function get_error() {
  125. global $HTTP_GET_VARS;
  126. if (isset($HTTP_GET_VARS['message']) && (strlen($HTTP_GET_VARS['message']) > 0)) {
  127. $error = stripslashes(urldecode($HTTP_GET_VARS['message']));
  128. } else {
  129. $error = MODULE_PAYMENT_SECPAY_TEXT_ERROR_MESSAGE;
  130. }
  131. return array('title' => MODULE_PAYMENT_SECPAY_TEXT_ERROR,
  132. 'error' => $error);
  133. }
  134. function check() {
  135. if (!isset($this->_check)) {
  136. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_SECPAY_STATUS'");
  137. $this->_check = tep_db_num_rows($check_query);
  138. }
  139. return $this->_check;
  140. }
  141. function install() {
  142. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable SECpay Module', 'MODULE_PAYMENT_SECPAY_STATUS', 'True', 'Do you want to accept SECPay payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  143. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Merchant ID', 'MODULE_PAYMENT_SECPAY_MERCHANT_ID', 'secpay', 'Merchant ID to use for the SECPay service', '6', '2', now())");
  144. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Currency', 'MODULE_PAYMENT_SECPAY_CURRENCY', 'Any Currency', 'The currency to use for credit card transactions', '6', '3', 'tep_cfg_select_option(array(\'Any Currency\', \'Default Currency\'), ', now())");
  145. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Mode', 'MODULE_PAYMENT_SECPAY_TEST_STATUS', 'Always Successful', 'Transaction mode to use for the SECPay service', '6', '4', 'tep_cfg_select_option(array(\'Always Successful\', \'Always Fail\', \'Production\'), ', now())");
  146. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_SECPAY_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
  147. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_SECPAY_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
  148. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_SECPAY_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
  149. }
  150. function remove() {
  151. tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  152. }
  153. function keys() {
  154. return array('MODULE_PAYMENT_SECPAY_STATUS', 'MODULE_PAYMENT_SECPAY_MERCHANT_ID', 'MODULE_PAYMENT_SECPAY_CURRENCY', 'MODULE_PAYMENT_SECPAY_TEST_STATUS', 'MODULE_PAYMENT_SECPAY_ZONE', 'MODULE_PAYMENT_SECPAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_SECPAY_SORT_ORDER');
  155. }
  156. }
  157. ?>