PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/includes/modules/payment/ipayment_pp.php

https://github.com/chrish123/oscommerce2
PHP | 258 lines | 192 code | 51 blank | 15 comment | 37 complexity | 56bfc6c2aa861d84587a55c39e997b41 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_pp {
  10. var $code, $title, $description, $enabled;
  11. // class constructor
  12. function ipayment_pp() {
  13. global $order;
  14. $this->signature = 'ipayment|ipayment_pp|1.0|2.2';
  15. $this->api_version = '2.0';
  16. $this->code = 'ipayment_pp';
  17. $this->title = MODULE_PAYMENT_IPAYMENT_PP_TEXT_TITLE;
  18. $this->public_title = MODULE_PAYMENT_IPAYMENT_PP_TEXT_PUBLIC_TITLE;
  19. $this->description = MODULE_PAYMENT_IPAYMENT_PP_TEXT_DESCRIPTION;
  20. $this->sort_order = MODULE_PAYMENT_IPAYMENT_PP_SORT_ORDER;
  21. $this->enabled = ((MODULE_PAYMENT_IPAYMENT_PP_STATUS == 'True') ? true : false);
  22. if ((int)MODULE_PAYMENT_IPAYMENT_PP_ORDER_STATUS_ID > 0) {
  23. $this->order_status = MODULE_PAYMENT_IPAYMENT_PP_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_PP_ID . '/processor/2.0/';
  28. }
  29. // class methods
  30. function update_status() {
  31. global $order;
  32. if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_IPAYMENT_PP_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_PP_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. return false;
  61. }
  62. function process_button() {
  63. global $order, $currency;
  64. $zone_code = '';
  65. if (is_numeric($order->billing['zone_id']) && ($order->billing['zone_id'] > 0)) {
  66. $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_id = '" . (int)$order->billing['zone_id'] . "'");
  67. if (tep_db_num_rows($zone_query)) {
  68. $zone = tep_db_fetch_array($zone_query);
  69. $zone_code = $zone['zone_code'];
  70. }
  71. }
  72. $process_button_string = tep_draw_hidden_field('silent', '1') .
  73. tep_draw_hidden_field('trx_paymenttyp', 'pp') .
  74. tep_draw_hidden_field('trxuser_id', MODULE_PAYMENT_IPAYMENT_PP_USER_ID) .
  75. tep_draw_hidden_field('trxpassword', MODULE_PAYMENT_IPAYMENT_PP_PASSWORD) .
  76. tep_draw_hidden_field('from_ip', tep_get_ip_address()) .
  77. tep_draw_hidden_field('trx_currency', $currency) .
  78. tep_draw_hidden_field('trx_amount', $this->format_raw($order->info['total'])*100) .
  79. tep_draw_hidden_field('trx_typ', ((MODULE_PAYMENT_IPAYMENT_PP_TRANSACTION_METHOD == 'Capture') ? 'auth' : 'preauth')) .
  80. tep_draw_hidden_field('addr_email', $order->customer['email_address']) .
  81. tep_draw_hidden_field('addr_street', $order->billing['street_address']) .
  82. tep_draw_hidden_field('addr_city', $order->billing['city']) .
  83. tep_draw_hidden_field('addr_zip', $order->billing['postcode']) .
  84. tep_draw_hidden_field('addr_country', $order->billing['country']['iso_code_2']) .
  85. tep_draw_hidden_field('addr_state', $zone_code) .
  86. tep_draw_hidden_field('addr_telefon', $order->customer['telephone']) .
  87. tep_draw_hidden_field('redirect_url', tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true)) .
  88. tep_draw_hidden_field('silent_error_url', tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code, 'SSL', true)) .
  89. tep_draw_hidden_field('hidden_trigger_url', tep_href_link('ext/modules/payment/ipayment/callback_pp.php', '', 'SSL', false)) .
  90. tep_draw_hidden_field('client_name', 'oscommerce') .
  91. tep_draw_hidden_field('client_version', $this->signature);
  92. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD)) {
  93. $process_button_string .= tep_draw_hidden_field('trx_securityhash', md5(MODULE_PAYMENT_IPAYMENT_PP_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . MODULE_PAYMENT_IPAYMENT_PP_PASSWORD . MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD));
  94. }
  95. return $process_button_string;
  96. }
  97. function before_process() {
  98. global $HTTP_GET_VARS, $HTTP_SERVER_VARS, $order, $currency;
  99. if ($HTTP_GET_VARS['ret_errorcode'] != '0') {
  100. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . tep_output_string_protected($HTTP_GET_VARS['ret_errormsg'])));
  101. }
  102. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD)) {
  103. $pass = true;
  104. // verify ret_param_checksum
  105. if ($HTTP_GET_VARS['ret_param_checksum'] != md5(MODULE_PAYMENT_IPAYMENT_PP_USER_ID . ($this->format_raw($order->info['total']) * 100) . $currency . $HTTP_GET_VARS['ret_authcode'] . $HTTP_GET_VARS['ret_booknr'] . MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD)) {
  106. $pass = false;
  107. }
  108. // verify ret_url_checksum
  109. $url= 'http' . (ENABLE_SSL == true ? 's' : '') . '://' . $HTTP_SERVER_VARS['SERVER_NAME'] . $HTTP_SERVER_VARS['REQUEST_URI'];
  110. $url_without_checksum = substr($url, 0, strpos($url, '&ret_url_checksum')+1);
  111. if ($HTTP_GET_VARS['ret_url_checksum'] != md5($url_without_checksum . MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD)) {
  112. $pass = false;
  113. }
  114. if ($pass != true) {
  115. tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code));
  116. }
  117. }
  118. return false;
  119. }
  120. function after_process() {
  121. return false;
  122. }
  123. function get_error() {
  124. global $HTTP_GET_VARS;
  125. $error = array('title' => MODULE_PAYMENT_IPAYMENT_PP_ERROR_HEADING,
  126. 'error' => ((isset($HTTP_GET_VARS['error'])) ? stripslashes(urldecode($HTTP_GET_VARS['error'])) : MODULE_PAYMENT_IPAYMENT_PP_ERROR_MESSAGE));
  127. return $error;
  128. }
  129. function check() {
  130. if (!isset($this->_check)) {
  131. $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_IPAYMENT_PP_STATUS'");
  132. $this->_check = tep_db_num_rows($check_query);
  133. }
  134. return $this->_check;
  135. }
  136. function install() {
  137. 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 (Prepaid)', 'MODULE_PAYMENT_IPAYMENT_PP_STATUS', 'False', 'Do you want to accept iPayment (Prepaid) payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
  138. 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_PP_ID', '999997', 'The account number used for the iPayment service', '6', '2', now())");
  139. 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_PP_USER_ID', '999997', 'The user ID for the iPayment service', '6', '3', now())");
  140. 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_PP_PASSWORD', '999997', 'The user password for the iPayment service', '6', '4', now())");
  141. 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_PP_TRANSACTION_METHOD', 'Authorization', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Capture\'), ', now())");
  142. 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_PP_SECRET_HASH_PASSWORD', '', 'The secret hash password to validate transactions with', '6', '4', 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 ('Transaction Notification (E-Mail)', 'MODULE_PAYMENT_IPAYMENT_PP_DEBUG_EMAIL', '', 'An e-mail address to send transaction notifications to.', '6', '0', now())");
  144. 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_PP_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
  145. 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_PP_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())");
  146. 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_PP_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())");
  147. }
  148. function remove() {
  149. tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  150. }
  151. function keys() {
  152. return array('MODULE_PAYMENT_IPAYMENT_PP_STATUS', 'MODULE_PAYMENT_IPAYMENT_PP_ID', 'MODULE_PAYMENT_IPAYMENT_PP_USER_ID', 'MODULE_PAYMENT_IPAYMENT_PP_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_PP_TRANSACTION_METHOD', 'MODULE_PAYMENT_IPAYMENT_PP_SECRET_HASH_PASSWORD', 'MODULE_PAYMENT_IPAYMENT_PP_DEBUG_EMAIL', 'MODULE_PAYMENT_IPAYMENT_PP_ZONE', 'MODULE_PAYMENT_IPAYMENT_PP_ORDER_STATUS_ID', 'MODULE_PAYMENT_IPAYMENT_PP_SORT_ORDER');
  153. }
  154. // format prices without currency formatting
  155. function format_raw($number, $currency_code = '', $currency_value = '') {
  156. global $currencies, $currency;
  157. if (empty($currency_code) || !$this->is_set($currency_code)) {
  158. $currency_code = $currency;
  159. }
  160. if (empty($currency_value) || !is_numeric($currency_value)) {
  161. $currency_value = $currencies->currencies[$currency_code]['value'];
  162. }
  163. return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
  164. }
  165. function sendDebugEmail($checksum_match = 0) {
  166. global $HTTP_POST_VARS, $HTTP_GET_VARS;
  167. if (tep_not_null(MODULE_PAYMENT_IPAYMENT_PP_DEBUG_EMAIL)) {
  168. $email_body = 'iPayment (Prepaid) Transaction' . "\n\n" .
  169. 'Date: ' . strftime(DATE_TIME_FORMAT) . "\n" .
  170. 'Checksum Match: ';
  171. switch ($checksum_match) {
  172. case 1:
  173. $email_body .= 'Valid';
  174. break;
  175. case -1:
  176. $email_body .= '##### Invalid #####';
  177. break;
  178. case 0:
  179. default:
  180. $email_body .= 'Unknown';
  181. break;
  182. }
  183. $email_body .= "\n\n" .
  184. 'POST REQUEST:' . "\n\n";
  185. if (!empty($HTTP_POST_VARS)) {
  186. foreach ($HTTP_POST_VARS as $key => $value) {
  187. $email_body .= $key . '=' . $value . "\n";
  188. }
  189. } else {
  190. $email_body .= '(empty)' . "\n";
  191. }
  192. $email_body .= "\n" . 'GET REQUEST:' . "\n\n";
  193. if (!empty($HTTP_GET_VARS)) {
  194. foreach ($HTTP_GET_VARS as $key => $value) {
  195. $email_body .= $key . '=' . $value . "\n";
  196. }
  197. } else {
  198. $email_body .= '(empty)' . "\n";
  199. }
  200. tep_mail('', MODULE_PAYMENT_IPAYMENT_PP_DEBUG_EMAIL, 'iPayment (Prepaid) Transaction', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
  201. }
  202. }
  203. }
  204. ?>