forked from MercuryPay/WebServices.PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMercury_Web_Services_SOAP_Helper.php
98 lines (82 loc) · 2.34 KB
/
Mercury_Web_Services_SOAP_Helper.php
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
<?php
class Mercury_Web_Services_SOAP_Helper
{
private $wsClient;
function __construct()
{
// Mercury Certification WSDL
$wsdlURL = "https://w1.mercurydev.net/ws/ws.asmx?WSDL";
$this->wsClient = new SoapClient($wsdlURL);
}
private function array_to_xml(array $arr, SimpleXMLElement &$xml)
{
foreach ($arr as $k => $v)
{
is_array($v) ? array_to_xml($v, $xml) : $xml->children()->addChild($k, $v);
}
return $xml->asXML();
}
private function array_flat(array $complexArray, array &$flatArray)
{
foreach ($complexArray as $key => $value)
{
if (is_array($value))
{
$flatArray = array_merge($flatArray, $this->array_flat($value, $flatArray));
}
else
{
$flatArray[$key] = $value;
}
}
return $flatArray;
}
public function credit_transaction(array $requestData, $password)
{
$tStream = new SimpleXMLElement('<TStream/>');
$secondElement = "Transaction";
if (isset($requestData["TranCode"]))
{
switch (strtolower($requestData["TranCode"]))
{
case "batchsummary":
case "itemdetail":
case "batchclear":
case "batchclose":
case "serverversion":
case "keychange":
$secondElement = "Admin";
break;
}
}
$tStream->addChild($secondElement);
$xmlRequest = $this->array_to_xml($requestData, $tStream);
$clientRequest = array(
"tran" => $xmlRequest,
"pw" => $password,
);
$xmlResponse = $this->wsClient->CreditTransaction($clientRequest)->CreditTransactionResult;
$complexArray = json_decode(json_encode((array) simplexml_load_string($xmlResponse)),1);
$flatArray = array();
$flatArray = $this->array_flat($complexArray, $flatArray);
return $flatArray;
}
public function gift_transaction(array $requestData, $password)
{
// IpPort required for Gift Transactions
$requestData["IpPort"] = "9100";
$tStream = new SimpleXMLElement('<TStream/>');
$tStream->addChild("Transaction");
$xmlRequest = $this->array_to_xml($requestData, $tStream);
$clientRequest = array(
"tran" => $xmlRequest,
"pw" => $password,
);
$xmlResponse = $this->wsClient->GiftTransaction($clientRequest)->GiftTransactionResult;
$complexArray = json_decode(json_encode((array) simplexml_load_string($xmlResponse)),1);
$flatArray = array();
$flatArray = $this->array_flat($complexArray, $flatArray);
return $flatArray;
}
}
?>