-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCProcessInterface.php
More file actions
111 lines (93 loc) · 3.33 KB
/
CCProcessInterface.php
File metadata and controls
111 lines (93 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
//create a session
session_start();
class CCProcessInterface
{
//validates a credit card with cc number, name, expiration date, and amount of purchase.
//returns true if successful, false if unsuccessful
//updates transaction number at the end
public function validateCard($creditCardNum, $name, $exp, $amt, $last4)
{
//this code obtained from BlackBoard
$transactionNum = CCProcessInterface::getTransactionNumber();
$url = 'http://blitz.cs.niu.edu/CreditCard/';
$data = array(
'vendor' => 'VE001-99',
'trans' => $transactionNum,
'cc' => $creditCardNum,
'name' => $name,
'exp' => $exp,
'amount' => $amt);
$options = array(
'http' => array(
'header' => array(
'Content-type: application/json'
, 'Accept: application/json'),
'method' => 'POST',
'content'=> json_encode($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
//search for "errors" in $result
$auth = json_decode($result);
//success, errors not found and $auth is not empty
if(!isset($auth->{"errors"}))
{
$_SESSION["payment"] = '****-****-****-';
$_SESSION["payment"] .= $last4;
echo "card validated";
CCProcessInterface::updateTransactionNumber($transactionNum);
return true;
//update current transacton number
}
//else failure
else
{
echo "card failed to validate: ".$auth->{"errors"}[0];
return false;
}
}
//returns next transaction number
public static function getTransactionNumber()
{
//CONNECT TO SYSTEM DATABASE
$dsn = "mysql:host=courses;dbname=z1808910";
$username = "z1808910";
$password = "1994Aug19";
try
{
$pdo = new PDO($dsn, $username, $password);
}//end of try
catch(PDOexception $e) {
echo $e->getMessage();
}//end of catch
//END CONNECT TO SYSTEM DATABASE
//run sql query
$sql = $pdo->query("select * FROM cctransnum ORDER BY num DESC LIMIT 1;");
$rows = $sql->fetchAll();
return $rows[0][0];
}
//updates database to hold next transaction number
public static function updateTransactionNumber($currentTransNum)
{
//add one to current transaction number
$one = 1;
$newTransNum = $currentTransNum + $one;
//CONNECT TO SYSTEM DATABASE
$dsn = "mysql:host=courses;dbname=z1808910";
$username = "z1808910";
$password = "1994Aug19";
try
{
$pdo = new PDO($dsn, $username, $password);
}//end of try
catch(PDOexception $e) {
echo $e->getMessage();
}//end of catch
//END CONNECT TO SYSTEM DATABASE
//run sql query
$sql = $pdo->query("UPDATE cctransnum SET num = ".$newTransNum." WHERE num = " .$currentTransNum.";");
}
}
?>