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

/includes/modules/payment/worldpay.php

https://github.com/digineo/xt-commerce
PHP | 201 lines | 114 code | 32 blank | 55 comment | 17 complexity | 9f5609b50073947eb0e8fa5ac76c7e19 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* -----------------------------------------------------------------------------------------
  3. $Id: worldpay.php,v 1.0
  4. XT-Commerce - community made shopping
  5. http://www.xt-commerce.com
  6. modified for XT-Commerce by XTC-Webservice.de http://www.xtc-webservice.de
  7. Copyright (c) 2003 XT-Commerce
  8. -----------------------------------------------------------------------------------------
  9. based on:
  10. (c) 2000-2001 The Exchange Project (earlier name of osCommerce)
  11. (c) 2002-2003 osCommerce(world.php,v Version 1.6); www.oscommerce.com
  12. Released under the GNU General Public License
  13. Third Party contribution:
  14. ************************************************************************
  15. $Id: worldpay.php,v MS1a 2003/04/06 21:30
  16. Author : Graeme Conkie (graeme@conkie.net)
  17. Title: WorldPay Payment Callback Module V4.0 Version 1.6
  18. Revisions:
  19. Paulz added minor changes to enable control of 'Payment Zone' added function update_status
  20. Version MS1a Cleaned up code, moved static English to language file to allow for bi-lingual use,
  21. Now posting language code to WP, Redirect on failure now to Checkout Payment,
  22. Reduced re-direct time to 8 seconds, added MD5, made callback dynamic
  23. NOTE: YOU MUST CHANGE THE CALLBACK URL IN WP ADMIN TO <wpdisplay item="MC_callback">
  24. Version 1.4 Removes boxes to prevent users from clicking away before update,
  25. Fixes currency for Yen,
  26. Redirects to Checkout_Process after 10 seconds or click by user
  27. Version 1.3 Fixes problem with Multi Currency
  28. Version 1.2 Added Sort Order and Default order status to work with snapshots after 14 Jan 2003
  29. Version 1.1 Added Worldpay Pre-Authorisation ability
  30. Version 1.0 Initial Payment Module
  31. osCommerce, Open Source E-Commerce Solutions
  32. http://www.oscommerce.com
  33. Copyright (c) 2003
  34. Released under the GNU General Public License
  35. -----------------------------------------------------------------------------------------*/
  36. class worldpay {
  37. var $code, $title, $description, $enabled;
  38. // class constructor
  39. function worldpay() {
  40. global $order;
  41. $this->code = 'worldpay';
  42. $this->title = MODULE_PAYMENT_WORLDPAY_TEXT_TITLE;
  43. $this->description = MODULE_PAYMENT_WORLDPAY_TEXT_DESC;
  44. $this->sort_order = MODULE_PAYMENT_WORLDPAY_SORT_ORDER;
  45. $this->enabled = ((MODULE_PAYMENT_WORLDPAY_STATUS == 'True') ? true : false);
  46. $this->info = MODULE_PAYMENT_WORLDPAY_TEXT_INFO;
  47. if ((int) MODULE_PAYMENT_WORLDPAY_ORDER_STATUS_ID > 0) {
  48. $this->order_status = MODULE_PAYMENT_WORLDPAY_ORDER_STATUS_ID;
  49. }
  50. if (is_object($order))
  51. $this->update_status();
  52. $this->form_action_url = 'https://select.worldpay.com/wcc/purchase';
  53. }
  54. // class methods
  55. function update_status() {
  56. global $order;
  57. if (($this->enabled == true) && ((int) MODULE_PAYMENT_WORLDPAY_ZONE > 0)) {
  58. $check_flag = false;
  59. $check_query = xtc_db_query("select zone_id from ".TABLE_ZONES_TO_GEO_ZONES." where geo_zone_id = '".MODULE_PAYMENT_WORLDPAY_ZONE."' and zone_country_id = '".$order->billing['country']['id']."' order by zone_id");
  60. while ($check = xtc_db_fetch_array($check_query)) {
  61. if ($check['zone_id'] < 1) {
  62. $check_flag = true;
  63. break;
  64. }
  65. elseif ($check['zone_id'] == $order->billing['zone_id']) {
  66. $check_flag = true;
  67. break;
  68. }
  69. }
  70. if ($check_flag == false) {
  71. $this->enabled = false;
  72. }
  73. }
  74. }
  75. // class methods
  76. function javascript_validation() {
  77. return false;
  78. }
  79. function selection() {
  80. return array ('id' => $this->code, 'module' => $this->title, 'description' => $this->info);
  81. }
  82. function pre_confirmation_check() {
  83. return false;
  84. }
  85. function confirmation() {
  86. return false;
  87. }
  88. function process_button() {
  89. global $order, $xtPrice;
  90. $worldpay_url = xtc_session_name().'='.xtc_session_id();
  91. $total = number_format($order->info['total'], $xtPrice->get_decimal_places($_SESSION['currency']), '.', '');
  92. $process_button_string = xtc_draw_hidden_field('instId', MODULE_PAYMENT_WORLDPAY_ID).xtc_draw_hidden_field('currency', $_SESSION['currency']).xtc_draw_hidden_field('desc', 'Purchase from '.STORE_NAME).xtc_draw_hidden_field('cartId', $worldpay_url).xtc_draw_hidden_field('amount', $total);
  93. // Pre Auth Mod 3/1/2002 - Graeme Conkie
  94. if (MODULE_PAYMENT_WORLDPAY_USEPREAUTH == 'True')
  95. $process_button_string .= xtc_draw_hidden_field('authMode', MODULE_PAYMENT_WORLDPAY_PREAUTH);
  96. // Ian-san: Create callback and language links here 6/4/2003:
  97. $language_code_raw = xtc_db_query("select code from ".TABLE_LANGUAGES." where languages_id ='".$_SESSION['languages_id']."'");
  98. $language_code_array = xtc_db_fetch_array($language_code_raw);
  99. $language_code = $language_code_array['code'];
  100. $address = htmlspecialchars($order->customer['street_address']."\n".$order->customer['suburb']."\n".$order->customer['city']."\n".$order->customer['state'], ENT_QUOTES);
  101. $process_button_string .= xtc_draw_hidden_field('testMode', MODULE_PAYMENT_WORLDPAY_MODE).xtc_draw_hidden_field('name', $order->customer['firstname'].' '.$order->customer['lastname']).xtc_draw_hidden_field('address', $address).xtc_draw_hidden_field('postcode', $order->customer['postcode']).xtc_draw_hidden_field('country', $order->customer['country']['iso_code_2']).xtc_draw_hidden_field('tel', $order->customer['telephone']).xtc_draw_hidden_field('myvar', 'Y').xtc_draw_hidden_field('fax', $order->customer['fax']).xtc_draw_hidden_field('email', $order->customer['email_address']).
  102. // Ian-san: Added dynamic callback and languages link here 6/4/2003:
  103. xtc_draw_hidden_field('lang', $language_code).xtc_draw_hidden_field('MC_callback', xtc_href_link('wpcallback.php')).xtc_draw_hidden_field('MC_XTCsid', $XTCsid);
  104. // Ian-san: Added MD5 here 6/4/2003:
  105. if (MODULE_PAYMENT_WORLDPAY_USEMD5 == '1') {
  106. $md5_signature_fields = 'amount:language:email';
  107. $md5_signature = MODULE_PAYMENT_WORLDPAY_MD5KEY.':'. (number_format($order->info['total'] * $currencies->get_value($currency), $currencies->get_decimal_places($currency), '.', '')).':'.$language_code.':'.$order->customer['email_address'];
  108. $md5_signature_md5 = md5($md5_signature);
  109. $process_button_string .= xtc_draw_hidden_field('signatureFields', $md5_signature_fields).xtc_draw_hidden_field('signature', $md5_signature_md5);
  110. }
  111. return $process_button_string;
  112. }
  113. function before_process() {
  114. return false;
  115. }
  116. function after_process() {
  117. global $insert_id;
  118. if ($this->order_status) xtc_db_query("UPDATE ". TABLE_ORDERS ." SET orders_status='".$this->order_status."' WHERE orders_id='".$insert_id."'");
  119. }
  120. function admin_order($oID) {
  121. return false;
  122. }
  123. function output_error() {
  124. return false;
  125. }
  126. function check() {
  127. if (!isset ($this->_check)) {
  128. $check_query = xtc_db_query("select configuration_value from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_WORLDPAY_STATUS'");
  129. $this->_check = xtc_db_num_rows($check_query);
  130. }
  131. return $this->_check;
  132. }
  133. function install() {
  134. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_STATUS', 'True', '6', '1', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  135. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_ID', '00000', '6', '2', now())");
  136. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_MODE', '100', '6', '5', now())");
  137. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_ALLOWED', '', '6', '0', now())");
  138. // Ian-san: Added MD5 here 6/4/2003:
  139. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_USEMD5', '0', '6', '4', now())");
  140. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_MD5KEY', '', '6', '5', now())");
  141. // Pre Auth Mod - Graeme Conkie 13/1/2003
  142. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_SORT_ORDER', '0', '6', '0', now())");
  143. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_USEPREAUTH', 'False', '6', '3', 'xtc_cfg_select_option(array(\'True\', \'False\'), ', now())");
  144. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, use_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_ORDER_STATUS_ID', '0', '6', '0', 'xtc_cfg_pull_down_order_statuses(', 'xtc_get_order_status_name', now())");
  145. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) values ('MODULE_PAYMENT_WORLDPAY_PREAUTH', 'A', '6', '4', now())");
  146. // Paulz zone control 04/04/2004
  147. xtc_db_query("insert into ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_ZONE', '0', '6', '2', 'xtc_get_zone_class_title', 'xtc_cfg_pull_down_zone_classes(', now())");
  148. // Ian-san: Added MD5 here 6/4/2003:
  149. xtc_db_query("delete from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_WORLDPAY_USEMD5'");
  150. xtc_db_query("delete from ".TABLE_CONFIGURATION." where configuration_key = 'MODULE_PAYMENT_WORLDPAY_MD5KEY'");
  151. }
  152. function remove() {
  153. xtc_db_query("delete from ".TABLE_CONFIGURATION." where configuration_key in ('".implode("', '", $this->keys())."')");
  154. }
  155. function keys() {
  156. return array ('MODULE_PAYMENT_WORLDPAY_STATUS', 'MODULE_PAYMENT_WORLDPAY_ID', 'MODULE_PAYMENT_WORLDPAY_MODE', 'MODULE_PAYMENT_WORLDPAY_ALLOWED', 'MODULE_PAYMENT_WORLDPAY_USEPREAUTH', 'MODULE_PAYMENT_WORLDPAY_PREAUTH', 'MODULE_PAYMENT_WORLDPAY_ZONE', 'MODULE_PAYMENT_WORLDPAY_SORT_ORDER', 'MODULE_PAYMENT_WORLDPAY_ORDER_STATUS_ID');
  157. }
  158. }
  159. ?>