command="sale"; $this->result="Error"; $this->resultcode="E"; $this->error="Transaction not processed yet."; $this->timeout=45; $this->cardpresent=false; if(isset($_SERVER['REMOTE_ADDR'])) $this->ip=$_SERVER['REMOTE_ADDR']; $this->software="USAePay PHP API v" . USAEPAY_VERSION; } /** * Verify that all required data has been set * * @return string */ function CheckData() { if(!$this->key) return "Source Key is required"; if(strtolower($this->command)=="capture" || strtolower($this->command)=="creditvoid") { if(!$this->refnum) return "Reference Number is required"; } else { if($this->command=="check" || $this->command=="checkcredit") { if(!$this->account) return "Account Number is required"; if(!$this->routing) return "Routing Number is required"; } else { if(!$this->magstripe) { if(!$this->card) return "Credit Card Number is required"; if(!$this->exp) return "Expiration Date is required"; } } $this->amount=ereg_replace("[^[:digit:].]","",$this->amount); if(!$this->amount) return "Amount is required"; if(!$this->invoice && !$this->orderid) return "Invoice number or Order ID is required"; if(!$this->magstripe) { //if(!$this->cardholder) return "Cardholder Name is required"; //if(!$this->street) return "Street Address is required"; //if(!$this->zip) return "Zipcode is required"; } } return 0; } /** * Send transaction to the USAePay Gateway and parse response * * @return boolean */ function Process() { // check that we have the needed data $tmp=$this->CheckData(); if($tmp) { $this->result="Error"; $this->resultcode="E"; $this->error=$tmp; $this->errorcode=10129; return false; } // check to make sure we have curl if(!function_exists("curl_version")) { $this->result="Error"; $this->resultcode="E"; $this->error="Libary Error: CURL support not found"; $this->errorcode=10130; return false; } //init the connection $ch = curl_init(($this->gatewayurl?$this->gatewayurl:"https://www.usaepay.com/secure/gate.php")); if(!is_resource($ch)) { $this->result="Error"; $this->resultcode="E"; $this->error="Libary Error: Unable to initialize CURL ($ch)"; $this->errorcode=10131; return false; } // set some options for the connection curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_TIMEOUT, ($this->timeout>0?$this->timeout:45)); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // Bypass ssl errors - A VERY BAD IDEA if($this->ignoresslcerterrors) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } // apply custom ca bundle location if($this->cabundle) { curl_setopt($ch, CURLOPT_CAINFO, $this->cabundle); } // set proxy if($this->proxyurl) { curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curl_setopt ($ch, CURLOPT_PROXY, $this->proxyurl); } // format the data $data = "UMkey=" . rawurlencode($this->key) . "&" . "UMcommand=" . rawurlencode($this->command) . "&" . "UMauthCode=" . rawurlencode($this->origauthcode) . "&" . "UMcard=" . rawurlencode($this->card) . "&" . "UMexpir=" . rawurlencode($this->exp) . "&" . "UMbillamount=" . rawurlencode($this->billamount) . "&" . "UMamount=" . rawurlencode($this->amount) . "&" . "UMinvoice=" . rawurlencode($this->invoice) . "&" . "UMorderid=" . rawurlencode($this->orderid) . "&" . "UMponum=" . rawurlencode($this->ponum) . "&" . "UMtax=" . rawurlencode($this->tax) . "&" . "UMtip=" . rawurlencode($this->tip) . "&" . "UMshipping=" . rawurlencode($this->shipping) . "&" . "UMdiscount=" . rawurlencode($this->discount) . "&" . "UMsubtotal=" . rawurlencode($this->subtotal) . "&" . "UMcurrency=" . rawurlencode($this->currency) . "&" . "UMname=" . rawurlencode($this->cardholder) . "&" . "UMstreet=" . rawurlencode($this->street) . "&" . "UMzip=" . rawurlencode($this->zip) . "&" . "UMdescription=" . rawurlencode($this->description) . "&" . "UMcvv2=" . rawurlencode($this->cvv2) . "&" . "UMip=" . rawurlencode($this->ip) . "&" . "UMtestmode=" . rawurlencode($this->testmode) . "&" . "UMcustemail=" . rawurlencode($this->custemail) . "&" . "UMcustreceipt=" . rawurlencode($this->custreceipt) . "&" . "UMrouting=" . rawurlencode($this->routing) . "&" . "UMaccount=" . rawurlencode($this->account) . "&" . "UMssn=" . rawurlencode($this->ssn) . "&" . "UMdlstate=" . rawurlencode($this->dlstate) . "&" . "UMdlnum=" . rawurlencode($this->dlnum) . "&" . "UMchecknum=" . rawurlencode($this->checknum) . "&" . "UMrecurring=" . rawurlencode($this->recurring) . "&" . "UMbillamount=" . rawurlencode($this->billamount) . "&" . "UMbilltax=" . rawurlencode($this->billtax) . "&" . "UMschedule=" . rawurlencode($this->schedule) . "&" . "UMnumleft=" . rawurlencode($this->numleft) . "&" . "UMstart=" . rawurlencode($this->start) . "&" . "UMexpire=" . rawurlencode($this->end) . "&" . ($this->billsourcekey?"UMbillsourcekey=yes&":"") . "UMbillfname=" . rawurlencode($this->billfname) . "&" . "UMbilllname=" . rawurlencode($this->billlname) . "&" . "UMbillcompany=" . rawurlencode($this->billcompany) . "&" . "UMbillstreet=" . rawurlencode($this->billstreet) . "&" . "UMbillstreet2=" . rawurlencode($this->billstreet2) . "&" . "UMbillcity=" . rawurlencode($this->billcity) . "&" . "UMbillstate=" . rawurlencode($this->billstate) . "&" . "UMbillzip=" . rawurlencode($this->billzip) . "&" . "UMbillcountry=" . rawurlencode($this->billcountry) . "&" . "UMbillphone=" . rawurlencode($this->billphone) . "&" . "UMemail=" . rawurlencode($this->email) . "&" . "UMfax=" . rawurlencode($this->fax) . "&" . "UMwebsite=" . rawurlencode($this->website) . "&" . "UMshipfname=" . rawurlencode($this->shipfname) . "&" . "UMshiplname=" . rawurlencode($this->shiplname) . "&" . "UMshipcompany=" . rawurlencode($this->shipcompany) . "&" . "UMshipstreet=" . rawurlencode($this->shipstreet) . "&" . "UMshipstreet2=" . rawurlencode($this->shipstreet2) . "&" . "UMshipcity=" . rawurlencode($this->shipcity) . "&" . "UMshipstate=" . rawurlencode($this->shipstate) . "&" . "UMshipzip=" . rawurlencode($this->shipzip) . "&" . "UMshipcountry=" . rawurlencode($this->shipcountry) . "&" . "UMshipphone=" . rawurlencode($this->shipphone) . "&" . "UMcardauth=" . rawurlencode($this->cardauth) . "&" . "UMpares=" . rawurlencode($this->pares) . "&" . "UMxid=" . rawurlencode($this->xid) . "&" . "UMcavv=" . rawurlencode($this->cavv) . "&" . "UMeci=" . rawurlencode($this->eci) . "&" . "UMcustid=" . rawurlencode($this->custid) . "&" . "UMcardpresent=" . ($this->cardpresent?"1":"0") . "&" . "UMmagstripe=" . rawurlencode($this->magstripe) . "&" . "UMtermtype=" . rawurlencode($this->termtype) . "&" . "UMmagsupport=" . rawurlencode($this->magsupport) . "&" . "UMcontactless=" . rawurlencode($this->contactless) . "&" . "UMsoftware=" . rawurlencode($this->software) . "&" . "UMignoreDuplicate=" . rawurlencode($this->ignoreduplicate) . "&" . "UMrefNum=" . rawurlencode($this->refnum); // Append md5hash if pin has been set. if($this->pin) { $key=mktime(); $data.="&UMmd5hash=" . rawurlencode(md5($this->command . ":" . $this->pin . ":" . $this->amount . ":" . $this->invoice . ":" . $key)) . "&UMmd5key=" . $key; } //echo $data; // attach the data curl_setopt($ch,CURLOPT_POSTFIELDS,$data); // run the transfer $result=curl_exec ($ch); //get the result and parse it for the response line. if(!strlen($result)) { $this->result="Error"; $this->resultcode="E"; $this->error="Error reading from card processing gateway."; $this->errorcode=10132; $this->blank=1; $this->curlerror=curl_error($ch); curl_close ($ch); return false; } curl_close ($ch); $this->rawresult=$result; if(!$result) { $this->result="Error"; $this->resultcode="E"; $this->error="Blank response from card processing gateway."; $this->errorcode=10132; return false; } // result will be on the last line of the return $tmp=split("\n",$result); $result=$tmp[count($tmp)-1]; // result is in urlencoded format, parse into an array parse_str($result,$tmp); // check to make sure we received the correct fields if(!isset($tmp["UMversion"]) || !isset($tmp["UMstatus"])) { $this->result="Error"; $this->resultcode="E"; $this->error="Error parsing data from card processing gateway."; $this->errorcode=10132; return false; } // Store results $this->result=(isset($tmp["UMstatus"])?$tmp["UMstatus"]:"Error"); $this->resultcode=(isset($tmp["UMresult"])?$tmp["UMresult"]:"E"); $this->authcode=(isset($tmp["UMauthCode"])?$tmp["UMauthCode"]:""); $this->refnum=(isset($tmp["UMrefNum"])?$tmp["UMrefNum"]:""); $this->batch=(isset($tmp["UMbatch"])?$tmp["UMbatch"]:""); $this->avs_result=(isset($tmp["UMavsResult"])?$tmp["UMavsResult"]:""); $this->avs_result_code=(isset($tmp["UMavsResultCode"])?$tmp["UMavsResultCode"]:""); $this->cvv2_result=(isset($tmp["UMcvv2Result"])?$tmp["UMcvv2Result"]:""); $this->cvv2_result_code=(isset($tmp["UMcvv2ResultCode"])?$tmp["UMcvv2ResultCode"]:""); $this->vpas_result_code=(isset($tmp["UMvpasResultCode"])?$tmp["UMvpasResultCode"]:""); $this->convertedamount=(isset($tmp["UMconvertedAmount"])?$tmp["UMconvertedAmount"]:""); $this->convertedamountcurrency=(isset($tmp["UMconvertedAmountCurrency"])?$tmp["UMconvertedAmountCurrency"]:""); $this->conversionrate=(isset($tmp["UMconversionRate"])?$tmp["UMconversionRate"]:""); $this->error=(isset($tmp["UMerror"])?$tmp["UMerror"]:""); $this->errorcode=(isset($tmp["UMerrorcode"])?$tmp["UMerrorcode"]:"10132"); $this->custnum=(isset($tmp["UMcustnum"])?$tmp["UMcustnum"]:""); // Obsolete variable (for backward compatibility) At some point they will no longer be set. $this->avs=(isset($tmp["UMavsResult"])?$tmp["UMavsResult"]:""); $this->cvv2=(isset($tmp["UMcvv2Result"])?$tmp["UMcvv2Result"]:""); if(isset($tmp["UMcctransid"])) $this->cctransid=$tmp["UMcctransid"]; if(isset($tmp["UMacsurl"])) $this->acsurl=$tmp["UMacsurl"]; if(isset($tmp["UMpayload"])) $this->pareq=$tmp["UMpayload"]; if($this->resultcode == "A") return true; return false; } /** * Verify Proper Installation of USAePay class and required PHP Support * */ function Test() { $curl_version=false; ?>
TestResult
Checking PHP Version Ok
PHP version on detected. Warning
PHP version detected. It is recommended that you upgrade to the most recent release of PHP.
Checking CURL Extension Ok
Curl Extension () detected. Error
Your PHP installation does not include the Curl Extension. You must either enable the curl extension in your php.ini file by removing the semi-colon from the line ";extension=php_curl.dll" or recompile php with the configuration flag: "--with-curl"
Checking CURL SSL Support Ok
SSL Version () detected. Error
It appears that your curl installation does not include support for the HTTPS (ssl) protocal Proper SSL installation is required to communicate with the USAePay gateway securely. Please recompile curl with SSL support.
Checking Communication with the Gateway Error
No curl support gatewayurl?$this->gatewayurl:"https://www.usaepay.com/secure/gate.php") . "?VersionCheck=1&UMsoftware=" . rawurlencode($this->software)); if(!$ch) { ?>Error
Curl failed to connect to server: (NULL $ch returned) cabundle) curl_setopt($ch, CURLOPT_CAINFO, $this->cabundle); $result=curl_exec($ch); parse_str($result, $return); if($return["UMversion"]) { $ssl_failed=false; ?>Ok
Successfully connected to the gateway. Detected version () of the USAePay gateway API. gatewayurl?$this->gatewayurl:"https://www.usaepay.com/secure/gate.php") . "?VersionCheck=1&UMsoftware=" . rawurlencode($this->software)); if($this->cabundle) curl_setopt($ch, CURLOPT_CAINFO, $this->cabundle); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result=curl_exec($ch); parse_str($result, $return); if($return["UMversion"]) { ?>Warning
Successfully connected to the gateway but could not verify SSL certificate. This usually indicates that you do not have curl set up with the proper root CA certificate. It is recommended that you install an up to date root ca bundle. As a temporary work around you may disable the ssl cert check by adding the following to your script:

$tran->ignoresslcerterrors=true;

cabundle) curl_setopt($ch, CURLOPT_CAINFO, $this->cabundle); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($ch); if(strlen($result)) { ?> SSL certificate for VeriSign was validated sucessfully. This would indicate that you have a root CA bundle installed but that it is outdated. See below. Unable to verify SSL certificate for VeriSign. This would indicate that you do not have a root CA bundle installed. See below. software)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result=curl_exec($ch); parse_str($result, $return); if($return["UMversion"]) { ?>Warning
Successfully connected to the gateway using a static IP but could not connect using hostname. This would indicate that you do not have DNS setup correctly. Please correct your server configuration to include a valid DNS server. As a temporary work around you may add the following to your script:

$tran->ignoresslcerterrors=true;
$tran->gatewayurl="https://216.133.244.70/gate.php";

Failed
Unable to establish connection to the USAePay Gateway. It is possible that you are firewalling outbound traffic from your server. To correct this problem, you must add an allow entry in your firewall for ip on port 443;
Looking for root CA Bundle Ok
A root CA bundle was found in "". Since the above test failed, its possible that curl is not correctly configured to use this bundle. You can correct the problem by add the following code to your script:

$tran->cabundle='';

It is also possible that your root CA bundle is out dated. Your root CA bundle was last updated . You can download a new file from: https://www.usaepay.com/topics/curl-ca-bundle.crt Error
Unable to locate your root CA bundle file. You can correct this by downloading a bundle file from: https://www.usaepay.com/topics/curl-ca-bundle.crt Once downloaded save this file to: You may also need to add the following code:

$tran->cabundle='';

= 0; $i--) { if($y==1) $y=2; else $y=1; //multiply every other digit by 2 $tmp=substr($ccnum,$i,1)*$y; if($tmp >9) $tmp=substr($tmp,0,1) + substr($tmp,1,1); $total+=$tmp; } if($total%10) {$umErrStr="Cardnumber fails Luhn Mod-10 check digit"; return 0;} switch(substr($ccnum,0,1)) { case 2: //enRoute - First four digits must be 2014 or 2149. Only valid length is 15 digits if((substr($ccnum,0,4) == "2014" || substr($ccnum,0,4) == "2149") && strlen($ccnum) == 15) return 20; break; case 3: //JCB - Um yuck, read the if statement below, and oh by the way 300 through 309 overlaps with diners club. bummer. if((substr($ccnum,0,4) == "3088" || substr($ccnum,0,4) == "3096" || substr($ccnum,0,4) == "3112" || substr($ccnum,0,4) == "3158" || substr($ccnum,0,4) == "3337" || (substr($ccnum,0,8) >= "35280000" ||substr($ccnum,0,8) <= "358999999")) && strlen($ccnum)==16) { return 28; } else { switch(substr($ccnum,1,1)) { case 4: case 7: // American Express - First digit must be 3 and second digit 4 or 7. Only Valid length is 15 if(strlen($ccnum) == 15) return 3; break; case 0: case 6: case 8: //Diners Club/Carte Blanche - First digit must be 3 and second digit 0, 6 or 8. Only valid length is 14 if(strlen($ccnum) == 14) return 4; break; } } break; case 4: // Visa - First digit must be a 4 and length must be either 13 or 16 digits. if(strlen($ccnum) == 13 || strlen($ccnum) == 16) { return 2; } break; case 5: // Mastercard - First digit must be a 5 and second digit must be int the range 1 to 5 inclusive. Only valid length is 16 if((substr($ccnum,1,1) >=1 && substr($ccnum,1,1) <=5) && strlen($ccnum) == 16) { return 1; } break; case 6: // Discover - First four digits must be 6011. Only valid length is 16 digits. if(substr($ccnum,0,4) == "6011" && strlen($ccnum) == 16) return 10; } // couldn't match a card profile. time to call it quits and go home. this goose is cooked. $umErrStr="Cardnumber did not match any known creditcard profiles"; return 0; } ?>