-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.php
More file actions
110 lines (96 loc) · 3.34 KB
/
Copy pathutil.php
File metadata and controls
110 lines (96 loc) · 3.34 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
<?php
/*
D I S C L A I M E R
WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IS AT YOUR OWN RISK.
Authorize.Net provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Authorize.Net owns and retains all right, title and interest in and to the Automated Recurring Billing intellectual property.
*/
include_once ("vars.php");
//function to send xml request to Api.
//There is more than one way to send https requests in PHP.
function send_xml_request($content)
{
global $g_apihost, $g_apipath;
return send_request_via_fsockopen($g_apihost,$g_apipath,$content);
}
//function to send xml request via fsockopen
//It is a good idea to check the http status code.
function send_request_via_fsockopen($host,$path,$content)
{
$posturl = "ssl://" . $host;
$header = "Host: $host\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: ".strlen($content)."\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = fsockopen($posturl, 443, $errno, $errstr, 30);
if (!$fp)
{
$body = false;
}
else
{
error_reporting(E_ERROR);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, $header.$content);
fwrite($fp, $out);
$response = "";
while (!feof($fp))
{
$response = $response . fgets($fp, 128);
}
fclose($fp);
error_reporting(E_ALL ^ E_NOTICE);
$len = strlen($response);
$bodypos = strpos($response, "\r\n\r\n");
if ($bodypos <= 0)
{
$bodypos = strpos($response, "\n\n");
}
while ($bodypos < $len && $response[$bodypos] != '<')
{
$bodypos++;
}
$body = substr($response, $bodypos);
}
return $body;
}
//function to send xml request via curl
function send_request_via_curl($host,$path,$content)
{
$posturl = "https://" . $host . $path;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
return $response;
}
//function to parse the api response
//The code uses SimpleXML. http://us.php.net/manual/en/book.simplexml.php
//There are also other ways to parse xml in PHP depending on the version and what is installed.
function parse_api_response($content)
{
$parsedresponse = simplexml_load_string($content, "SimpleXMLElement", LIBXML_NOWARNING);
if ("Ok" != $parsedresponse->messages->resultCode) {
//echo "The operation failed with the following errors:<br>";
//foreach ($parsedresponse->messages->message as $msg) {
// echo "[" . htmlspecialchars($msg->code) . "] " . htmlspecialchars($msg->text) . "<br>";
//}
//echo "<br>";
}
return $parsedresponse;
}
function MerchantAuthenticationBlock() {
global $g_loginname, $g_transactionkey;
return
"<merchantAuthentication>".
"<name>" . $g_loginname . "</name>".
"<transactionKey>" . $g_transactionkey . "</transactionKey>".
"</merchantAuthentication>";
}
?>