de2044b6a67d0cff4420be60a86ea0fb8791f596
[tclink.git] / curltest.php
1 <?
2 // Sends the transaction to us and processes the response into a
3 // standard PHP array.
4 function curl_tc_send($fields_to_send)
5 {
6 $post_string = '';
7 $use_amp = 0;
8 foreach ($fields_to_send as $key => $value)
9 {
10 if ($use_amp) $post_string .= '&';
11 $post_string .= "$key=$value";
12 $use_amp = 1;
13 }
14 $curl_object = curl_init('https://vault.trustcommerce.com/trans/');
15 curl_setopt($curl_object, CURLOPT_RETURNTRANSFER, 1);
16 curl_setopt($curl_object, CURLOPT_POST, 1);
17 curl_setopt($curl_object, CURLOPT_POSTFIELDS, $post_string);
18
19 $unformatted_results = curl_exec($curl_object);
20 curl_close($curl_object);
21 $result_array = explode("\n", $unformatted_results);
22 $tclink_results = array();
23 foreach ($result_array as $key => $value)
24 {
25 $key_pair = explode('=', $value);
26 if (count($key_pair) == 2)
27 {
28 $tclink_results[$key_pair[0]] = $key_pair[1];
29 }
30 }
31 return $tclink_results;
32 }
33
34 $transaction = array(
35 'custid' => 'XXXX',
36 'password' => 'PPPP',
37 'action' => 'preauth',
38 'amount' => '100',
39 'cc' => '4111111111111111',
40 'exp' => '1213',
41 'address1' => '123 Anywhere St',
42 'zip' => '92606'
43 );
44
45 print_r(curl_tc_send($transaction));
46
47 ?>