• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / PayWay / 5212705470

pending completion
5212705470

push

github

mlocati
Initial version

1803 of 1803 new or added lines in 47 files covered. (100.0%)

1313 of 1803 relevant lines covered (72.82%)

1.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.12
/src/Verify/Response/Unserializer.php
1
<?php
2

3
namespace MLocati\PayWay\Verify\Response;
4

5
use DOMElement;
6
use MLocati\PayWay\Service;
7
use MLocati\PayWay\Verify\Response;
8

9
class Unserializer
10
{
11
    use Service\UnserializerTrait;
12

13
    const NS_SOAPENVELOPE = 'http://schemas.xmlsoap.org/soap/envelope/';
14

15
    const NS_IGFS = 'http://services.api.web.cg.igfs.apps.netsw.it/';
16

17
    /**
18
     * @param string $raw
19
     *
20
     * @throws \MLocati\PayWay\Exception\InvalidXml
21
     */
22
    public function unserialize($raw)
23
    {
24
        $xResponse = $this->loadDocument($raw, '/soap:Envelope/soap:Body/igfs:VerifyResponse/response');
3✔
25
        $response = new Response();
2✔
26
        foreach ($this->listDOMElements($xResponse) as $child) {
2✔
27
            $tagName = $child->tagName;
2✔
28
            $setter = 'set' . ucfirst($tagName);
2✔
29
            $value = (string) $child->nodeValue;
2✔
30
            switch ($tagName) {
31
                case 'reqTime':
2✔
32
                    $value = $this->unserializeDateTime($value);
×
33
                    break;
×
34
                case 'error':
2✔
35
                    $value = $this->unserializeBoolean($value);
2✔
36
                    break;
2✔
37
                case 'tranID':
2✔
38
                case 'expireMonth':
2✔
39
                case 'expireYear':
2✔
40
                    $value = $this->unserializeInteger($value);
1✔
41
                    break;
1✔
42
                case 'additionalFee':
2✔
43
                    $value = $this->unserializeInteger($value);
×
44
                    $setter .= 'AsCents';
×
45
                    break;
×
46
                case 'level3Info':
2✔
47
                    $value = $this->unserializeLevel3Info($child, $response);
1✔
48
                    break;
1✔
49
                case 'payTraceData':
2✔
50
                    list($key, $value) = $this->unserializeEntryAttribute($child, $response);
×
51
                    $response->addPayTraceData($key, $value);
×
52
                    continue 2;
×
53
                case 'payAddData':
2✔
54
                    list($key, $value) = $this->unserializeEntryAttribute($child, $response);
×
55
                    $response->addPayAddData($key, $value);
×
56
                    continue 2;
×
57
            }
58
            if (!method_exists($response, $setter)) {
2✔
59
                $response->addUnrecognizedXmlElement($child);
×
60
                continue;
×
61
            }
62
            $response->{$setter}($value);
2✔
63
        }
64

65
        return $response;
2✔
66
    }
67

68
    /**
69
     * @return \MLocati\PayWay\Service\Level3Info
70
     */
71
    protected function unserializeLevel3Info(DOMElement $node, Response $response)
72
    {
73
        $result = new Service\Level3Info();
1✔
74
        foreach ($this->listDOMElements($node) as $child) {
1✔
75
            $tagName = $child->tagName;
1✔
76
            $setter = 'set' . ucfirst($tagName);
1✔
77
            $value = (string) $child->nodeValue;
1✔
78
            switch ($tagName) {
79
                case 'destinationDate':
1✔
80
                    $value = $this->unserializeDateTime($value);
×
81
                    break;
×
82
                case 'freightAmount':
1✔
83
                case 'taxAmount':
1✔
84
                    $value = $this->unserializeInteger($value);
1✔
85
                    $setter .= 'AsCents';
1✔
86
                    break;
1✔
87
                case 'product':
1✔
88
                    $result->addProduct($this->unserializeLevel3InfoProduct($child, $response));
1✔
89
                    continue 2;
1✔
90
            }
91
            if (!method_exists($result, $setter)) {
1✔
92
                $response->addUnrecognizedXmlElement($child);
×
93
                continue;
×
94
            }
95
            $result->{$setter}($value);
1✔
96
        }
97

98
        return $result;
1✔
99
    }
100

101
    /**
102
     * @return \MLocati\PayWay\Service\Level3Info\Product
103
     */
104
    protected function unserializeLevel3InfoProduct(DOMElement $node, Response $response)
105
    {
106
        $result = new Service\Level3Info\Product();
1✔
107
        foreach ($this->listDOMElements($node) as $child) {
1✔
108
            $tagName = $child->tagName;
1✔
109
            $setter = 'set' . ucfirst($tagName);
1✔
110
            $value = (string) $child->nodeValue;
1✔
111
            switch ($tagName) {
112
                case 'items':
1✔
113
                    $value = $this->unserializeInteger($value);
1✔
114
                    break;
1✔
115
                case 'amount':
1✔
116
                    $value = $this->unserializeInteger($value);
1✔
117
                    $setter .= 'AsCents';
1✔
118
                    break;
1✔
119
            }
120
            if (!method_exists($result, $setter)) {
1✔
121
                $response->addUnrecognizedXmlElement($child);
×
122
                continue;
×
123
            }
124
            $result->{$setter}($value);
1✔
125
        }
126

127
        return $result;
1✔
128
    }
129

130
    /**
131
     * @return string[]
132
     */
133
    protected function unserializeEntryAttribute(DOMElement $node, Response $response)
134
    {
135
        $result = ['', ''];
×
136
        foreach ($this->listDOMElements($node) as $child) {
×
137
            switch ($child->tagName) {
×
138
                case 'key':
×
139
                    $result[0] = (string) $child->nodeValue;
×
140
                    break;
×
141
                case 'value':
×
142
                    $result[1] = (string) $child->nodeValue;
×
143
                    break;
×
144
                default:
145
                    $response->addUnrecognizedXmlElement($child);
×
146
            }
147
        }
148

149
        return $result;
×
150
    }
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc