This class allows you to submit Credit Card transactions to the merchant provider GoEmerchant.com. It requires Curl. There is a debug feature you can turn on that will allow you to test it as you code without needing to send a request to their server.
By : sleighboy
<?php /* Author: Daniel Anderson */ /* http://www.dattrix.com/ */ /* GoEMerchant.com Gateway PHP Class*/ /* Requires: CURL */
class GoEmerchant {
/* Specify your username and password */ var $merchant = "USERNAME"; var $password = "PASSWORD";
/* You can set this to 1, and it will not send the transaction. It will just return whatever you specify for debug_return */ var $debug = 0; var $debug_return = 0;
/* An array that stores the last data sent to the class */ var $recent_transaction = array("success"=>"","authcode"=>"","authresponse"=>"","avs_code"=>"","orderid_given"=>"","orderid_returned"=>"","total"=>"","cardname"=>"","cardnum1"=>"","cardnum2"=>"","cardnum3"=>"","cardnum4"=>"","cardexpm"=>"","cardexpy"=>"","cvv2"=>"","nameoncard"=>"","cardstreet"=>"","cardcity"=>"","cardstate"=>"","cardzip"=>"","cardcountry"=>"");
/* Will be 1 if Curl is available */ var $curl_available;
/* Array that will store errors */ var $error;
/* This function runs automatically upon object creation to determine if Curl is available*/ function GoEmerchant(){ if(extension_loaded("curl")) $this->curl_available = 1; else $this->curl_available = 0; }
/* This does the processing, the $orderid argument is your own order ID number, everything else should be pretty self-explanatory , default Country is US*/ function process_credit_card($orderid,$total,$cardnum1,$cardnum2,$cardnum3,$cardnum4,$cardexpm,$cardexpy,$cvv2,$nameoncard,$cardstreet,$cardcity,$cardstate,$cardzip,$cardcountry = "US"){
/* If you set debug to 1, it skips any real processing and just returns what you told it to return */ if($this->debug == 0){ /* Make sure all arguments are passed to function */ if($cardcountry != "US") $num_args = 15; else $num_args = 14;
if(func_num_args() == $num_args){ /*Auto-Correct Total Field*/ $total = str_replace("\$","",str_replace(",","",$total));
/* Run error checks based on card type */ switch($card_type){ case 'Amex': if(strlen($cvv2) != 4) $this->error[] = "American Express Requires Four-Digit CVV2 Code";
}else{ /* If debugging was toggled, then do as it was instructed to do */ if($this->debug_return == 0){ $this->recent_transaction["success"] = 0; $this->recent_transaction["authcode"] = ""; $this->recent_transaction["authresponse"] = "Developer Debugging Forces Decline"; $this->recent_transaction["avs_code"] = 0; $this->recent_transaction["orderid_returned"] = $orderid; return false; }else{ $this->recent_transaction["success"] = 1; $this->recent_transaction["authcode"] = "ASDFG12345"; $this->recent_transaction["authresponse"] = "Developer Debugging Forces Accept"; $this->recent_transaction["avs_code"] = 1; $this->recent_transaction["orderid_returned"] = $orderid; return true; } } }
}
?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.