office payments

[insert_php]
define(“APPROVED”, 1);
define(“DECLINED”, 2);
define(“ERROR”, 3);

class gwapi {

function setLogin($username, $password) {
$this->login[‘username’] = $username;
$this->login[‘password’] = $password;
}

function setOrder($orderid,
$orderdescription) {
$this->order[‘orderid’] = $orderid;
$this->order[‘orderdescription’] = $orderdescription;
}

function setBilling($firstname,
$lastname,
$address1,
$address2,
$city,
$state,
$zip,
$phone,
$email) {
$this->billing[‘firstname’] = $firstname;
$this->billing[‘lastname’] = $lastname;
$this->billing[‘address1’] = $address1;
$this->billing[‘address2’] = $address2;
$this->billing[‘city’] = $city;
$this->billing[‘state’] = $state;
$this->billing[‘zip’] = $zip;
$this->billing[‘phone’] = $phone;
$this->billing[’email’] = $email;
}

function doSale($amount, $ccnumber, $ccexp, $cvv) {

$query = “”;
// Login Information
$query .= “username=” . urlencode($this->login[‘username’]) . “&”;
$query .= “password=” . urlencode($this->login[‘password’]) . “&”;
// Sales Information
$query .= “ccnumber=” . urlencode($ccnumber) . “&”;
$query .= “ccexp=” . urlencode($ccexp) . “&”;
$query .= “amount=” . urlencode(number_format($amount,2,”.”,””)) . “&”;
$query .= “cvv=” . urlencode($cvv) . “&”;
// Order Information
$query .= “orderid=” . urlencode($this->order[‘orderid’]) . “&”;
$query .= “orderdescription= ” . urlencode($this->order[‘orderdescription’]) . “&”;
// Billing Information
$query .= “firstname=” . urlencode($this->billing[‘firstname’]) . “&”;
$query .= “lastname=” . urlencode($this->billing[‘lastname’]) . “&”;
$query .= “address1=” . urlencode($this->billing[‘address1’]) . “&”;
$query .= “address2=” . urlencode($this->billing[‘address2’]) . “&”;
$query .= “city=” . urlencode($this->billing[‘city’]) . “&”;
$query .= “state=” . urlencode($this->billing[‘state’]) . “&”;
$query .= “zip=” . urlencode($this->billing[‘zip’]) . “&”;
$query .= “phone=” . urlencode($this->billing[‘phone’]) . “&”;
$query .= “email=” . urlencode($this->billing[’email’]) . “&”;
$query .= “customer_receipt=true” . “&”;
$query .= “type=sale”;
return $this->_doPost($query);
}

function _doPost($query) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, “https://secure.nmi.com/api/transact.php”);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_POST, 1);

if (!($data = curl_exec($ch))) {
return ERROR;
}
curl_close($ch);
unset($ch);
//print “\n$data\n”; //print all the data (debug only)!!!!!
$data = explode(“&”,$data);
for($i=0;$i<count($data);$i++) { $rdata = explode(“=”,$data[$i]); $this->responses[$rdata[0]] = $rdata[1];
}
if ($data[0]==”response=1″) {
Print “\nInvoice Summary\n”;
Print “\n” . $_POST[‘fname’] . ‘ ‘ . $_POST[‘lname’] . “\n”;
Print “\n” . $_POST[‘address1’] . “\n”;
Print “\n” . $_POST[‘address2’] . “\n”;
Print “\n” . $_POST[‘city’] . ‘, ‘ . $_POST[‘state’] . ‘ ‘ . $_POST[‘zip’] . “\n”;
print “\n$data[3]\n”;
print “\n” . ‘Patient Name: ‘ . $_POST[‘ptfname’] . ” ” . $_POST[‘ptlname’] . “\n”;
print “\n” . ‘Account Number = ‘ . $_POST[‘inv’] . “\n”;
print “\n” . ‘Payment Amount: $ ‘ . $_POST[‘amt’] .”\n”;
print “\n” . ‘Description:’. ‘ ‘. $_POST[‘office’] . ‘ ‘ . $_POST[‘desc’] . “\n”;
print “\n” . ‘ Please check your email for a copy of the receipt. ‘ . “\n”;
//print “\n$data[0]\n”;
//credit card formatting
function FormatCreditCard($cc) {

//replace the – with “”
$cc = str_replace(array(‘-‘, ‘ ‘), ”, $cc);

//length of the var
$cc_length = strlen($cc);

$newCreditCard = substr($cc, -4);

for ($i = $cc_length – 5; $i >= 0; $i–) {
// ADDS HYPHEN HERE
if ((($i + 1) – $cc_length) % 4 == 0) {
$newCreditCard = ‘-‘ . $newCreditCard;
}
$newCreditCard = $cc[$i] . $newCreditCard;
}

// REPLACE CHARACTERS WITH X EXCEPT FIRST FOUR AND LAST FOUR
for ($i = 0; $i < $cc_length – 1; $i++) { if ($newCreditCard[$i] == ‘-‘) { continue; } $newCreditCard[$i] = ‘*’; } // RETURN THE FINAL FORMATED AND MASKED CREDIT CARD NO return $newCreditCard; } //create email //body $email_message = “Receipt Summary below.\n\n”; $email_message .= “Transaction Information\n”; $email_message .= “Patient Name: “.$_POST[‘ptfname’].” “.$_POST[‘ptlname’].”\n”; $email_message .= “Account Number: “.$_POST[‘inv’].”\n”; $email_message .= “Description: “.$_POST[‘desc’].”\n”; $email_message .= “Transaction Amount : $”.$_POST[‘amt’].”\n”; $email_message .= “$data[3]\n”; $email_message .= “Credit Card Number: “.FormatCreditCard($_POST[‘card’]).”\n”; $email_message .= “Expiration Date: “.$_POST[‘exp’].”\n”; $email_message .= “\nCustomer Billing Information\n”; $email_message .= “First Name: “.$_POST[‘fname’].” “.$_POST[‘lname’].”\n”; $email_message .= “Address: “.$_POST[‘address1’].”\n”; $email_message .= “Address 2: “.$_POST[‘address2’].”\n”; $email_message .= “City: “.$_POST[‘city’].”\n”; $email_message .= “State: “.$_POST[‘state’].”\n”; $email_message .= “Zip Code: “.$_POST[‘zip’].”\n”; $email_message .= “Phone: “.$_POST[‘phone’].”\n”; $email_message .= “Email: “.$_POST[’email’].”\n”; //email $email_to = “megan.miller@ips-mso.com,hui.yang@ips-mso.com”; //$email_to = “hui.yang@ips-mso.com”; //testing email $email_subject = “NPA Payment, Account # ” . $_POST[‘inv’]; $email_from = ” npa.online.billpay@npa.com”; $headers = ‘From: ‘.$email_from.”\r\n”.’Reply-To: ‘.$email_from.”\r\n”.’X-Mailer: PHP/’ . phpversion(); //mail($email_to, $email_subject, $email_message, $headers); //echo “Mail Sent.”; return $this->responses[‘response’];
}
else {
print “Payment Fail. Please check your information, and try again”;
}
}
}

