class SurePayObject {
// define vars for internal use
var $reqheader;
var $request;
var $auth;
var $creditcard;
var $shipaddress;
var $lineitem;
var $data;
var $authstatus;
var $result;
var $message;
var $shortmessage;
// define vars spec to merchant
var $merchantid;
var $password;
// define vars specific to the order
var $orderid;
var $shippingcost;
var $ccn;
var $exp;
var $shipfname;
var $shiplname;
var $addr1;
var $addr2;
var $city;
var $state;
var $zipcode; // 5 only
var $phone;
var $email;
// var $sku;
// var $description;
// var $quantity;
// var $unitprice;
var $items;
// Constructor
function SurePayObject() {
$this->reqheader = "xml=";
}
// Define Methods
function MakeXMLRequest() {
$this->request = "merchantid . "\" password=\"" . $this->password . "\">";
$this->auth = "orderid . "\" shippingcost=\"" . $this->shippingcost . "USD\" >";
$this->creditcard = "ccn) . "\" expiration=\"" . $this->exp . "\">";
$this->shipaddress = "shipfname . "\" lastname=\"" . $this->shiplname . "\" address1=\"" . $this->addr1 . "\" address2=\"" . $this->addr2 . "\" city=\"" . $this->city . "\" state=\"" . $this->state . "\" zip=\"" . $this->zipcode . "\" country=\"US\" phone=\"" . $this->phone . "\" email=\"" . $this->email . "\"/>";
$itemcount = sizeof($this->items);
for ($i=0;$i<$itemcount;$i++) {
// echo "Adding Item $i
\n";
$this->lineitems .= "items[$i]['sku'] . "\" description=\"" . $this->items[$i]['description'] . "\" quantity=\"" . $this->items[$i]['quantity'] . "\" taxrate=\"0\" unitprice=\"" . $this->items[$i]['unitprice'] . "USD\"/>";
}
$this->data = $this->request . $this->auth . $this->creditcard . $this->billaddress . "" . $this->shipaddress . $this->lineitems . "";
return $this->data;
} // function MakeXMLRequest
function DoPriceAdjustment($NewAmount) {
$arequest = "merchantid . "\" password=\"" . $this->password . "\">";
$arequest .= "TransactionID . "\" amount=\"" . $NewAmount . "USD\" markfor=\"fulfilled\">";
$arequest .= "";
register_log("surepay", "adjusting/fulfilling transaction (ID ".$this->TransactionID."): new amt $NewAmount");
$this->PostXMLRequest($arequest);
if ( ! preg_match("/pp\.adjustresponse/i", $this->result) ||
preg_match("/failure=\"true\"/i", $this->result) ) {
register_log("surepay", "BAD RESULT (mail sent): " . $this->result);
@mail("regfailure@nameboy.com", "surepay failure (DoPriceAdjustment)", "In DoPriceAdjustment, for transactionid ".$this->TransactionID.", we got\nan error, like so:\n\n".$this->result);
}
}
function DoVoidAdjustment() {
$arequest = "merchantid . "\" password=\"" . $this->password . "\">";
$arequest .= "TransactionID . "\" markfor=\"void\">";
$arequest .= "";
register_log("surepay", "voiding transaction (ID ".$this->TransactionID.")");
$this->PostXMLRequest($arequest);
if ( ! preg_match("/pp\.adjustresponse/i", $this->result) ||
preg_match("/failure=\"true\"/i", $this->result) ) {
register_log("surepay", "BAD RESULT (mail sent): " . $this->result."\n");
@mail("regfailure@nameboy.com", "surepay failure (DoVoidAdjustment)", "In DoVoidAdjustment, for transactionid ".$this->TransactionID.", we got\nan error, like so:\n\n".$this->result);
}
}
function ProcessXMLRequest() {
$this->PostXMLRequest($this->data);
if (eregi("authstatus=\"AUTH\"", $this->result)) {
// echo "You are Authorized.";
$this->authstatus = TRUE;
$this->message = "You are Authorized.";
$this->shortmessage = "AUTHORIZED";
preg_match("/transactionid=\"([^\"]+)\"/", $this->result, $regs);
$this->TransactionID = $regs[1];
register_log("surepay", "AUTH received (ID ".$this->TransactionID.")");
}
else if (eregi("authstatus=\"DCL\"", $this->result)) {
// echo "Your card was Declined.";
$this->authstatus = FALSE;
$this->message = "Your card was Declined.";
$this->shortmessage = "DECLINED";
register_log("surepay", "DCL received (ID ".$this->TransactionID.")");
}
else if (eregi("authstatus=\"REF\"", $this->result)) {
// echo "We were unable to process your credit card. You may attempt to fill in another card, or call us for assistance.";
$this->authstatus = FALSE;
$this->message = "We were unable to process your credit card. You may attempt to fill in another card, or call us for assistance.";
$this->shortmessage = "FAILED";
register_log("surepay", "REF received (ID ".$this->TransactionID.")");
}
else if (eregi("biz.InvalidCCNumberException", $this->result) ) {
$this->authstatus = FALSE;
$this->message = "The credit card number you entered is not valid.";
$this->shortmessage = "FAILED";
register_log("surepay", "InvalidCCNumberException received (ID ".$this->TransactionID.")");
}
else {
$this->authstatus = FALSE;
$this->message = "We could not process your credit card. Please try again, or email us at support@nameboy.com.";
$this->shortmessage = "ERROR";
//echo 'No valid result returned';
register_log("surepay", "auth error: Result was: ".$this->result."\n");
}
return $this->result;
} // function ProcessXMLRequest
function PostXMLRequest($data) {
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "https://xml.surepay.com");
// curl_setopt ($ch, CURLOPT_URL, "http://midwifeinfo.com/app.php");
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->reqheader . $data);
curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 360);
curl_setopt ($ch, CURLOPT_HEADER, 0);
// curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$this->result = curl_exec ($ch);
}
function LoadCCfromUser($login, $shipfname, $shiplname, $ccn, $exp, $addr1, $addr2, $city, $state, $country, $phone, $zipcode) {
$this->login = $login;
$this->shipfname = $shipfname;
$this->shiplname = $shiplname;
$this->ccn = $ccn;
$this->exp = $exp;
$this->addr1 = $addr1;
$this->addr2 = $addr2;
$this->city = $city;
$this->state = $state;
$this->country = $country;
$this->phone = $phone;
$this->zipcode = $zipcode;
}
function LoadCCfromDB($login) {
$qs = "select * from dr_user_cc where login = '$login';";
$qr = mysql_query($qs);
$nr = mysql_num_rows($qr);
if ($nr>0) {
//found cc
$row = mysql_fetch_row($qr);
$this->login = $row[0];
$this->shipfname = $row[1];
$this->shiplname = $row[2];
$this->ccn = $row[3];
$this->exp = $row[4];
$this->addr1 = $row[5];
$this->addr2 = $row[6];
$this->city = $row[7];
$this->state = $row[8];
$this->country = $row[9];
$this->phone = $row[10];
$this->zipcode = $row[11];
}
else {
//no such cc info;
return FALSE;
}
}
function Prepare () {
// load the generic variables for the SurePay account
$this->merchantid = "20430";
$this->password = "2pvpis";
$this->orderid = "1";
$this->shippingcost = "0.00";
$this->sku = "3";
// $this->description = "DeleteReport Membership Fee";
// $this->quantity = "1";
// $this->unitprice = "9.95";
}
function UpdateTransactionDB() {
$qs = "insert into dr_transactions values ('$this->login', NULL, '$this->ccn','$this->exp','$this->addr','$this->zipcode','$this->city','$this->state', '$this->country', '$this->shipfname', '$this->shiplname', '$this->shortmessage', $this->unitprice);";
//echo $qs;
$qr = mysql_query($qs);
}
function UpdateCCDB() {
$qs = "replace into dr_user_cc values ('$this->login','$this->shipfname','$this->shiplname','$this->ccn','$this->exp','$this->addr1','$this->addr2','$this->city','$this->state','$this->country','$this->phone','$this->zipcode');";
// echo $qs;
$qr = mysql_query($qs);
}
function Dump () {
echo "
\n";
print_r($this);
echo "
\n";
}
} // class SurePayObject
?>