PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/payment/ps_pbs.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 303 lines | 235 code | 12 blank | 56 comment | 25 complexity | a9b9ad6ad6d231a2513c5be7004c4ec8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: ps_pbs.php 1095 2007-12-19 20:19:16Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage payment
  8. * @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * The ps_pbs class, containing the payment processing code
  20. * for transactions with PBS supported Payment Gateways
  21. * @author soeren
  22. */
  23. class ps_pbs {
  24. var $payment_code = "PBS";
  25. var $classname = "ps_pbs";
  26. /**
  27. * Show all configuration parameters for this payment method
  28. * @returns boolean False when the Payment method has no configration
  29. */
  30. function show_configuration() {
  31. global $VM_LANG, $mosConfig_live_site;
  32. $db =& new ps_DB;
  33. /** Read current Configuration ***/
  34. require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
  35. ?>
  36. <table>
  37. <tr>
  38. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBS_MERCHANT_ID') ?></strong></td>
  39. <td>
  40. <input type="text" name="PBS_MERCHANT_ID" class="inputbox" value="<?php echo PBS_MERCHANT_ID ?>" />
  41. </td>
  42. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBS_MERCHANT_ID_EXPLAIN') ?></td>
  43. </tr>
  44. <tr>
  45. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBD_GATEWAY') ?></strong></td>
  46. <td>
  47. <select name="PBS_GATEWAY" onchange="updateExtraInfo();" class="inputbox">
  48. <option <?php if (PBS_GATEWAY == 'freeway.dk') echo "selected=\"selected\""; ?> value="freeway.dk">freeway.dk</option>
  49. <option <?php if (PBS_GATEWAY == 'danhost.dk') echo "selected=\"selected\""; ?> value="danhost.dk">danhost.dk</option>
  50. <!--<option <?php if (PBS_GATEWAY == 'webhosting.dk') echo "selected=\"selected\""; ?> value="webhosting.dk">webhosting.dk</option>-->
  51. <!--<option <?php if (PBS_GATEWAY == 'interpay.dk') echo "selected=\"selected\""; ?> value="interpay.dk">interpay.dk</option>-->
  52. <option <?php if (PBS_GATEWAY == 'wannafind.dk') echo "selected=\"selected\""; ?> value="wannafind.dk">wannafind.dk</option>
  53. <option <?php if (PBS_GATEWAY == 'dandomain.dk') echo "selected=\"selected\""; ?> value="dandomain.dk">dandomain.dk</option>
  54. </select>
  55. </td>
  56. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBD_GATEWAY_EXPLAIN') ?></td>
  57. </tr>
  58. <tr>
  59. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBS_SHOP_ID') ?></strong></td>
  60. <td>
  61. <input type="text" name="PBS_SHOP_ID" class="inputbox" value="<?php echo PBS_SHOP_ID ?>" />
  62. </td>
  63. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PBS_SHOP_ID_EXPLAIN') ?></td>
  64. </tr>
  65. <tr>
  66. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_SUCC') ?></strong></td>
  67. <td>
  68. <select name="PBS_VERIFIED_STATUS" class="inputbox" >
  69. <?php
  70. $q = "SELECT order_status_name,order_status_code FROM #__{vm}_order_status ORDER BY list_order";
  71. $db->query($q);
  72. $order_status_code = Array();
  73. $order_status_name = Array();
  74. while ($db->next_record()) {
  75. $order_status_code[] = $db->f("order_status_code");
  76. $order_status_name[] = $db->f("order_status_name");
  77. }
  78. for ($i = 0; $i < sizeof($order_status_code); $i++) {
  79. echo "<option value=\"" . $order_status_code[$i];
  80. if (PBS_VERIFIED_STATUS == $order_status_code[$i])
  81. echo "\" selected=\"selected\">";
  82. else
  83. echo "\">";
  84. echo $order_status_name[$i] . "</option>\n";
  85. }?>
  86. </select>
  87. </td>
  88. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_SUCC_EXPLAIN') ?></td>
  89. </tr>
  90. <tr>
  91. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_FAIL') ?></strong></td>
  92. <td>
  93. <select name="PBS_INVALID_STATUS" class="inputbox" >
  94. <?php
  95. for ($i = 0; $i < sizeof($order_status_code); $i++) {
  96. echo "<option value=\"" . $order_status_code[$i];
  97. if (PBS_INVALID_STATUS == $order_status_code[$i])
  98. echo "\" selected=\"selected\">";
  99. else
  100. echo "\">";
  101. echo $order_status_name[$i] . "</option>\n";
  102. } ?>
  103. </select>
  104. </td>
  105. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYMENT_ORDERSTATUS_FAIL_EXPLAIN') ?></td>
  106. </tr>
  107. <tr>
  108. <td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE') ?></strong></td>
  109. <td>
  110. <select name="PBS_TEST_MODE" class="inputbox" >
  111. <option <?php if (PBS_TEST_MODE == '1') echo "selected=\"selected\""; ?> value="1"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') ?></option>
  112. <option <?php if (PBS_TEST_MODE == '0') echo "selected=\"selected\""; ?> value="0"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') ?></option>
  113. </select>
  114. </td>
  115. <td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE_EXPLAIN') ?>
  116. </td>
  117. </tr>
  118. </table>
  119. <script type="text/javascript">
  120. function updateExtraInfo() {
  121. var form = document.adminForm;
  122. switch( form.PBS_GATEWAY.selectedIndex ) {
  123. // FreeWay.dk
  124. case 0:
  125. form.payment_extrainfo.value = '<'+'?php\n'
  126. +'// This is the Session ID\n'
  127. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  128. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  129. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  130. +'$sessionid = base64_encode( $sessionid );\n'
  131. +'?>\n'
  132. +'<form action="https://pay.freeway.dk/payform/relay.asp/<'+'?php echo PBS_MERCHANT_ID ?>?sessionid=<'+'?php echo $sessionid ?>" method="post" name="paymentform">\n'
  133. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  134. +'</form>'
  135. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  136. break;
  137. // DanHost.dk
  138. case 1:
  139. form.payment_extrainfo.value = '<'+'?php\n'
  140. +'// This is the Session ID\n'
  141. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  142. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  143. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  144. +'$sessionid = base64_encode( $sessionid );\n'
  145. +'?>\n'
  146. +'<form action="https://gateway.fuzion.dk/" method="post">\n'
  147. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  148. +'<input type="hidden" name="shopid" value="<'+'?php echo PBS_SHOP_ID ?>" />\n'
  149. +'<input type="hidden" name="sessionid" value="<'+'?php echo $sessionid ?>" />\n'
  150. +'<input type="hidden" name="shop_orderid" value="<'+'?php echo $order_id ?>" />\n'
  151. +'</form>'
  152. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  153. break;
  154. // Webhosting.dk
  155. case 2:
  156. form.payment_extrainfo.value = '<'+'?php\n'
  157. +'// This is the Session ID\n'
  158. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  159. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  160. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  161. +'$sessionid = base64_encode( $sessionid );\n'
  162. +'?>\n'
  163. +'<form action="https://secure.webhosting.dk/pbsgateway/index.php" method="post" name="paymentform">\n'
  164. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  165. +'<input type="hidden" name="shopid" value="<'+'?php echo PBS_SHOP_ID ?>" />\n'
  166. +'<input type="hidden" name="sessionid" value="<'+'?php echo $sessionid ?>" />\n'
  167. +'<input type="hidden" name="orderid" value="<'+'?php echo $order_id ?>" />\n'
  168. +'<input type="hidden" name="currencycode" value="208" />\n'
  169. +'<input type="hidden" name="amount" value="<'+'?php echo $db->f("order_total") ?>" />\n'
  170. +'</form>'
  171. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  172. break;
  173. // Interpay.dk
  174. case 3:
  175. form.payment_extrainfo.value = '<'+'?php\n'
  176. +'// This is the Session ID\n'
  177. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  178. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  179. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  180. +'$sessionid = base64_encode( $sessionid );\n'
  181. +'?>\n'
  182. +'<form action="https://pbs.interpay.dk/?sessionid=<'+'?php echo $sessionid ?>&amount=<'+'?php $db->p("order_total") ?>" method="post" name="paymentform">\n'
  183. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  184. +'</form>'
  185. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  186. break;
  187. // WannaFind.dk
  188. case 4:
  189. form.payment_extrainfo.value = '<'+'?php\n'
  190. +'// This is the Session ID\n'
  191. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  192. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  193. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  194. +'$sessionid = base64_encode( $sessionid );\n'
  195. +'?>\n'
  196. +'<form action="https://betaling.wannafind.dk/proxy/p.php/<'+'?php echo $mosConfig_live_site ?>/index.php?option=com_virtuemart&page=checkout.wannafind_cc_form&sessionid=<'+'?php echo $sessionid ?>" method="post" name="paymentform">\n'
  197. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  198. +'<input type="hidden" name="shopid" value="<'+'?php echo PBS_SHOP_ID ?>" />\n'
  199. +'<input type="hidden" name="orderid" value="<'+'?php echo $order_id ?>" />\n'
  200. +'</form>'
  201. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  202. break;
  203. // DanDomain.dk
  204. case 5:
  205. form.payment_extrainfo.value = '<'+'?php\n'
  206. +'// This is the Session ID\n'
  207. +'// It contains the Order ID, the VirtueMart Session ID and an md5 HASH CheckCode\n'
  208. +'$sessionid = sprintf("%08d", $order_id). $_COOKIE[\'virtuemart\'].md5($_SERVER[\'REMOTE_ADDR\']);\n'
  209. +'$sessionid .= md5( $sessionid . $mosConfig_secret . ENCODE_KEY);\n'
  210. +'$sessionid = base64_encode( $sessionid );\n'
  211. +'?>\n'
  212. +'<form action="https://pay.dandomain.dk/securetunnel.asp" method="post" name="paymentform">\n'
  213. +'<input type="image" src="components/com_virtuemart/shop_image/ps_image/payment.gif" name="submit" alt="Pay your Order now - Click here!" align="center" border="0" />\n'
  214. +'<input type="hidden" name="MerchantNumber" value="<'+'?php echo PBS_MERCHANT_ID ?>" />\n'
  215. +'<input type="hidden" name="TunnelURL" value="<'+'?php echo $mosConfig_live_site ?>/index.php?option=com_virtuemart&page=checkout.dandomain_cc_form&sessionid=<'+'?php echo $sessionid ?>" />\n'
  216. +'<input type="hidden" name="shopid" value="<'+'?php echo PBS_SHOP_ID ?>" />\n'
  217. +'<input type="hidden" name="OrderID" value="<'+'?php echo $order_id ?>" />\n'
  218. +'<input type="hidden" name="Amount" value="<'+'?php echo str_replace(".", ",", $db->f("order_total")) ?>" />\n'
  219. +'<input type="hidden" name="CurrencyID" value="208" />\n'
  220. +'</form>'
  221. +'<a href="#" onclick="document.paymentform.submit();">Pay your Order now - Click here!</a>\n';
  222. break;
  223. }
  224. }
  225. </script>
  226. <?php
  227. // return false if there\'s no configuration
  228. return true;
  229. }
  230. function has_configuration() {
  231. // return false if there's no configuration
  232. return true;
  233. }
  234. /**
  235. * Returns the "is_writeable" status of the configuration file
  236. * @param void
  237. * @returns boolean True when the configuration file is writeable, false when not
  238. */
  239. function configfile_writeable() {
  240. return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
  241. }
  242. /**
  243. * Returns the "is_readable" status of the configuration file
  244. * @param void
  245. * @returns boolean True when the configuration file is writeable, false when not
  246. */
  247. function configfile_readable() {
  248. return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
  249. }
  250. /**
  251. * Writes the configuration file for this payment method
  252. * @param array An array of objects
  253. * @returns boolean True when writing was successful
  254. */
  255. function write_configuration( &$d ) {
  256. global $vmLogger;
  257. $my_config_array = array("PBS_MERCHANT_ID" => $d['PBS_MERCHANT_ID'],
  258. "PBS_GATEWAY" => $d['PBS_GATEWAY'],
  259. "PBS_SHOP_ID" => $d['PBS_SHOP_ID'],
  260. "PBS_VERIFIED_STATUS" => $d['PBS_VERIFIED_STATUS'],
  261. "PBS_INVALID_STATUS" => $d['PBS_INVALID_STATUS'],
  262. "PBS_TEST_MODE" => $d['PBS_TEST_MODE']
  263. );
  264. $config = "<?php\n";
  265. $config .= "if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); \n\n";
  266. foreach( $my_config_array as $key => $value ) {
  267. $config .= "define ('$key', '$value');\n";
  268. }
  269. $config .= "?>";
  270. if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
  271. fputs($fp, $config, strlen($config));
  272. fclose ($fp);
  273. return true;
  274. }
  275. else {
  276. $vmLogger->err( "Could not write to configuration file ".CLASSPATH ."payment/".$this->classname.".cfg.php" );
  277. return false;
  278. }
  279. }
  280. /**************************************************************************
  281. ** name: process_payment()
  282. ** created by: ryan
  283. ** description: process transaction for PayMeNow
  284. ** parameters: $order_number, the number of the order, we're processing here
  285. ** $order_total, the total $ of the order
  286. ** returns:
  287. ***************************************************************************/
  288. function process_payment($order_number, $order_total, &$d) {
  289. return true;
  290. }
  291. }