Issues (4)

src/Response/DecryptResponse.php (1 issue)

Labels
Severity
1
<?php
2
3
/*
4
 * This file is part of the GestPayWS library.
5
 *
6
 * (c) Manuel Dalla Lana <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EndelWar\GestPayWS\Response;
13
14
/**
15
 * Class DecryptResponse
16
 */
17
class DecryptResponse extends Response
18
{
19
    protected $parametersName = [
20
        // Mandatory
21
        'TransactionType',
22
        'TransactionResult',
23
        'ShopTransactionID',
24
        'BankTransactionID',
25
        'AuthorizationCode',
26
        'Currency',
27
        'Amount',
28
        'ErrorCode',
29
        'ErrorDescription',
30
31
        // Optional
32
        'Country',
33
        'CustomInfo',
34
        'Buyer', // contains BuyerName and BuyerEmail
35
        'TDLevel',
36
        'AlertCode',
37
        'AlertDescription',
38
        'CVVPresent',
39
        'MaskedPAN',
40
        'PaymentMethod',
41
        'TOKEN',
42
        'ProductType',
43
        'TokenExpiryMonth',
44
        'TokenExpiryYear',
45
        'TransactionKey',
46
        'VbV',
47
        'VbVRisp',
48
        'VbVBuyer',
49
        'VbVFlag',
50
        'AVSResultCode',
51
        'AVSResultDescription',
52
        'RiskResponseCode',
53
        'RiskResponseDescription'
54
    ];
55
    protected $separator = '*P1*';
56
57
    /**
58
     * @param \stdClass $soapResponse
59
     * @throws \Exception
60
     */
61
    public function __construct($soapResponse)
62
    {
63
        $xml = simplexml_load_string($soapResponse->DecryptResult->any);
64
        if (isset($xml->CustomInfo)) {
65
            $xml->CustomInfo = urldecode($xml->CustomInfo);
66
        }
67
        parent::__construct($xml);
0 ignored issues
show
It seems like $xml can also be of type false; however, parameter $xml of EndelWar\GestPayWS\Respo...Response::__construct() does only seem to accept SimpleXMLElement, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        parent::__construct(/** @scrutinizer ignore-type */ $xml);
Loading history...
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public function getCustomInfoToArray()
74
    {
75
        $allinfo = explode($this->separator, $this->data['CustomInfo']);
76
        $customInfoArray = [];
77
        foreach ($allinfo as $singleInfo) {
78
            $tagvalue = explode('=', $singleInfo);
79
            $customInfoArray[$tagvalue[0]] = urldecode($tagvalue[1]);
80
        }
81
82
        return $customInfoArray;
83
    }
84
}
85