WEB-HOSTING-CANADA-SHOPPING-CART.PHP
This is an improved version of
web-hosting-shopping-cart.php .
Thanks to the enom component, it can tell a potential client that a domain name is taken.
Now people can manually enter the amount of extra bandwidth and disk space that they want.
I created a separate script to handle the checkout, it's a little more tedious for the client,
but it handles multiple forms of payment better.
Added error checking to the forms. Also added a Credit Card information
gathering interface. It's currently disabled though.
A working version of this this shopping cart can be found
here .
The complete source code can be found
here .
I removed PaySystems support: After losing their ability to process
credit cards outside the US, they left us with about 30 broken subscriptions.
Not only that, they also kept nearly 2000 of our dollars.
Recently our account was mysteriously deleted from their database.
We don't like them.
<?
include("verify-email-address.php");
extract($_GET);
extract($_POST);
$notification_email = "support@webhostingcanada.org";
$notification_email_cc = "sales@webhostingcanada.org";
?>
<?
if($checkout == "PayPalPurchase")
$f = "y";
?>
<? include("calculate.php"); ?>
5
Invoice
<? if(isset($sld)) { ?>
<?= $sld . "." . $tld ?> Domain Name <?= sprintf("$%01.2f",$domain) ?>
<?= $plandesc ?> Plan <?= sprintf("$%01.2f",$plan) ?>
<? if($diskspace != 0) { ?>
Additional Diskspace <?= sprintf("$%01.2f",$diskspace) ?>
<? } ?>
<? if($bandwidth != 0) { ?>
Additional Bandwidth <?= sprintf("$%01.2f",$bandwidth) ?>
<? } ?>
<? if($gst != 0) { ?>
GST <?= sprintf("$%01.2f",$gst) ?>
<? } ?>
<? if($pst != 0) { ?>
PST <?= sprintf("$%01.2f",$pst) ?>
<? } ?>
<? $total = sprintf("%01.2f",($subtotal + $gst + $pst));?>
Payable every <?= $frequency ?>
<? } ?>
<?
$error_messages = Array();
if(isset($ccnumber))
{
if(is_numeric($ccnumber) == false || strlen($ccnumber) != 16)
$error_messages[sizeof($error_messages)] = "Your credit card number should consist of 16 decimal digits.";
if(is_numeric($cccvv) == false || strlen($cccvv) != 3)
$error_messages[sizeof($error_messages)] = "Your CVV number should consist of 3 decimal digits.";
if($ccname == "" ||
$ccaddress == "" ||
$cccity == "" ||
$ccprovince == "" ||
$cccountry == "" ||
$ccpc == "")
$error_messages[sizeof($error_messages)] = "Please Fill in all the fields below.";
if(verify_email_address($email) == false)
$error_messages[sizeof($error_messages)] = "Please enter a valid email address.";
}
?>
6
Checkout
<? if(sizeof($error_messages) != 0) { ?>
<? for($index = 0; $index < sizeof($error_messages); $index++) { ?>
<?= $error_messages[$index] ?>
<? } ?>
<? } ?>
<?
$item_number = "item_number=" .
$plandesc . "-" . $sld . "." . $tld . "-" . $d. "-" . $p;
if($dk != "")
$item_number .= "-" . $dk . "Megs(diskspace)";
if($b != "")
$item_number .= "-" . $p . "Gigs(bandwidth)";
$item_number .= "-" . $f;
$item_name = "item_name=" . urlencode($sld . "." . $tld . " WebHostingCanada.org account.");
$business_email = "sales@bambookit.com";
?>
<? if($checkout == "PayPalSubscription") { ?>
<?
$days = "365";
$yahoof = "Y";
if($f == "m") {$days = "30"; $yahoof = "M";}
$paypal = "https://www.paypal.com/subscriptions/business=" . $business_email .
"&" . $item_number .
"&" . $item_name .
"&no_note=1¤cy_code=CAD&a3=" .
$total . "&p3=1&t3=" . $yahoof . "&src=1&sra=1";
} //PayPal Subscription. ?>
<? if($checkout == "PayPalPurchase") { ?>
<?
$days = "365";
$yahoof = "Y";
if($f == "m") {$days = "30"; $yahoof = "M";}
$paypal = "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" . $business_email .
"&" . $item_number .
"&" . $item_name .
"&amount=" . $total .
"&no_shipping=0&no_note=1¤cy_code=CAD&charset=UTF%2d8";
} //PayPal Subscription. ?>
<? if($checkout == "PayPalSubscription" || $checkout == "PayPalPurchase")
{
$headers = "From: " . $notification_email . "\n" .
"To: " . $notification_email;
//I do this because we can't allways count on paypal to
//send us an email when someone signs up through them.
mail("", $sld . "." . $tld . " WebHostingCanada.org account.", $paypal, $headers);
?>
<? } //PayPal. ?>
<? if($checkout == "CreditCard" && sizeof($error_messages) == 0)
{
$creditcard = $item_number . "\n\n" .
$ccnumber . " " . $cccvv . " " . $ccexpmonth . "-" . $ccexpyear . "\n\n" .
$ccname . "\n" .
$ccaddress . "\n" .
$cccity . "\n" .
$ccprovince . "\n" .
$cccountry . "\n" .
$ccpc;
$headers = "From: " . $notification_email . "\n" .
"To: " . $notification_email . "\n" .
"CC: " . $notification_email_cc;
mail("", $item_name, $creditcard, $headers);
?>
Your order has been placed. Thank you for choosing to host your site with us.
<? } ?>
<? if($checkout == "CreditCard" && sizeof($error_messages) != 0) { ?>
Credit Card Number
CVV Number
Name on the Credit Card
Address
City
State / Province
Country
Postal Code
Phone Number
Email Address
Credit Card Expiration Date
<? $month_names = array
(
"jan",
"feb",
"mar",
"apr",
"may",
"jun",
"jul",
"aug",
"sep",
"oct",
"nov",
"dec"
);
for($index = 1; $index <= 9; $index++) { ?>
0<?= $index ?>(<?= $month_names[$index - 1] ?>)
<? } ?>
<? for($index = 10; $index <= 12; $index++) { ?>
<?= $index ?>(<?= $month_names[$index - 1] ?>)
<? } ?>
<?
$date = getDate();
$year = $date["year"];
?>
<? for($index = 0; $index <= 10; $index++) { ?>
<?= ($index + $year) ?>
<? } ?>
<? } //CreditCard ?>