5.0 from trustcommerce
[tclink.git] / tcexample.php
CommitLineData
d667da5b
IK
1<?
2 // This example assumes that tclink.so has already been loaded.
3 // Normally this is done by adding "extension=tclink.so" to your
4 // php.ini, but you may also make a manual call to dl("tclink")
5 // as well. See tctest.php for example code.
6
7 $custid = (!empty($_REQUEST['custid']) ? $_REQUEST['custid'] : "TestMerchant");
8 $password = (!empty($_REQUEST['password']) ? $_REQUEST['password'] : "password");
9?>
10<html>
11<head><title>TCLink PHP Example</title></head>
12<body bgcolor=white text=black>
13
14 <form method="post" action="<?= $PHP_SELF ?>">
15
16 <table cellspacing=1 cellpadding=3>
17 <tr bgcolor=blue><th colspan=2 align=center>
18 <font color=white>TrustCommerce PHP Example - TCLink ver. <?= tclink_getversion() ?>)</font>
19 </th></tr>
20
21 <tr><th align=right> CustID: </td><td> <input type="text" name="custid" value="<?= htmlspecialchars($custid) ?>"> </td></tr>
22 <tr><th align=right> Password: </td><td> <input type="text" name="password" value="<?= htmlspecialchars($password) ?>"> </td></tr>
23 <tr><th align=right> Action: </td><td> <select name="action">
24 <option value="sale">Sale</option>
25 <option value="preauth">Pre-Authorization</option>
26 <option value="postauth">Post-Authorization</option>
27 <option value="credit">Credit</option>
28 </select> </td></tr>
29 <tr><th align=right> Amount (in cents):</td><td> <input type="text" name="amount"> </td></tr>
30 <tr bgcolor=lightgray><td colspan=2 align=center> Sales and Pre-Authorizations Only: </td></tr>
31 <tr><th align=right> Card Number: </td><td> <input type="text" name="cc" size="16" maxlength="16"> </td></tr>
32 <tr><th align=right> Expiration: </td>
33 <td><select name="mm"><? for ($i = 1; $i <= 12; $i++) { ?><option value="<?=sprintf("%02d", $i);?>"><?=sprintf("%02d", $i);?></option><? } ?></select>
34 <select name="yy"><? for($i = (strftime("%Y")); $i <= (strftime("%Y") + 10); $i++) { ?><option value="<?=substr(sprintf("%04d", $i),2,2);?>"><?=$i;?></option><? } ?></select><br>
35 </td></tr>
36 <tr><th align=right> Cardholder Name: </td><td> <input type="text" name="name"> </td></tr>
37 <tr bgcolor=lightgray><td colspan=2 align=center> Credits and Post-Authorizations Only: </td></tr>
38 <tr><th align=right> Transaction ID: </td><td> <input type="text" name="transid" size="14" maxlength="14"> </td></tr>
39 <tr><td colspan=2 align=center> <input type="submit" name="Action" value="Process"> </td></tr>
40
41 <?
42 if ($_REQUEST['Action'] == 'Process')
43 {
44 $tclink['custid'] = $custid;
45 $tclink['password'] = $password;
46 $tclink['action'] = $_REQUEST['action'];
47 if (is_numeric($_REQUEST['amount']))
48 $tclink['amount'] = $_REQUEST['amount'];
49
50 if ($_REQUEST['action'] == 'sale' || $_REQUEST['action'] == 'preauth')
51 {
52 $tclink['name'] = $_REQUEST['name'];
53 $tclink['cc'] = $_REQUEST['cc'];
54 $tclink['exp'] = $_REQUEST['mm'] . $_REQUEST['yy'];
55 }
56 else if ($_REQUEST['action'] == 'credit' || $_REQUEST['action'] == 'postauth')
57 {
58 $tclink['transid'] = $_REQUEST['transid'];
59 }
60
61 $result = tclink_send($tclink);
62
63 print "<tr><td colspan=2><hr></td></tr>";
64 print "<tr bgcolor=blue><th colspan=2 align=center><font color=white>Transaction Results:</font></td></tr>";
65
66 if ($result['transid'])
67 printf("<tr><th>Transaction ID:</th><td>%s</td></tr>\n", $result['transid']);
68
69 printf("<tr><th>Status:</td><td>%s</td></tr>\n", $result['status']);
70 switch($result['status'])
71 {
72 case 'accepted':
73 case 'approved':
74 break;
75
76 case 'decline':
77 case 'rejected':
78 printf("<tr><th>Decline Type:</th><td>%s</td></tr>\n", $result['declinetype']);
79 break;
80
81 case 'error':
82 printf("<tr><th>Error Type</th><td>%s</td></tr>\n", $result['errortype']);
83 break;
84
85 case 'baddata':
86 printf("<tr><th>Offenders:</th><td>%s</td></tr>\n", htmlspecialchars($result['$offenders']));
87 break;
88 }
89
90 print "<tr bgcolor=lightgray><td colspan=2 align=center>All Results:</td></tr>";
91
92 while(list($key, $value) = each($result))
93 printf("<tr><th>%s</th><td>%s</td></tr>\n", htmlspecialchars($key), htmlspecialchars($value));
94 }
95 ?>
96
97</table>
98</form>
99
100</body>
101</html>