if (empty($_POST[‘submit’]) && empty($_GET[‘token-id’])) {

print ‘ ‘;
print ‘

 

Billing Information

*Office: *Credit Card Number: *Expiration Date: (mmyy) *Card Security Code: CVV2/CID

Payment information

*Patients: Last Name: First Name: *Amount: (nn.nn) *Account Number: Description:

Card Billing Address

*First Name: *Last Name: *Address: *City: *State: *Zip/Postal: *Phone Number: *Email Address:

* Your payment will be secure through our Secure Sockets Layer (SSL) connection for storage in our Level 1 PCI certified data facility. *If there is an issue please email info@ips-mso.com

‘;
}else if ($_POST[‘submit’]=”true”){
$gw = new gwapi;
$gw->setLogin(“salesonly”, “Criticalmass1”);
$gw->setBilling($_POST[‘fname’],$_POST[‘lname’],$_POST[‘address1’],$_POST[‘address2’],$_POST[‘city’],$_POST[‘state’],$_POST[‘zip’],$_POST[‘phone’],$_POST[’email’]);
$gw->setOrder($_POST[‘inv’],$_POST[‘office’] . ‘ ‘ . $_POST[‘desc’]);

$r = $gw->doSale($_POST[‘amt’],$_POST[‘card’],$_POST[‘exp’],$_POST[‘cvv’]);
//print $gw->responses[‘responsetext’]; //prints response from the server
}
[/insert_php]