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.
7 $custid = (!empty($_REQUEST['custid']) ?
$_REQUEST['custid'] : "TestMerchant");
8 $password = (!empty($_REQUEST['password']) ?
$_REQUEST['password'] : "password");
11 <head
><title
>TCLink PHP Example
</title
></head
>
12 <body bgcolor
=white text
=black
>
14 <form method
="post" action
="<?= $PHP_SELF ?>">
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
>
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
>
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
>
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
>
42 if ($_REQUEST['Action'] == 'Process')
44 $tclink['custid'] = $custid;
45 $tclink['password'] = $password;
46 $tclink['action'] = $_REQUEST['action'];
47 if (is_numeric($_REQUEST['amount']))
48 $tclink['amount'] = $_REQUEST['amount'];
50 if ($_REQUEST['action'] == 'sale' ||
$_REQUEST['action'] == 'preauth')
52 $tclink['name'] = $_REQUEST['name'];
53 $tclink['cc'] = $_REQUEST['cc'];
54 $tclink['exp'] = $_REQUEST['mm'] . $_REQUEST['yy'];
56 else if ($_REQUEST['action'] == 'credit' ||
$_REQUEST['action'] == 'postauth')
58 $tclink['transid'] = $_REQUEST['transid'];
61 $result = tclink_send($tclink);
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>";
66 if ($result['transid'])
67 printf("<tr><th>Transaction ID:</th><td>%s</td></tr>\n", $result['transid']);
69 printf("<tr><th>Status:</td><td>%s</td></tr>\n", $result['status']);
70 switch($result['status'])
78 printf("<tr><th>Decline Type:</th><td>%s</td></tr>\n", $result['declinetype']);
82 printf("<tr><th>Error Type</th><td>%s</td></tr>\n", $result['errortype']);
86 printf("<tr><th>Offenders:</th><td>%s</td></tr>\n", htmlspecialchars($result['$offenders']));
90 print "<tr bgcolor=lightgray><td colspan=2 align=center>All Results:</td></tr>";
92 while(list($key, $value) = each($result))
93 printf("<tr><th>%s</th><td>%s</td></tr>\n", htmlspecialchars($key), htmlspecialchars($value));