Annotation of /com_supacart/trunk/admin_files/classes/payment/ps_skipjack.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 3 : | /** | ||
| 4 : | * | ||
| 5 : | * @version $Id: ps_skipjack.php 617 2007-01-04 19:43:08Z soeren_nb $ | ||
| 6 : | * @package SupaCart | ||
| 7 : | * @subpackage payment | ||
| 8 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 9 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 10 : | * SupaCart is free software, originally derived from Virtuemart. 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_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 15 : | * | ||
| 16 : | * http://www.supacart.com | ||
| 17 : | */ | ||
| 18 : | |||
| 19 : | /** | ||
| 20 : | * | ||
| 21 : | * The ps_skipjack class, containing the payment processing code | ||
| 22 : | * for transactions with Skipjack.com | ||
| 23 : | * @copyright (C) 2005 Matthew Schick | ||
| 24 : | */ | ||
| 25 : | class ps_skipjack { | ||
| 26 : | |||
| 27 : | var $payment_code = "SKJ"; | ||
| 28 : | var $classname = "ps_skipjack"; | ||
| 29 : | var $error_codes = array("-35" => "Invalid credit card number", | ||
| 30 : | "-37" => "Failed communication", | ||
| 31 : | "-39" => "Length serial number", | ||
| 32 : | "-51" => "Length zip code", | ||
| 33 : | "-52" => "Length shipto zip code", | ||
| 34 : | "-53" => "Length expiration date", | ||
| 35 : | "-54" => "Length account number date", | ||
| 36 : | "-55" => "Length street address", | ||
| 37 : | "-56" => "Length shipto street address", | ||
| 38 : | "-57" => "Length transaction amount", | ||
| 39 : | "-58" => "Length name", | ||
| 40 : | "-59" => "Length location", | ||
| 41 : | "-60" => "Length state", | ||
| 42 : | "-61" => "Length shipto state", | ||
| 43 : | "-62" => "Length order string", | ||
| 44 : | "-64" => "Invalid phone number", | ||
| 45 : | "-65" => "Empty name", | ||
| 46 : | "-66" => "Empty email", | ||
| 47 : | "-67" => "Empty street address", | ||
| 48 : | "-68" => "Empty city", | ||
| 49 : | "-69" => "Empty state", | ||
| 50 : | "-79" => "Length customer name", | ||
| 51 : | "-80" => "Length shipto customer name", | ||
| 52 : | "-81" => "Length customer location", | ||
| 53 : | "-82" => "Length customer state", | ||
| 54 : | "-83" => "Length shipto phone", | ||
| 55 : | "-84" => "Duplicate ordernumber", | ||
| 56 : | "-91" => "CVV2", | ||
| 57 : | "-92" => "Error Approval Code", | ||
| 58 : | "-93" => "Blind Credits Not Allowed", | ||
| 59 : | "-94" => "Blind Credits Failed", | ||
| 60 : | "-95" => "Voice Authorizations Not Allowed" ); | ||
| 61 : | |||
| 62 : | /** | ||
| 63 : | * Show all configuration parameters for this payment method | ||
| 64 : | * @returns boolean False when the Payment method has no configration | ||
| 65 : | */ | ||
| 66 : | function show_configuration() { | ||
| 67 : | |||
| 68 : | global $VM_LANG, $sess; | ||
| 69 : | $payment_method_id = mosGetParam( $_REQUEST, 'payment_method_id', null ); | ||
| 70 : | $db =& new ps_DB; | ||
| 71 : | /** Read current Configuration ***/ | ||
| 72 : | require_once(CLASSPATH ."payment/".$this->classname.".cfg.php"); | ||
| 73 : | ?> | ||
| 74 : | <table> | ||
| 75 : | <tr> | ||
| 76 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_ENABLE_SKJ_TESTMODE ?></strong></td> | ||
| 77 : | <td> | ||
| 78 : | <select name="SKJ_TEST_REQUEST" class="inputbox" > | ||
| 79 : | <option <?php if (SKJ_TEST_REQUEST == 'TRUE') echo "selected=\"selected\""; ?> value="TRUE"><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_YES ?></option> | ||
| 80 : | <option <?php if (SKJ_TEST_REQUEST == 'FALSE') echo "selected=\"selected\""; ?> value="FALSE"><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_NO ?></option> | ||
| 81 : | </select> | ||
| 82 : | </td> | ||
| 83 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_ENABLE_SKJ_TESTMODE_EXPLAIN ?> | ||
| 84 : | </td> | ||
| 85 : | </tr> | ||
| 86 : | <tr> | ||
| 87 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_SKJ_SERIAL ?></strong></td> | ||
| 88 : | <td> | ||
| 89 : | <input type="text" name="SKJ_SERIAL" class="inputbox" value="<?php echo SKJ_SERIAL ?>" /> | ||
| 90 : | </td> | ||
| 91 : | <td><?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_SKJ_SERIAL_EXPLAIN ?></td> | ||
| 92 : | </tr> | ||
| 93 : | <tr> | ||
| 94 : | <td><strong><?php echo $VM_LANG->_PHPSHOP_PAYMENT_CVV2 ?></strong></td> | ||
| 95 : | <td> | ||
| 96 : | <select name="SKJ_CHECK_CARD_CODE" class="inputbox"> | ||
| 97 : | <option <?php if (SKJ_CHECK_CARD_CODE == 'YES') echo "selected=\"selected\""; ?> value="YES"> | ||
| 98 : | <?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_YES ?></option> | ||
| 99 : | <option <?php if (SKJ_CHECK_CARD_CODE == 'NO') echo "selected=\"selected\""; ?> value="NO"> | ||
| 100 : | <?php echo $VM_LANG->_PHPSHOP_ADMIN_CFG_NO ?></option> | ||
| 101 : | </select> | ||
| 102 : | </td> | ||
| 103 : | <td><?php echo $VM_LANG->_PHPSHOP_PAYMENT_CVV2_TOOLTIP ?></td> | ||
| 104 : | </tr> | ||
| 105 : | <tr><td colspan="3"><hr/></td></tr> | ||
| 106 : | <tr> | ||
| 107 : | <td><strong>Order Status for successful transactions</strong></td> | ||
| 108 : | <td> | ||
| 109 : | <select name="SKJ_VERIFIED_STATUS" class="inputbox" > | ||
| 110 : | <?php | ||
| 111 : | $q = "SELECT order_status_name,order_status_code FROM #__{sc}_order_status ORDER BY list_order"; | ||
| 112 : | $db->query($q); | ||
| 113 : | $order_status_code = Array(); | ||
| 114 : | $order_status_name = Array(); | ||
| 115 : | |||
| 116 : | while ($db->next_record()) { | ||
| 117 : | $order_status_code[] = $db->f("order_status_code"); | ||
| 118 : | $order_status_name[] = $db->f("order_status_name"); | ||
| 119 : | } | ||
| 120 : | for ($i = 0; $i < sizeof($order_status_code); $i++) { | ||
| 121 : | echo "<option value=\"" . $order_status_code[$i]; | ||
| 122 : | if (SKJ_VERIFIED_STATUS == $order_status_code[$i]) | ||
| 123 : | echo "\" selected=\"selected\">"; | ||
| 124 : | else | ||
| 125 : | echo "\">"; | ||
| 126 : | echo $order_status_name[$i] . "</option>\n"; | ||
| 127 : | }?> | ||
| 128 : | </select> | ||
| 129 : | </td> | ||
| 130 : | <td>Select the order status to which the actual order is set, if the Skipjack Transaction was successful. | ||
| 131 : | If using download selling options: select the status which enables the download (then the customer is instantly notified about the download via e-mail). | ||
| 132 : | </td> | ||
| 133 : | </tr> | ||
| 134 : | <tr> | ||
| 135 : | <td><strong>Order Status for failed transactions</strong></td> | ||
| 136 : | <td> | ||
| 137 : | <select name="SKJ_INVALID_STATUS" class="inputbox" > | ||
| 138 : | <?php | ||
| 139 : | for ($i = 0; $i < sizeof($order_status_code); $i++) { | ||
| 140 : | echo "<option value=\"" . $order_status_code[$i]; | ||
| 141 : | if (SKJ_INVALID_STATUS == $order_status_code[$i]) | ||
| 142 : | echo "\" selected=\"selected\">"; | ||
| 143 : | else | ||
| 144 : | echo "\">"; | ||
| 145 : | echo $order_status_name[$i] . "</option>\n"; | ||
| 146 : | } ?> | ||
| 147 : | </select> | ||
| 148 : | </td> | ||
| 149 : | <td>Select an order status for failed Skipjack transactions.</td> | ||
| 150 : | </tr> | ||
| 151 : | </table> | ||
| 152 : | <?php | ||
| 153 : | // return false if there's no configuration | ||
| 154 : | return true; | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | function has_configuration() { | ||
| 158 : | // return false if there's no configuration | ||
| 159 : | return true; | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | /** | ||
| 163 : | * Returns the "is_writeable" status of the configuration file | ||
| 164 : | * @param void | ||
| 165 : | * @returns boolean True when the configuration file is writeable, false when not | ||
| 166 : | */ | ||
| 167 : | function configfile_writeable() { | ||
| 168 : | return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" ); | ||
| 169 : | } | ||
| 170 : | |||
| 171 : | /** | ||
| 172 : | * Returns the "is_readable" status of the configuration file | ||
| 173 : | * @param void | ||
| 174 : | * @returns boolean True when the configuration file is writeable, false when not | ||
| 175 : | */ | ||
| 176 : | function configfile_readable() { | ||
| 177 : | return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" ); | ||
| 178 : | } | ||
| 179 : | /** | ||
| 180 : | * Writes the configuration file for this payment method | ||
| 181 : | * @param array An array of objects | ||
| 182 : | * @returns boolean True when writing was successful | ||
| 183 : | */ | ||
| 184 : | function write_configuration( &$d ) { | ||
| 185 : | |||
| 186 : | $my_config_array = array("SKJ_TEST_REQUEST" => $d['SKJ_TEST_REQUEST'], | ||
| 187 : | "SKJ_SERIAL" => $d['SKJ_SERIAL'], | ||
| 188 : | "SKJ_INVALID_STATUS" => $d['SKJ_INVALID_STATUS'], | ||
| 189 : | "SKJ_VERIFIED_STATUS" => $d['SKJ_VERIFIED_STATUS'], | ||
| 190 : | "SKJ_CHECK_CARD_CODE" => $d['SKJ_CHECK_CARD_CODE'] | ||
| 191 : | ); | ||
| 192 : | $config = "<?php\n"; | ||
| 193 : | $config .= "defined('_VALID_MOS') or die('Direct Access to this location is not allowed.'); \n\n"; | ||
| 194 : | foreach( $my_config_array as $key => $value ) { | ||
| 195 : | $config .= "define ('$key', '$value');\n"; | ||
| 196 : | } | ||
| 197 : | |||
| 198 : | $config .= "?>"; | ||
| 199 : | |||
| 200 : | if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) { | ||
| 201 : | fputs($fp, $config, strlen($config)); | ||
| 202 : | fclose ($fp); | ||
| 203 : | return true; | ||
| 204 : | } | ||
| 205 : | else | ||
| 206 : | return false; | ||
| 207 : | } | ||
| 208 : | |||
| 209 : | /************************************************************************** | ||
| 210 : | ** name: process_payment() | ||
| 211 : | ** created by: Matthew Schick | ||
| 212 : | ** description: process transaction Skipjack.com | ||
| 213 : | ** parameters: $order_number, the number of the order, we're processing here | ||
| 214 : | ** $order_total, the total $ of the order | ||
| 215 : | ** returns: | ||
| 216 : | ***************************************************************************/ | ||
| 217 : | function process_payment($order_number, $order_total, &$d) { | ||
| 218 : | |||
| 219 : | global $vendor_mail, $vendor_currency, $VM_LANG, $vmLogger; | ||
| 220 : | |||
| 221 : | $ps_vendor_id = $_SESSION["ps_vendor_id"]; | ||
| 222 : | $auth = $_SESSION['auth']; | ||
| 223 : | $ps_checkout = new ps_checkout; | ||
| 224 : | |||
| 225 : | /*** Get the Configuration File for Skipjack.com ***/ | ||
| 226 : | require_once(CLASSPATH ."payment/".$this->classname.".cfg.php"); | ||
| 227 : | |||
| 228 : | // Get user billing information | ||
| 229 : | $dbbt = new ps_DB; | ||
| 230 : | $qt = "SELECT * FROM #__{sc}_user_info WHERE user_id='".$auth["user_id"]."' AND address_type='BT'"; | ||
| 231 : | $dbbt->query($qt); | ||
| 232 : | $dbbt->next_record(); | ||
| 233 : | $user_info_id = $dbbt->f("user_info_id"); | ||
| 234 : | if( $user_info_id != $d["ship_to_info_id"]) { | ||
| 235 : | // Get user billing information | ||
| 236 : | $dbst =& new ps_DB; | ||
| 237 : | $qt = "SELECT * FROM #__{sc}_user_info WHERE user_info_id='".$d["ship_to_info_id"]."' AND address_type='ST'"; | ||
| 238 : | $dbst->query($qt); | ||
| 239 : | $dbst->next_record(); | ||
| 240 : | } | ||
| 241 : | else { | ||
| 242 : | $dbst = $dbbt; | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | if(SKJ_TEST_REQUEST == 'TRUE') { | ||
| 246 : | $host = "developer.skipjackic.com"; | ||
| 247 : | } | ||
| 248 : | else { | ||
| 249 : | $host = "www.skipjackic.com"; | ||
| 250 : | } | ||
| 251 : | $port = 443; | ||
| 252 : | $path = "/scripts/evolvcc.dll?AuthorizeAPI"; | ||
| 253 : | // echo "Host path : ".$host.$path."\n"; | ||
| 254 : | |||
| 255 : | //Skipjack vars to send | ||
| 256 : | $bill_full_name = $dbbt->f("first_name") . " " . $dbbt->f("last_name"); | ||
| 257 : | $ship_full_name = $dbst->f("first_name") . " " . $dbst->f("last_name"); | ||
| 258 : | if (!$dbbt->f("phone_1")) { | ||
| 259 : | $phone = '123-456-7890'; | ||
| 260 : | } | ||
| 261 : | else { | ||
| 262 : | $phone = $dbbt->f("phone_1"); | ||
| 263 : | } | ||
| 264 : | $formdata = array ( | ||
| 265 : | |||
| 266 : | // SkipJack required fields | ||
| 267 : | 'sjname' => substr($bill_full_name, 0, 50), | ||
| 268 : | 'Email' => $dbbt->f("email"), | ||
| 269 : | 'Streetaddress' => substr($dbbt->f("address_1"), 0, 40), | ||
| 270 : | 'City' => substr($dbbt->f("city"), 0, 40), | ||
| 271 : | 'State' => substr($dbbt->f("state"), 0, 40), | ||
| 272 : | 'Zipcode' => substr($dbbt->f("zip"), 0, 9), | ||
| 273 : | 'Ordernumber' => $order_number, | ||
| 274 : | 'Accountnumber' => $_SESSION['ccdata']['order_payment_number'], | ||
| 275 : | 'Month' => ($_SESSION['ccdata']['order_payment_expire_month']), | ||
| 276 : | 'Year' => ($_SESSION['ccdata']['order_payment_expire_year']), | ||
| 277 : | 'Serialnumber' => SKJ_SERIAL, | ||
| 278 : | 'Transactionamount' => $order_total, | ||
| 279 : | //FIXME - Needs order details to be compliant | ||
| 280 : | 'Orderstring' => "1~1~0.00~1~N~||", | ||
| 281 : | 'Shiptophone' => $phone, | ||
| 282 : | |||
| 283 : | // Customer Shipping Address | ||
| 284 : | 'Shiptoname' => substr($ship_full_name, 0, 50), | ||
| 285 : | 'Shiptostreetaddress' => substr($dbst->f("address_1"), 0, 40), | ||
| 286 : | 'Shiptocity' => substr($dbst->f("city"), 0, 40), | ||
| 287 : | 'Shiptostate' => substr($dbst->f("state"), 0, 40), | ||
| 288 : | 'Shiptozipcode' => substr($dbst->f("zip"), 0, 20), | ||
| 289 : | 'Shiptocountry' => substr($dbst->f("country"), 0, 60), | ||
| 290 : | |||
| 291 : | // Additional Customer Data | ||
| 292 : | 'Country' => substr($dbbt->f("country"), 0, 40), | ||
| 293 : | |||
| 294 : | 'cvv2' => $_SESSION['ccdata']['credit_card_code'] | ||
| 295 : | |||
| 296 : | ); | ||
| 297 : | |||
| 298 : | //build the post string | ||
| 299 : | $poststring = ''; | ||
| 300 : | foreach($formdata AS $key => $val){ | ||
| 301 : | $poststring .= urlencode($key) . "=" . urlencode($val) . "&"; | ||
| 302 : | } | ||
| 303 : | // echo "Poststring: ".$poststring."\n"; | ||
| 304 : | // strip off trailing ampersand | ||
| 305 : | $poststring = substr($poststring, 0, -1); | ||
| 306 : | |||
| 307 : | if( function_exists( "curl_init" )) { | ||
| 308 : | |||
| 309 : | $CR = curl_init(); | ||
| 310 : | curl_setopt($CR, CURLOPT_URL, "https://".$host.$path); | ||
| 311 : | curl_setopt($CR, CURLOPT_POST, 1); | ||
| 312 : | curl_setopt($CR, CURLOPT_FAILONERROR, true); | ||
| 313 : | curl_setopt($CR, CURLOPT_POSTFIELDS, $poststring); | ||
| 314 : | curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); | ||
| 315 : | |||
| 316 : | // No PEER certificate validation...as we don't have | ||
| 317 : | // a certificate file for it to authenticate the host www.ups.com against! | ||
| 318 : | curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0); | ||
| 319 : | //curl_setopt($CR, CURLOPT_SSLCERT , "/usr/locale/xxxx/clientcertificate.pem"); | ||
| 320 : | |||
| 321 : | $result = curl_exec( $CR ); | ||
| 322 : | |||
| 323 : | $error = curl_error( $CR ); | ||
| 324 : | if( !empty( $error )) { | ||
| 325 : | $vmLogger->err( "curl error: ".curl_error( $CR ) ); | ||
| 326 : | $html = "<br/><span class=\"message\">".$VM_LANG->_PHPSHOP_PAYMENT_INTERNAL_ERROR." Skipjack.com</span>"; | ||
| 327 : | return false; | ||
| 328 : | } | ||
| 329 : | else { | ||
| 330 : | // echo "result: " . $result; | ||
| 331 : | } | ||
| 332 : | curl_close( $CR ); | ||
| 333 : | } | ||
| 334 : | else { | ||
| 335 : | |||
| 336 : | $fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 60); | ||
| 337 : | if(!$fp){ | ||
| 338 : | //error tell us | ||
| 339 : | $vmLogger->err( "$errstr ($errno)" ); | ||
| 340 : | } | ||
| 341 : | else { | ||
| 342 : | |||
| 343 : | //send the server request | ||
| 344 : | fputs($fp, "POST $path HTTP/1.1\r\n"); | ||
| 345 : | fputs($fp, "Host: $host\r\n"); | ||
| 346 : | fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); | ||
| 347 : | fputs($fp, "Content-length: ".strlen($poststring)."\r\n"); | ||
| 348 : | fputs($fp, "Connection: close\r\n\r\n"); | ||
| 349 : | fputs($fp, $poststring . "\r\n\r\n"); | ||
| 350 : | |||
| 351 : | //Get the response header from the server | ||
| 352 : | $str = ''; | ||
| 353 : | while(!feof($fp) && !stristr($str, 'content-length')) { | ||
| 354 : | $str = fgets($fp, 4096); | ||
| 355 : | } | ||
| 356 : | // If didnt get content-lenght, something is wrong, return false. | ||
| 357 : | if (!stristr($str, 'content-length')) { | ||
| 358 : | return false; | ||
| 359 : | |||
| 360 : | } | ||
| 361 : | $data = ""; | ||
| 362 : | while (!feof($fp)) { | ||
| 363 : | $data .= fgets ($fp, 1024); | ||
| 364 : | } | ||
| 365 : | $result = trim( $data ); | ||
| 366 : | /* | ||
| 367 : | // Get length of data to be received. | ||
| 368 : | $length = trim(substr($str,strpos($str,'content-length') + 15)); | ||
| 369 : | // Get buffer (blank data before real data) | ||
| 370 : | fgets($fp, 4096); | ||
| 371 : | // Get real data | ||
| 372 : | $data = fgets($fp, $length); | ||
| 373 : | fclose($fp);*/ | ||
| 374 : | |||
| 375 : | } | ||
| 376 : | } | ||
| 377 : | $result_lines = explode("\n", $result); | ||
| 378 : | // echo "Line 2: " . $result_lines[1] . "\n"; | ||
| 379 : | $response = explode("\",\"", $result_lines[1]); | ||
| 380 : | |||
| 381 : | // Approved - Success! | ||
| 382 : | if ($response[8] == '1') { | ||
| 383 : | $d["order_payment_log"] = $VM_LANG->_PHPSHOP_PAYMENT_TRANSACTION_SUCCESS.": "; | ||
| 384 : | // $d["order_payment_log"] .= $response[3]; | ||
| 385 : | // Catch Transaction ID | ||
| 386 : | $d["order_payment_trans_id"] = $response[8]; | ||
| 387 : | |||
| 388 : | return True; | ||
| 389 : | } | ||
| 390 : | // Payment Declined | ||
| 391 : | elseif ($response[8] == '0') { | ||
| 392 : | $vmLogger->err( $response[3] ); | ||
| 393 : | $d["order_payment_log"] = $response[3]; | ||
| 394 : | // Catch Transaction ID | ||
| 395 : | $d["order_payment_trans_id"] = $response[8]; | ||
| 396 : | return False; | ||
| 397 : | } | ||
| 398 : | // Transaction Error | ||
| 399 : | elseif ($response[0] == '0') { | ||
| 400 : | $vmLogger->err( $response[3] ); | ||
| 401 : | $d["order_payment_log"] = $response[3]; | ||
| 402 : | // Catch Transaction ID | ||
| 403 : | $d["order_payment_trans_id"] = $response[8]; | ||
| 404 : | return False; | ||
| 405 : | } | ||
| 406 : | } | ||
| 407 : | |||
| 408 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

