Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Payment / SkipJack.php
blobe48699dc5aedc132b4422f483a8bec57f86a3914
1 <?php
2 /** @package verysimple::Payment */
4 /**
5 * import supporting libraries
6 */
7 require_once("PaymentProcessor.php");
9 /**
10 * SkipJack extends the generic PaymentProcessor object to process
11 * a PaymentRequest through the SkipJack payment gateway.
13 * @package verysimple::Payment
14 * @author VerySimple Inc.
15 * @copyright 1997-2012 VerySimple, Inc.
16 * @license http://www.gnu.org/licenses/lgpl.html LGPL
17 * @version 2.1
19 class SkipJack extends PaymentProcessor
21 private $liveUrl = "https://www.skipjackic.com/scripts/evolvcc.dll?AuthorizeApi";
22 private $testUrl = "https://developer.skipjackic.com/scripts/evolvcc.dll?AuthorizeAPI";
23 private $url = "";
25 /**
26 * Called on contruction
28 * @param bool $test
29 * set to true to enable test mode. default = false
31 function Init($testmode)
33 // set the post url depending on whether we're in test mode or not
34 $this->url = $testmode ? $this->testUrl : $this->liveUrl;
37 /**
39 * @see PaymentProcessor::Refund()
41 function Refund(RefundRequest $req)
43 throw new Exception("Refund not implemented for this gateway");
46 /**
47 * Process a PaymentRequest
49 * @param PaymentRequest $req
50 * Request object to be processed
51 * @return PaymentResponse
53 function Process(PaymentRequest $req)
55 if ($this->_testMode) {
56 if ($req->SerialNumber == "" || $req->DeveloperSerialNumber == "") {
57 throw new Exception("SkipJack requires a SerialNumber and DeveloperSerialNumber for test transactions. Free developer accounts can be obtained through SkipJack.com");
59 } else {
60 if ($req->SerialNumber == "") {
61 throw new Exception("SkipJack requires a SerialNumber for live transactions");
65 // skipjack requires a funky formatted order string
66 if (! $req->OrderString) {
67 $req->OrderString = "1~None~0.00~0~N~||";
70 $resp = new PaymentResponse();
71 $resp->OrderNumber = $req->OrderNumber;
73 // post to skipjack service
74 $resp->RawResponse = $this->CurlPost($this->url, $this->GetPostData($req));
76 // response is two lines - first line is field name, 2nd line is values
77 $lines = explode("\r\n", $resp->RawResponse);
79 // strip off the beginning and ending doublequote
80 $lines [0] = substr($lines [0], 1, strlen($lines [0]) - 2);
81 $lines [1] = substr($lines [1], 1, strlen($lines [1]) - 2);
83 // split the fields and values
84 $fields = explode("\",\"", $lines [0]);
85 $vals = explode("\",\"", $lines [1]);
87 // convert these two lines into a hash so we can get individual values
88 for ($i = 0; $i < count($fields); $i ++) {
89 $resp->ParsedResponse [$fields [$i]] = $vals [$i];
92 // convert these codes into a generic response object
93 $resp->ResponseCode = $resp->ParsedResponse ["szReturnCode"];
94 $resp->TransactionId = $resp->ParsedResponse ["AUTHCODE"];
96 // figure out if the transaction was a total success or not
97 $verifyOK = $resp->ParsedResponse ["szReturnCode"] == "1";
98 $approvedOK = $resp->ParsedResponse ["szIsApproved"] == "1";
99 $authOK = $resp->ParsedResponse ["AUTHCODE"] != "EMPTY" && $resp->ParsedResponse ["AUTHCODE"] != "" && $resp->ParsedResponse ["szAuthorizationResponseCode"] != "";
100 $resp->IsSuccess = ($verifyOK && $approvedOK && $authOK);
102 // dependin on the status, get the best description we can
103 if ($resp->IsSuccess) {
104 $resp->ResponseMessage = $this->GetMessage($resp->ParsedResponse ["szReturnCode"]);
105 } else if (! $verifyOK) {
106 // verification failed
107 $resp->ResponseMessage = $this->GetMessage($resp->ParsedResponse ["szReturnCode"]);
108 } else if (! $authOK) {
109 // verification was ok, but the processor didn't process the transaction
110 $resp->ResponseMessage = $resp->ParsedResponse ["szAuthorizationDeclinedMessage"];
111 } else {
112 // we don't know why it so just display all the possible error messages
113 $resp->ResponseMessage = $resp->ParsedResponse ["szAuthorizationDeclinedMessage"] . " " . $resp->ParsedResponse ["szAVSResponseMessage"] . " " . $resp->ParsedResponse ["szCVV2ResponseMessage"];
116 return $resp;
118 private function GetPostData($req)
120 $data = array ();
121 $data ["orderstring"] = $req->OrderString;
122 $data ["serialnumber"] = $req->SerialNumber;
123 $data ["developerserialnumber"] = $req->DeveloperSerialNumber;
124 $data ["sjname"] = $req->CustomerName;
125 $data ["streetaddress"] = $req->CustomerStreetAddress;
126 $data ["city"] = $req->CustomerCity;
127 $data ["state"] = $req->CustomerState;
128 $data ["zipcode"] = $req->CustomerZipCode;
129 $data ["shiptophone"] = $req->CustomerPhone;
130 $data ["email"] = $req->CustomerEmail;
131 $data ["ordernumber"] = "CC" . substr(md5(time()), 0, 20);
132 $data ["transactionamount"] = number_format($req->TransactionAmount, 2, ".", "");
133 $data ["accountnumber"] = str_replace(array (
134 "-",
136 ), array (
139 ), $req->CCNumber);
140 $data ["month"] = $req->CCExpMonth;
141 $data ["year"] = $req->CCExpYear;
142 $data ["cvv2"] = $req->CCSecurityCode;
143 $data ["country"] = $req->CustomerCountry;
144 $data ["comment"] = $req->Comment;
145 return $data;
149 * Returns a text description based on the return code
151 * @param string $code
152 * the skipjack response code
153 * @return string
155 private function GetMessage($code)
157 $errors = array ();
158 $errors ["-1"] = "Error in request Data was not by received intact by Skipjack Transaction Network.";
159 $errors ["0"] = "Communication Failure Error in Request and Response at IP level. Use Get Transaction Status before retrying transaction.";
160 $errors ["1"] = "Success";
161 $errors ["-35"] = "Credit card number does not comply with the Mod10 check. Retry with correct credit card number.";
162 $errors ["-37"] = "Skipjack is unable to communicate with payment Processor. Please Retry.";
163 $errors ["-39"] = "Check HTML Serial Number length and that it is a correct/valid number. Confirm you are sending to the correct environment (Development or Production)";
164 $errors ["-51"] = "Length or value of zip code The value or length for billing zip code is incorrect.";
165 $errors ["-52"] = "The value or length for shipping zip code is incorrect.";
166 $errors ["-53"] = "The value or length for credit card expiration month is incorrect.";
167 $errors ["-54"] = "The value or length of the month or year of the credit card account number was incorrect.";
168 $errors ["-55"] = "The value or length or billing street address is incorrect.";
169 $errors ["-56"] = "The value or length of the shipping address is incorrect.";
170 $errors ["-57"] = "The length of the transaction amount must be at least 3 digits long (excluding the decimal place).";
171 $errors ["-58"] = "Merchant Name associated with Skipjack account is misconfigured or invalid";
172 $errors ["-59"] = "Merchant Address associated with Skipjack account is misconfigured or invalid Skipjack Financial Services Skipjack Integration GuidePage 52 of 251";
173 $errors ["-60"] = "Merchant State associated with Skipjack account is misconfigured or invalid";
174 $errors ["-61"] = "The value or length for shipping state/province is empty.";
175 $errors ["-62"] = "The value for length orderstring is empty.";
176 $errors ["-64"] = "The value for the phone number is incorrect.";
177 $errors ["-65"] = "Error empty sjname The value or length for billing name is empty.";
178 $errors ["-66"] = "The value or length for billing e-mail is empty.";
179 $errors ["-67"] = "The value or length for billing street address is empty.";
180 $errors ["-68"] = "The value or length for billing city is empty.";
181 $errors ["-69"] = "The value or length for billing state is empty.";
182 $errors ["-70"] = "Zip Code field is empty.";
183 $errors ["-71"] = "Ordernumber field is empty.";
184 $errors ["-72"] = "Account number field is empty";
185 $errors ["-73"] = "Month field is empty.";
186 $errors ["-74"] = "Year field is empty.";
187 $errors ["-75"] = "Serial number field is empty.";
188 $errors ["-76"] = "Transaction amount field is empty.";
189 $errors ["-77"] = "Orderstring field is empty.";
190 $errors ["-78"] = "Shiptophone field is empty.";
191 $errors ["-79"] = "Length or value sjname The value or length for billing name is empty.";
192 $errors ["-80"] = "Error in the length or value of shiptophone.";
193 $errors ["-81"] = "Length or value of Customer location";
194 $errors ["-82"] = "The value or length for billing state is empty.";
195 $errors ["-83"] = "The value or length for shipping phone is empty.";
196 $errors ["-84"] = "There is already an existing pending transaction in the register sharing the posted Order Number.";
197 $errors ["-85"] = "Airline leg field value is invalid or empty.";
198 $errors ["-86"] = "Airline ticket info field is invalid or empty";
199 $errors ["-87"] = "Point of Sale check routing number is invalid or empty.";
200 $errors ["-88"] = "Point of Sale check account number is invalid or empty.";
201 $errors ["-89"] = "Point of Sale check MICR invalid or empty.";
202 $errors ["-90"] = "Point of Sale check number missingor invalid Point of Sale check number invalid or empty.";
203 $errors ["-91"] = "\"Make CVV a required field feature\" enabled in the Merchant Account Setup interface but no CVV code was sent in the transaction data.";
204 $errors ["-92"] = "Approval Code Invalid. Approval Code is a 6 digit code.";
205 $errors ["-93"] = "Blind Credits Request Refused \"Allow Blind Credits\" option must be enabled on the Skipjack Merchant Account.";
206 $errors ["-94"] = "BlindCreditsFailed Skipjack Financial Services Skipjack Integration GuidePage 53 of 251";
207 $errors ["-95"] = "Voice Authorization Request Refused Voice Authorization option must be enabled on the Skipjack";
208 $errors ["-96"] = "Voice Authorizations Failed";
209 $errors ["-97"] = "Fraud Rejection Violates Velocity Settling.";
210 $errors ["-98"] = "Invalid Discount Amount";
211 $errors ["-99"] = "POS PIN Debit Pin BlockDebit-specific";
212 $errors ["-100"] = "POS PIN Debit Invalid Key Serial Number Debit-specific";
213 $errors ["-101"] = "Data for Verified by Visa/MC Secure Code is invalid.";
214 $errors ["-102"] = "Authentication Data Not Allowed";
215 $errors ["-103"] = "POS checkdateofbirth variable contains a birth date in an incorrect format. Use MM/DD/YYYY format for this variable.";
216 $errors ["-104"] = "POS checkidentificationtype variable contains a identificationtype value which is invalid. Use the single digit value where Social Security Number=1, Drivers License=2 for this variable.";
217 $errors ["-105"] = "Track Data is in invalid format.";
218 $errors ["-106"] = "POS Check Invalid Account Type";
219 $errors ["-107"] = "POS PIN Debit Invalid Sequence Number";
220 $errors ["-108"] = "Invalid Transaction ID";
221 $errors ["-109"] = "Invalid From Account Type";
222 $errors ["-110"] = "Pos Error Invalid To Account Type";
223 $errors ["-112"] = "Pos Error Invalid Auth Option";
224 $errors ["-113"] = "Pos Error Transaction Failed";
225 $errors ["-114"] = "Pos Error Invalid Incoming Eci";
226 $errors ["-115"] = "POS Check Invalid Check Type";
227 $errors ["-116"] = "POS Check lane or cash register number is invalid. Use a valid lane or cash register number that has been configured in the Skipjack Merchant Account.";
228 $errors ["-117"] = "POS Check Invalid Cashier Number";
230 return (isset($errors [$code])) ? $errors [$code] : "Unknown Error";