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

mlocati / PayWay / 5272005549

pending completion
5272005549

Pull #4

github

web-flow
Merge d20a1048f into ada68d889
Pull Request #4: Multiple fixes

51 of 51 new or added lines in 8 files covered. (100.0%)

1603 of 2134 relevant lines covered (75.12%)

1.54 hits per line

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

59.18
/src/Service/BaseResponseTrait.php
1
<?php
2

3
namespace MLocati\PayWay\Service;
4

5
use DateTime;
6
use DateTimeInterface;
7
use DOMElement;
8
use MLocati\PayWay\Exception;
9
use ValueError;
10

11
trait BaseResponseTrait
12
{
13
    use JsonCleanupTrait;
14

15
    /**
16
     * @var string
17
     */
18
    private $tid = '';
19

20
    /**
21
     * @var string
22
     */
23
    private $payInstr = '';
24

25
    /**
26
     * @var \DateTimeInterface|null
27
     */
28
    private $reqTime;
29

30
    /**
31
     * @var string
32
     */
33
    private $rc = '';
34

35
    /**
36
     * @var bool
37
     */
38
    private $error = false;
39

40
    /**
41
     * @var string
42
     */
43
    private $errorDesc = '';
44

45
    /**
46
     * @var string
47
     */
48
    private $signature = '';
49

50
    /**
51
     * @var string[]
52
     */
53
    private $unrecognizedXmlElements = [];
54

55
    /**
56
     * @return string
57
     */
58
    public function getTid()
59
    {
60
        return $this->tid;
2✔
61
    }
62

63
    /**
64
     * @param string $value
65
     *
66
     * @return $this
67
     */
68
    public function setTid($value)
69
    {
70
        $this->tid = (string) $value;
4✔
71

72
        return $this;
4✔
73
    }
74

75
    /**
76
     * @return string
77
     */
78
    public function getPayInstr()
79
    {
80
        return $this->payInstr;
2✔
81
    }
82

83
    /**
84
     * @param string $value
85
     *
86
     * @return $this
87
     */
88
    public function setPayInstr($value)
89
    {
90
        $this->payInstr = (string) $value;
1✔
91

92
        return $this;
1✔
93
    }
94

95
    /**
96
     * @return $this
97
     */
98
    public function getReqTime()
99
    {
100
        return $this->reqTime;
2✔
101
    }
102

103
    /**
104
     * @return $this
105
     */
106
    public function setReqTime(DateTimeInterface $value = null)
107
    {
108
        $this->reqTime = $value;
×
109

110
        return $this;
×
111
    }
112

113
    /**
114
     * @return string
115
     */
116
    public function getRc()
117
    {
118
        return $this->rc;
2✔
119
    }
120

121
    /**
122
     * @param string $value
123
     *
124
     * @return $this
125
     */
126
    public function setRc($value)
127
    {
128
        $this->rc = (string) $value;
4✔
129

130
        return $this;
4✔
131
    }
132

133
    /**
134
     * @return bool
135
     */
136
    public function isError()
137
    {
138
        return $this->error;
2✔
139
    }
140

141
    /**
142
     * @param bool $value
143
     *
144
     * @return $this
145
     */
146
    public function setError($value)
147
    {
148
        $this->error = (bool) $value;
4✔
149

150
        return $this;
4✔
151
    }
152

153
    /**
154
     * @return string
155
     */
156
    public function getErrorDesc()
157
    {
158
        return $this->errorDesc;
2✔
159
    }
160

161
    /**
162
     * @param string $value
163
     *
164
     * @return $this
165
     */
166
    public function setErrorDesc($value)
167
    {
168
        $this->errorDesc = (string) $value;
4✔
169

170
        return $this;
4✔
171
    }
172

173
    /**
174
     * @return string
175
     */
176
    public function getSignature()
177
    {
178
        return $this->signature;
2✔
179
    }
180

181
    /**
182
     * @param string $value
183
     *
184
     * @return $this
185
     */
186
    public function setSignature($value)
187
    {
188
        $this->signature = (string) $value;
4✔
189

190
        return $this;
4✔
191
    }
192

193
    /**
194
     * @return string[]
195
     */
196
    public function getUnrecognizedXmlElements()
197
    {
198
        return $this->unrecognizedXmlElements;
×
199
    }
200

201
    /**
202
     * @param string[]|\DOMElement[] $value
203
     *
204
     * @return $this
205
     */
206
    public function setUnrecognizedXmlElements(array $value)
207
    {
208
        $this->unrecognizedXmlElements = [];
×
209
        foreach ($value as $item) {
×
210
            $this->addUnrecognizedXmlElement($item);
×
211
        }
212

213
        return $this;
×
214
    }
215

216
    /**
217
     * @param string|\DOMElement $value
218
     *
219
     * @return $this
220
     */
221
    public function addUnrecognizedXmlElement($value)
222
    {
223
        if ($value instanceof DOMElement) {
×
224
            $value = $value->ownerDocument->saveXML($value);
×
225
        }
226
        $this->unrecognizedXmlElements[] = $value;
×
227

228
        return $this;
×
229
    }
230

231
    /**
232
     * Check the HMAC-SHA256 signature.
233
     *
234
     * @param string $key
235
     *
236
     * @throws \MLocati\PayWay\Exception\InvalidSignature
237
     */
238
    public function checkSignature($key)
239
    {
240
        $data = implode('', $this->getSignatureFields());
×
241
        try {
242
            $expectedRawSignature = hash_hmac('sha256', $data, $key, true);
×
243
        } catch (ValueError $x) {
×
244
            throw new Exception\UnableToCreateSignature($x->getMessage());
×
245
        }
246
        if ($expectedRawSignature === false) {
×
247
            throw new Exception\UnableToCreateSignature();
×
248
        }
249
        $expectedSignature = base64_encode($expectedRawSignature);
×
250
        if ($this->signature !== $expectedSignature) {
×
251
            throw new Exception\InvalidSignature($expectedSignature, $this->signature);
×
252
        }
253
    }
254

255
    /**
256
     * {@inheritdoc}
257
     *
258
     * @see \JsonSerializable::jsonSerialize()
259
     */
260
    #[\ReturnTypeWillChange]
261
    public function jsonSerialize()
262
    {
263
        return $this->cleanupJson([
4✔
264
            'tid' => $this->tid,
4✔
265
            'payInstr' => $this->payInstr,
4✔
266
            'reqTime' => $this->reqTime === null ? '' : $this->reqTime->format(DateTime::RFC3339),
4✔
267
            'rc' => $this->rc,
4✔
268
            'error' => $this->error,
4✔
269
            'errorDesc' => $this->errorDesc,
4✔
270
            'signature' => $this->signature,
4✔
271
            '_unrecognizedXmlElements' => $this->unrecognizedXmlElements,
4✔
272
        ]);
4✔
273
    }
274

275
    /**
276
     * @return string[]
277
     *
278
     * @private
279
     */
280
    abstract protected function getSignatureFields();
281
}
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

© 2025 Coveralls, Inc