PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/includes/modules/payment/ipayment_elv.php

https://github.com/chrish123/oscommerce2
PHP | 269 lines | 201 code | 53 blank | 15 comment | 37 complexity | 576238fe76a45550405403efec4e77d2 MD5 | raw file
  1. <?php
  2. /*
  3. $Id$
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Copyright (c) 2010 osCommerce
  7. Released under the GNU General Public License
  8. */
  9. class ipayment_elv {
  10. var $code, $title, $description, $enabled;
  11. // class constructor
  12. function ipayment_elv() {
  13. global $order;
  14. $this->signature = 'ipayment|ipayment_elv|1.0|2.2';
  15. $this->api_version = '2.0';
  16. $this->code = 'ipayment_elv';
  17. $this->title = MODULE_PAYMENT_IPAYMENT_ELV_TEXT_TITLE;
  18. $this->public_title = MODULE_PAYMENT_IPAYMENT_ELV_TEXT_PUBLIC_TITLE;
  19. $this->description = MODULE_PAYMENT_IPAYMENT_ELV_TEXT_DESCRIPTION;
  20. $this->sort_order = MODULE_PAYMENT_IPAYMENT_ELV_SORT_ORDER;
  21. $this->enabled = ((MODULE_PAYMENT_IPAYMENT_ELV_STATUS == 'True') ? true : false);
  22. if ((int)MODULE_PAYMENT_IPAYMENT_ELV_ORDER_STATUS_ID > 0) {
  23. $this->order_status = MODULE_PAYMENT_IPAYMENT_ELV_ORDER_STATUS_ID;
  24. }
  25. $this->gateway_addresses = array('212.227.34.218', '212.227.34.219', '212.227.34.220');
  26. if (is_object($order)) $this->update_status();
  27. $this->form_action_url = 'https://ipayment.de/merchant/' . MODULE_PAYMENT_IPAYMENT_ELV_ID . '/processor/2.0/';
  28. }
  29. // class methods
  30. function update_status() {
  31. global $order;
  32. if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_IPAYMENT_ELV_ZONE > 0) ) {
  33. $check_flag = false;
  34. $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_IPAYMENT_ELV_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  35. while ($check = tep_db_fetch_array($check_query)) {
  36. if ($check['zone_id'] < 1) {
  37. $check_flag = true;
  38. break;
  39. } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  40. $check_flag = true;
  41. break;
  42. }
  43. }
  44. if ($check_flag == false) {
  45. $this->enabled = false;
  46. }
  47. }
  48. }
  49. function javascript_validation() {
  50. return false;
  51. }
  52. function selection() {
  53. return array('id' => $this->code,
  54. 'module' => $this->public_title);
  55. }
  56. function pre_confirmation_check() {
  57. return false;
  58. }
  59. function confirmation() {
  60. global $order;
  61. $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_IPAYMENT_ELV_TEXT_BANK_ACCOUNT_OWNER,
  62. 'field' => tep_draw_input_field('addr_name', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
  63. array('title' => MODULE_PAYMENT_IPAYMENT_ELV_TEXT_BANK_ACCOUNT_NUMBER,
  64. 'field' => tep_draw_input_field('bank_accountnumber')),
  65. array('title' => MODULE_PAYMENT_IPAYMENT_ELV_TEXT_BANK_CODE,
  66. 'field' => tep_draw_input_field('bank_code')),
  67. array('title' => MODULE_PAYMENT_IPAYMENT_ELV_TEXT_BANK_NAME,
  68. 'field' => tep_draw_input_field('bank_name'))));
  69. return $confirmation;
  70. }
  71. function process_button() {
  72. global $order, $currency;
  73. $zone_code = '';
  74. if (is_numeric($order->billing['zone_id']) && ($order->billing['zone_id'] > 0)) {
  75. $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_id = '" . (int)$order->billing['zone_id'] . "'");
  76. if (tep_db_num_rows($zone_query)) {
  77. $zone = tep_db_fetch_array($zone_query);
  78. $zone_code = $zone['zone_code'];
  79. }
  80. }
  81. $process_button_string = tep_draw_hidden_field('silent', '1') .
  82. tep_draw_hidden_field('trx_paymenttyp', 'elv') .
  83. tep_draw_hidden_field('trxuser_id', MODULE_PAYMENT_IPAYMENT_ELV_USER_ID) .
  84. tep_draw_hidden_field('trxpassword', MODULE_PAYMENT_IPAYMENT_ELV_PASSWORD) .
  85. tep_draw_hidden_field('from_ip', tep_get_ip_address()) .
  86. tep_draw_hidden_field('trx_currency', $currency) .
  87. tep_draw_hidden_field('trx_amount', $this->format_raw($order->info['total'])*100) .
  88. tep_draw_hidden_field('trx_typ', ((MODULE_PAYMENT_IPAYMENT_ELV_TRANSACTION_METHOD == 'Capture') ? 'auth' : 'preauth')) .
  89. tep_draw_hidden_field('addr_email', $order->customer['email_address']) .
  90. tep_draw_hidden_field('addr_street', $order->billing['street_address']) .
  91. tep_draw_hidden_field('addr_city', $order->billing['city']) .
  92. tep_draw_hidden_field('addr_zip', $order->billing['postcode']) .
  93. tep_draw_hidden_field('addr_country', $order->billing['country']['iso_code_2']) .
  94. tep_draw_hidden_field('addr_state', $zone_code) .
  95. tep_draw_hidden_field('addr_telefon', $order->customer['telephone']) .
  96. tep_draw_hidden_field('redirect_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true)) .
  97. tep_draw_hidden_field('silent_error_url', tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL', true)) .
  98. tep_draw_hidden_field('hidden_trigger_url', tep_href_link('ext/modules/payment/ipayment/callback_elv.php', '', 'SSL', false)) .
  99. tep_draw_hidden_field('client_name', 'oscommerce') .
  100. tep_draw_hidden_field('client_version', $this->signature);
  101. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD)) {
  102. $process_button_string .= tep_draw_hidden_field('trx_securityhash', md5(MODULE_PAYMENT_IPAYMENT_ELV_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . MODULE_PAYMENT_IPAYMENT_ELV_PASSWORD . MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD));
  103. }
  104. return $process_button_string;
  105. }
  106. function before_process() {
  107. global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $order, $currency;
  108. if ($HTTP_GET_VARS['ret_errorcode'] != '0') {
  109. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . tep_output_string_protected($HTTP_GET_VARS['ret_errormsg'])));
  110. }
  111. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD)) {
  112. $pass = true;
  113. // verify ret_param_checksum
  114. if ($HTTP_GET_VARS['ret_param_checksum'] != md5(MODULE_PAYMENT_IPAYMENT_ELV_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . $HTTP_GET_VARS['ret_authcode'] . $HTTP_GET_VARS['ret_booknr'] . MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD)) {
  115. $pass = false;
  116. }
  117. // verify ret_url_checksum
  118. $url= 'http' . (ENABLE_SSL == true ? 's' : '') . '://' . $HTTP_SERVER_VARS['SERVER_NAME'] . $HTTP_SERVER_VARS['REQUEST_URI'];
  119. $url_without_checksum = substr($url, 0, strpos($url, '&ret_url_checksum')+1);
  120. if ($HTTP_GET_VARS['ret_url_checksum'] != md5($url_without_checksum . MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD)) {
  121. $pass = false;
  122. }
  123. if ($pass != true) {
  124. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code));
  125. }
  126. }
  127. return false;
  128. }
  129. function after_process() {
  130. return false;
  131. }
  132. function get_error() {
  133. global $HTTP_GET_VARS;
  134. $error = array('title' => MODULE_PAYMENT_IPAYMENT_ELV_ERROR_HEADING,
  135. 'error' => ((isset($HTTP_GET_VARS['error'])) ? stripslashes(urldecode($HTTP_GET_VARS['error'])) : MODULE_PAYMENT_IPAYMENT_ELV_ERROR_MESSAGE));
  136. return $error;
  137. }
  138. function check() {
  139. if (!isset($this->_check)) {
  140. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_IPAYMENT_ELV_STATUS'");
  141. $this->_check = tep_db_num_rows($check_query);
  142. }
  143. return $this->_check;
  144. }
  145. function install() {
  146. 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 iPayment (ELV)', 'MODULE_PAYMENT_IPAYMENT_ELV_STATUS', 'False', 'Do you want to accept iPayment (ELV) payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  147. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Account Number', 'MODULE_PAYMENT_IPAYMENT_ELV_ID', '99999', 'The account number used for the iPayment service', '6', '2', now())");
  148. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('User ID', 'MODULE_PAYMENT_IPAYMENT_ELV_USER_ID', '99998', 'The user ID for the iPayment service', '6', '3', now())");
  149. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('User Password', 'MODULE_PAYMENT_IPAYMENT_ELV_PASSWORD', '0', 'The user password for the iPayment service', '6', '4', now())");
  150. 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 Method', 'MODULE_PAYMENT_IPAYMENT_ELV_TRANSACTION_METHOD', 'Authorization', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Capture\'), ', now())");
  151. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Secret Hash Password', 'MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD', 'testtest', 'The secret hash password to validate transactions with', '6', '4', now())");
  152. tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Transaction Notification (E-Mail)', 'MODULE_PAYMENT_IPAYMENT_ELV_DEBUG_EMAIL', '', 'An e-mail address to send transaction notifications to.', '6', '0', now())");
  153. 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_IPAYMENT_ELV_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
  154. 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_IPAYMENT_ELV_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())");
  155. 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_IPAYMENT_ELV_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())");
  156. }
  157. function remove() {
  158. tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  159. }
  160. function keys() {
  161. return array('MODULE_PAYMENT_IPAYMENT_ELV_STATUS', 'MODULE_PAYMENT_IPAYMENT_ELV_ID', 'MODULE_PAYMENT_IPAYMENT_ELV_USER_ID', 'MODULE_PAYMENT_IPAYMENT_ELV_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_ELV_TRANSACTION_METHOD', 'MODULE_PAYMENT_IPAYMENT_ELV_SECRET_HASH_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_ELV_DEBUG_EMAIL', 'MODULE_PAYMENT_IPAYMENT_ELV_ZONE', 'MODULE_PAYMENT_IPAYMENT_ELV_ORDER_STATUS_ID', 'MODULE_PAYMENT_IPAYMENT_ELV_SORT_ORDER');
  162. }
  163. // format prices without currency formatting
  164. function format_raw($number, $currency_code = '', $currency_value = '') {
  165. global $currencies, $currency;
  166. if (empty($currency_code) || !$this->is_set($currency_code)) {
  167. $currency_code = $currency;
  168. }
  169. if (empty($currency_value) || !is_numeric($currency_value)) {
  170. $currency_value = $currencies->currencies[$currency_code]['value'];
  171. }
  172. return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
  173. }
  174. function sendDebugEmail($checksum_match = 0) {
  175. global $HTTP_POST_VARS, $HTTP_GET_VARS;
  176. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_ELV_DEBUG_EMAIL)) {
  177. $email_body = 'iPayment (ELV) Transaction' . "\n\n" .
  178. 'Date: ' . strftime(DATE_TIME_FORMAT) . "\n" .
  179. 'Checksum Match: ';
  180. switch ($checksum_match) {
  181. case 1:
  182. $email_body .= 'Valid';
  183. break;
  184. case -1:
  185. $email_body .= '##### Invalid #####';
  186. break;
  187. case 0:
  188. default:
  189. $email_body .= 'Unknown';
  190. break;
  191. }
  192. $email_body .= "\n\n" .
  193. 'POST REQUEST:' . "\n\n";
  194. if (!empty($HTTP_POST_VARS)) {
  195. foreach ($HTTP_POST_VARS as $key => $value) {
  196. $email_body .= $key . '=' . $value . "\n";
  197. }
  198. } else {
  199. $email_body .= '(empty)' . "\n";
  200. }
  201. $email_body .= "\n" . 'GET REQUEST:' . "\n\n";
  202. if (!empty($HTTP_GET_VARS)) {
  203. foreach ($HTTP_GET_VARS as $key => $value) {
  204. $email_body .= $key . '=' . $value . "\n";
  205. }
  206. } else {
  207. $email_body .= '(empty)' . "\n";
  208. }
  209. tep_mail('', MODULE_PAYMENT_IPAYMENT_ELV_DEBUG_EMAIL, 'iPayment (ELV) Transaction', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
  210. }
  211. }
  212. }
  213. ?>