forked from mewebstudio/pos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosHelpersTrait.php
85 lines (73 loc) · 1.48 KB
/
PosHelpersTrait.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
<?php
namespace Mews\Pos;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
/**
* Trait PosHelpersTrait
* @package Mews\Pos
*/
trait PosHelpersTrait
{
/**
* API URL
*
* @var string
*/
public $url;
/**
* 3D Pay Gateway URL
*
* @var string
*/
public $gateway;
/**
* Create XML DOM Document
*
* @param array $nodes
* @param string $encoding
* @return string the XML, or false if an error occurred.
*/
public function createXML(array $nodes, $encoding = 'UTF-8')
{
$rootNodeName = array_keys($nodes)[0];
$encoder = new XmlEncoder($rootNodeName);
$xml = $encoder->encode($nodes[$rootNodeName], 'xml', [
'xml_encoding' => $encoding
]);
return $xml;
}
/**
* Print Data
*
* @param $data
* @return null|string
*/
public function printData($data)
{
if ((is_object($data) || is_array($data)) && !count((array) $data)) {
$data = null;
}
return (string) $data;
}
/**
* Is success
*
* @return bool
*/
public function isSuccess()
{
$success = false;
if (isset($this->response) && $this->response->status == 'approved') {
$success = true;
}
return $success;
}
/**
* Is error
*
* @return bool
*/
public function isError()
{
return !$this->isSuccess();
}
}