Annotation of /com_supacart/trunk/admin_files/classes/payment/ps_echeck.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | /** | ||
| 3 : | * The ps_echeck class, containing the payment processing code | ||
| 4 : | * for eCheck.net transactions with authorize.net | ||
| 5 : | * | ||
| 6 : | * @version $Id: ps_echeck.php 617 2007-01-04 19:43:08Z soeren_nb $ | ||
| 7 : | * @package SupaCart | ||
| 8 : | * @subpackage payment | ||
| 9 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 10 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 11 : | * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant | ||
| 12 : | * to the GNU General Public License, and as distributed it includes or | ||
| 13 : | * is derivative of works licensed under the GNU General Public License or | ||
| 14 : | * other free or open source software licenses. | ||
| 15 : | * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 16 : | * | ||
| 17 : | * http://www.supacart.com | ||
| 18 : | */ | ||
| 19 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 20 : | |||
| 21 : | class ps_echeck { | ||
| 22 : | |||
| 23 : | var $payment_code = "ECK"; | ||
| 24 : | var $classname = "ps_echeck"; | ||
| 25 : | |||
| 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 : | |||
| 32 : | global $VM_LANG, $sess; | ||
| 33 : | $payment_method_id = mosGetParam( $_REQUEST, 'payment_method_id', null ); | ||
| 34 : | /** Read current Configuration ***/ | ||
| 35 : | require_once(CLASSPATH ."payment/".$this->classname.".cfg.php"); ?> | ||
| 36 : | <table> | ||
| 37 : | <tr> | ||
| 38 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE ?></strong></td> | ||
| 39 : | <td> | ||
| 40 : | <select name="ECK_TEST_REQUEST" class="inputbox" > | ||
| 41 : | <option <?php if (ECK_TEST_REQUEST == 'TRUE') echo "selected=\"selected\""; ?> value="TRUE"><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_YES ?></option> | ||
| 42 : | <option <?php if (ECK_TEST_REQUEST == 'FALSE') echo "selected=\"selected\""; ?> value="FALSE"><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_NO ?></option> | ||
| 43 : | </select> | ||
| 44 : | </td> | ||
| 45 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE_EXPLAIN ?> | ||
| 46 : | </td> | ||
| 47 : | </tr> | ||
| 48 : | <tr> | ||
| 49 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_USERNAME ?></strong></td> | ||
| 50 : | <td> | ||
| 51 : | <input type="text" name="ECK_LOGIN" class="inputbox" value="<?php echo ECK_LOGIN ?>" /> | ||
| 52 : | </td> | ||
| 53 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_USERNAME_EXPLAIN ?> | ||
| 54 : | </td> | ||
| 55 : | </tr> | ||
| 56 : | <tr> | ||
| 57 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_KEY ?></strong></td> | ||
| 58 : | <td> | ||
| 59 : | <a id="changekey" href="<?php $sess->purl($_SERVER['PHP_SELF']."?page=store.payment_method_keychange&pshop_mode=admin&payment_method_id=$payment_method_id") ?>" > | ||
| 60 : | <input onclick="document.location=document.getElementById('changekey').href" type="button" name="" value="<?php echo $VM_LANG->_PHPSHOP_CHANGE_TRANSACTION_KEY ?>" /><a/> | ||
| 61 : | </td> | ||
| 62 : | <td> </td> | ||
| 63 : | </tr> | ||
| 64 : | <tr> | ||
| 65 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_PAYMENT_AN_RECURRING ?></strong></td> | ||
| 66 : | <td> | ||
| 67 : | <select name="ECK_RECURRING" class="inputbox"> | ||
| 68 : | <option <?php if (ECK_RECURRING == 'YES') echo "selected=\"selected\""; ?> value="YES"> | ||
| 69 : | <?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_YES ?></option> | ||
| 70 : | <option <?php if (ECK_RECURRING == 'NO') echo "selected=\"selected\""; ?> value="NO"> | ||
| 71 : | <?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_NO ?></option> | ||
| 72 : | </select> | ||
| 73 : | </td> | ||
| 74 : | <td><?php echo $VM_LANG->_PHPSHOP_PAYMENT_AN_RECURRING_TOOLTIP ?> | ||
| 75 : | </td> | ||
| 76 : | </tr> | ||
| 77 : | <tr> | ||
| 78 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_AUTENTICATIONTYPE ?></strong></td> | ||
| 79 : | <td> | ||
| 80 : | <select name="ECK_TYPE" class="inputbox"> | ||
| 81 : | <option <?php if (ECK_TYPE == 'AUTH_CAPTURE') echo "selected=\"selected\""; ?> value="AUTH_CAPTURE">AUTH_CAPTURE</option> | ||
| 82 : | <option <?php if (ECK_TYPE == 'CREDIT') echo "selected=\"selected\""; ?> value="CREDIT">CREDIT</option> | ||
| 83 : | </select> | ||
| 84 : | </td> | ||
| 85 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_AUTENTICATIONTYPE_EXPLAIN ?> | ||
| 86 : | </td> | ||
| 87 : | </tr> | ||
| 88 : | <tr> | ||
| 89 : | <td><strong>eCheck.net Transaction Type</strong></td> | ||
| 90 : | <td> | ||
| 91 : | <select name="ECK_ECHECK_TYPE" class="inputbox"> | ||
| 92 : | <option <?php if (ECK_ECHECK_TYPE == 'CCD') echo "selected=\"selected\""; ?> value="CCD">CCD</option> | ||
| 93 : | <option <?php if (ECK_ECHECK_TYPE == 'PPD') echo "selected=\"selected\""; ?> value="PPD">PPD</option> | ||
| 94 : | <option <?php if (ECK_ECHECK_TYPE == 'TEL') echo "selected=\"selected\""; ?> value="TEL">TEL</option> | ||
| 95 : | <option <?php if (ECK_ECHECK_TYPE == 'WEB') echo "selected=\"selected\""; ?> value="WEB">WEB</option> | ||
| 96 : | </select> | ||
| 97 : | </td> | ||
| 98 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_AUTORIZENET_AUTENTICATIONTYPE_EXPLAIN ?> | ||
| 99 : | </td> | ||
| 100 : | </tr> | ||
| 101 : | </table> | ||
| 102 : | <?php | ||
| 103 : | // return false if there's no configuration | ||
| 104 : | return true; | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | function has_configuration() { | ||
| 108 : | // return false if there's no configuration | ||
| 109 : | return true; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | /** | ||
| 113 : | * Returns the "is_writeable" status of the configuration file | ||
| 114 : | * @param void | ||
| 115 : | * @returns boolean True when the configuration file is writeable, false when not | ||
| 116 : | */ | ||
| 117 : | function configfile_writeable() { | ||
| 118 : | return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" ); | ||
| 119 : | } | ||
| 120 : | |||
| 121 : | /** | ||
| 122 : | * Returns the "is_readable" status of the configuration file | ||
| 123 : | * @param void | ||
| 124 : | * @returns boolean True when the configuration file is writeable, false when not | ||
| 125 : | */ | ||
| 126 : | function configfile_readable() { | ||
| 127 : | return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" ); | ||
| 128 : | } | ||
| 129 : | /** | ||
| 130 : | * Writes the configuration file for this payment method | ||
| 131 : | * @param array An array of objects | ||
| 132 : | * @returns boolean True when writing was successful | ||
| 133 : | */ | ||
| 134 : | function write_configuration( &$d ) { | ||
| 135 : | |||
| 136 : | $my_config_array = array("ECK_TEST_REQUEST" => $d['ECK_TEST_REQUEST'], | ||
| 137 : | "ECK_LOGIN" => $d['ECK_LOGIN'], | ||
| 138 : | "ECK_TYPE" => $d['ECK_TYPE'], | ||
| 139 : | "ECK_ECHECK_TYPE" => $d['ECK_ECHECK_TYPE'], | ||
| 140 : | "ECK_RECURRING" => $d['ECK_RECURRING'] | ||
| 141 : | ); | ||
| 142 : | $config = "<?php\n"; | ||
| 143 : | $config .= "defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); \n\n"; | ||
| 144 : | foreach( $my_config_array as $key => $value ) { | ||
| 145 : | $config .= "define ('$key', '$value');\n"; | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | $config .= "?>"; | ||
| 149 : | |||
| 150 : | if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) { | ||
| 151 : | fputs($fp, $config, strlen($config)); | ||
| 152 : | fclose ($fp); | ||
| 153 : | return true; | ||
| 154 : | } | ||
| 155 : | else | ||
| 156 : | return false; | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | /************************************************************************** | ||
| 160 : | ** name: process_payment() | ||
| 161 : | ** created by: jep | ||
| 162 : | ** description: process transaction authorize.net | ||
| 163 : | ** parameters: $order_number, the number of the order, we're processing here | ||
| 164 : | ** $order_total, the total $ of the order | ||
| 165 : | ** returns: | ||
| 166 : | ***************************************************************************/ | ||
| 167 : | function process_payment($order_number, $order_total, &$d) { | ||
| 168 : | |||
| 169 : | global $vendor_mail, $vendor_currency, $VM_LAN, $vmLogger; | ||
| 170 : | $database = new ps_DB(); | ||
| 171 : | |||
| 172 : | $ps_vendor_id = $_SESSION["ps_vendor_id"]; | ||
| 173 : | $auth = $_SESSION['auth']; | ||
| 174 : | $ps_checkout = new ps_checkout; | ||
| 175 : | |||
| 176 : | /*** Get the Configuration File for authorize.net ***/ | ||
| 177 : | require_once(CLASSPATH ."payment/".$this->classname.".cfg.php"); | ||
| 178 : | |||
| 179 : | // Get the Transaction Key securely from the database | ||
| 180 : | $database->query( "SELECT DECODE(payment_passkey,'".ENCODE_KEY."') as passkey FROM #__{sc}_payment_method WHERE payment_class='".$this->classname."'" ); | ||
| 181 : | $transaction = $database->record[0]; | ||
| 182 : | if( empty($transaction->passkey)) { | ||
| 183 : | $vmLogger->err($VM_LANG->_PHPSHOP_PAYMENT_ERROR); | ||
| 184 : | return false; | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | // Get user billing information | ||
| 188 : | $dbbt = new ps_DB; | ||
| 189 : | $qt = "SELECT * FROM #__{sc}_user_info WHERE user_id='".$auth["user_id"]."' AND address_type='BT'"; | ||
| 190 : | $dbbt->query($qt); | ||
| 191 : | $dbbt->next_record(); | ||
| 192 : | $user_info_id = $dbbt->f("user_info_id"); | ||
| 193 : | if( $user_info_id != $d["ship_to_info_id"]) { | ||
| 194 : | // Get user billing information | ||
| 195 : | $dbst =& new ps_DB; | ||
| 196 : | $qt = "SELECT * FROM #__{sc}_user_info WHERE user_info_id='".$d["ship_to_info_id"]."' AND address_type='ST'"; | ||
| 197 : | $dbst->query($qt); | ||
| 198 : | $dbst->next_record(); | ||
| 199 : | } | ||
| 200 : | else { | ||
| 201 : | $dbst = $dbbt; | ||
| 202 : | } | ||
| 203 : | |||
| 204 : | $host = "secure.authorize.net"; | ||
| 205 : | $port = 443; | ||
| 206 : | $path = "/gateway/transact.dll"; | ||
| 207 : | |||
| 208 : | //Authnet vars to send | ||
| 209 : | $formdata = array ( | ||
| 210 : | 'x_version' => '3.1', | ||
| 211 : | 'x_login' => ECK_LOGIN, | ||
| 212 : | 'x_tran_key' => $transaction->passkey, | ||
| 213 : | 'x_test_request' => ECK_TEST_REQUEST, | ||
| 214 : | |||
| 215 : | 'x_delim_data' => 'TRUE', | ||
| 216 : | 'x_delim_char' => '|', | ||
| 217 : | 'x_relay_response' => 'FALSE', | ||
| 218 : | |||
| 219 : | 'x_first_name' => substr($dbbt->f("first_name"), 0, 50), | ||
| 220 : | 'x_last_name' => substr($dbbt->f("last_name"), 0, 50), | ||
| 221 : | 'x_company' => substr($dbbt->f("company"), 0, 50), | ||
| 222 : | 'x_address' => substr($dbbt->f("address_1"), 0, 60), | ||
| 223 : | 'x_city' => substr($dbbt->f("city"), 0, 40), | ||
| 224 : | 'x_state' => substr($dbbt->f("state"), 0, 40), | ||
| 225 : | 'x_zip' => substr($dbbt->f("zip"), 0, 20), | ||
| 226 : | 'x_country' => substr($dbbt->f("country"), 0, 60), | ||
| 227 : | 'x_phone' => substr($dbbt->f("phone_1"), 0, 25), | ||
| 228 : | 'x_fax' => substr($dbbt->f("fax"), 0, 25), | ||
| 229 : | |||
| 230 : | 'x_ship_to_first_name' => substr($dbst->f("first_name"), 0, 50), | ||
| 231 : | 'x_ship_to_last_name' => substr($dbst->f("last_name"), 0, 50), | ||
| 232 : | 'x_ship_to_company' => substr($dbst->f("company"), 0, 50), | ||
| 233 : | 'x_ship_to_address' => substr($dbst->f("address_1"), 0, 60), | ||
| 234 : | 'x_ship_to_city' => substr($dbst->f("city"), 0, 40), | ||
| 235 : | 'x_ship_to_state' => substr($dbst->f("state"), 0, 40), | ||
| 236 : | 'x_ship_to_zip' => substr($dbst->f("zip"), 0, 20), | ||
| 237 : | 'x_ship_to_country' => substr($dbst->f("country"), 0, 60), | ||
| 238 : | |||
| 239 : | 'x_cust_id' => $auth['user_id'], | ||
| 240 : | 'x_customer_ip' => $_SERVER["REMOTE_ADDR"], | ||
| 241 : | 'x_customer_tax_id' => $dbbt->f("tax_id"), | ||
| 242 : | |||
| 243 : | 'x_email' => $dbbt->f("email"), | ||
| 244 : | 'x_email_customer' => 'True', | ||
| 245 : | 'x_merchant_email' => $vendor_mail, | ||
| 246 : | |||
| 247 : | 'x_invoice_num' => substr($order_number, 0, 20), | ||
| 248 : | 'x_description' => '', | ||
| 249 : | |||
| 250 : | 'x_amount' => $order_total, | ||
| 251 : | 'x_currency_code' => $vendor_currency, | ||
| 252 : | 'x_method' => 'ECHECK', | ||
| 253 : | 'x_type' => ECK_TYPE, | ||
| 254 : | 'x_echeck_type' => ECK_ECHECK_TYPE, | ||
| 255 : | |||
| 256 : | 'x_recurring_billing' => ECK_RECURRING, | ||
| 257 : | |||
| 258 : | 'x_bank_aba_code' => $dbbt->f("bank_iban"), | ||
| 259 : | 'x_bank_acct_num' => $dbbt->f("bank_account_nr"), | ||
| 260 : | 'x_bank_acct_type' => $dbbt->f("bank_account_type"), | ||
| 261 : | 'x_bank_name' => $dbbt->f("bank_name"), | ||
| 262 : | 'x_bank_acct_name' => $dbbt->f("bank_account_holder"), | ||
| 263 : | |||
| 264 : | // Level 2 data | ||
| 265 : | 'x_po_num' => substr($order_number, 0, 20), | ||
| 266 : | 'x_tax' => substr($d['order_tax'], 0, 15), | ||
| 267 : | 'x_tax_exempt' => "FALSE", | ||
| 268 : | 'x_freight' => $d['order_shipping'], | ||
| 269 : | 'x_duty' => 0 | ||
| 270 : | ); | ||
| 271 : | |||
| 272 : | //build the post string | ||
| 273 : | $poststring = ''; | ||
| 274 : | foreach($formdata AS $key => $val){ | ||
| 275 : | $poststring .= urlencode($key) . "=" . urlencode($val) . "&"; | ||
| 276 : | } | ||
| 277 : | // strip off trailing ampersand | ||
| 278 : | $poststring = substr($poststring, 0, -1); | ||
| 279 : | |||
| 280 : | if( function_exists( "curl_init" )) { | ||
| 281 : | |||
| 282 : | $CR = curl_init(); | ||
| 283 : | curl_setopt($CR, CURLOPT_URL, "https://".$host.$path); | ||
| 284 : | curl_setopt($CR, CURLOPT_POST, 1); | ||
| 285 : | curl_setopt($CR, CURLOPT_FAILONERROR, true); | ||
| 286 : | curl_setopt($CR, CURLOPT_POSTFIELDS, $poststring); | ||
| 287 : | curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); | ||
| 288 : | |||
| 289 : | // No PEER certificate validation...as we don't have | ||
| 290 : | // a certificate file for it to authenticate the host www.ups.com against! | ||
| 291 : | curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0); | ||
| 292 : | //curl_setopt($CR, CURLOPT_SSLCERT , "/usr/locale/xxxx/clientcertificate.pem"); | ||
| 293 : | |||
| 294 : | $result = curl_exec( $CR ); | ||
| 295 : | |||
| 296 : | $error = curl_error( $CR ); | ||
| 297 : | if( !empty( $error )) { | ||
| 298 : | $vmLogger->err( curl_error( $CR ) ); | ||
| 299 : | $html = "<br/><span class=\"message\">".$VM_LANG->_PHPSHOP_PAYMENT_INTERNAL_ERROR." authorize.net</span>"; | ||
| 300 : | return false; | ||
| 301 : | } | ||
| 302 : | else { | ||
| 303 : | //echo $result; exit(); | ||
| 304 : | } | ||
| 305 : | curl_close( $CR ); | ||
| 306 : | } | ||
| 307 : | else { | ||
| 308 : | |||
| 309 : | $fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 60); | ||
| 310 : | if(!$fp){ | ||
| 311 : | //error tell us | ||
| 312 : | $vmLogger->err( "$errstr ($errno)" ); | ||
| 313 : | } | ||
| 314 : | else { | ||
| 315 : | |||
| 316 : | //send the server request | ||
| 317 : | fputs($fp, "POST $path HTTP/1.1\r\n"); | ||
| 318 : | fputs($fp, "Host: $host\r\n"); | ||
| 319 : | fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); | ||
| 320 : | fputs($fp, "Content-length: ".strlen($poststring)."\r\n"); | ||
| 321 : | fputs($fp, "Connection: close\r\n\r\n"); | ||
| 322 : | fputs($fp, $poststring . "\r\n\r\n"); | ||
| 323 : | |||
| 324 : | //Get the response header from the server | ||
| 325 : | $str = ''; | ||
| 326 : | while(!feof($fp) && !stristr($str, 'content-length')) { | ||
| 327 : | $str = fgets($fp, 4096); | ||
| 328 : | } | ||
| 329 : | // If didnt get content-lenght, something is wrong, return false. | ||
| 330 : | if (!stristr($str, 'content-length')) { | ||
| 331 : | return false; | ||
| 332 : | |||
| 333 : | } | ||
| 334 : | $data = ""; | ||
| 335 : | while (!feof($fp)) { | ||
| 336 : | $data .= fgets ($fp, 1024); | ||
| 337 : | } | ||
| 338 : | $result = trim( $data ); | ||
| 339 : | /* | ||
| 340 : | // Get length of data to be received. | ||
| 341 : | $length = trim(substr($str,strpos($str,'content-length') + 15)); | ||
| 342 : | // Get buffer (blank data before real data) | ||
| 343 : | fgets($fp, 4096); | ||
| 344 : | // Get real data | ||
| 345 : | $data = fgets($fp, $length); | ||
| 346 : | fclose($fp);*/ | ||
| 347 : | |||
| 348 : | } | ||
| 349 : | } | ||
| 350 : | $response = explode("|", $result); | ||
| 351 : | |||
| 352 : | // Approved - Success! | ||
| 353 : | if ($response[0] == '1') { | ||
| 354 : | $d["order_payment_log"] = $VM_LANG->_PHPSHOP_PAYMENT_TRANSACTION_SUCCESS.": "; | ||
| 355 : | $d["order_payment_log"] .= $response[3]; | ||
| 356 : | return True; | ||
| 357 : | } | ||
| 358 : | // Payment Declined | ||
| 359 : | elseif ($response[0] == '2') { | ||
| 360 : | $vmLogger->err($response[3]); | ||
| 361 : | $d["order_payment_log"] = $response[3]; | ||
| 362 : | return False; | ||
| 363 : | } | ||
| 364 : | // Transaction Error | ||
| 365 : | elseif ($response[0] == '3') { | ||
| 366 : | $vmLogger->err($response[3]); | ||
| 367 : | $d["order_payment_log"] = $response[3]; | ||
| 368 : | return False; | ||
| 369 : | } | ||
| 370 : | } | ||
| 371 : | |||
| 372 : | |||
| 373 : | |||
| 374 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

