Issues (14)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Gateway.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay;
6
7
use DOMElement;
8
use DOMDocument;
9
use GuzzleHttp\Client as Http;
10
use Illuminate\Support\Collection;
11
use Symfony\Component\Serializer\Serializer;
12
use AcquiroPay\Gateway\Responses\InitResponse;
13
use Symfony\Component\Serializer\Encoder\XmlEncoder;
14
use AcquiroPay\Gateway\Responses\PaymentStatusByCfResponse;
15
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
16
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
17
18
class Gateway
19
{
20
    private const LIVE_URL = 'https://gateway.acquiropay.com';
21
    private const TEST_URL = 'https://gateway.acqp.co';
22
23
    protected $http;
24
    protected $url;
25
26
    protected $merchantId;
27
    protected $secretWord;
28
29
    protected $request;
30
31
    public function __construct(
32
        Http $http,
33
        int $merchantId = null,
0 ignored issues
show
The parameter $merchantId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
        string $secretWord = null,
0 ignored issues
show
The parameter $secretWord is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
        bool $live = false
0 ignored issues
show
The parameter $live is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    ) {
37
        $this->http = $http;
38
    }
39
40
    public function setUrl(string $url): self
41
    {
42
        $this->url = $url;
43
44
        return $this;
45
    }
46
47
    public function setMerchantId(int $merchantId): self
48
    {
49
        $this->merchantId = $merchantId;
50
51
        return $this;
52
    }
53
54
    public function setSecretWord(string $secretWord): self
55
    {
56
        $this->secretWord = $secretWord;
57
58
        return $this;
59
    }
60
61
    public function setLive(bool $live): self
62
    {
63
        $this->url = $live ? self::LIVE_URL : self::TEST_URL;
64
65
        return $this;
66
    }
67
68
    /**
69
     * Init payment.
70
     *
71
     * @param int $productId
72
     * @param string $pan
73
     * @param string $cardHolder
74
     * @param int $expiryMonth
75
     * @param int $expiryYear
76
     * @param string $cvv
77
     * @param string $cf
78
     * @param float|string $amount
79
     * @param array $parameters
80
     *
81
     * @return InitResponse
82
     */
83
    public function init(
84
        int $productId,
85
        string $pan,
86
        string $cardHolder,
87
        int $expiryMonth,
88
        int $expiryYear,
89
        string $cvv,
90
        string $cf,
91
        float $amount,
92
        array $parameters = []
93
    ): InitResponse {
94
        $amount = $this->formatAmount($amount);
95
96
        $parameters = array_merge($parameters, [
97
            'opcode' => 0,
98
            'product_id' => $productId,
99
            'amount' => $amount,
100
            'cf' => $cf,
101
            'pan' => $pan,
102
            'cvv' => $cvv,
103
            'exp_month' => $expiryMonth,
104
            'exp_year' => $expiryYear,
105
            'cardholder' => $cardHolder,
106
            'token' => md5(
107
                $this->merchantId.
108
                $productId.
109
                $amount.
110
                $cf.
111
                array_get($parameters, 'cf2').
112
                array_get($parameters, 'cf3').
113
                $this->secretWord
114
            ),
115
        ]);
116
117
        $response = $this->send($parameters);
118
119
        return $this->deserialize($response, InitResponse::class);
120
    }
121
122
    /**
123
     * Get payment status using cf.
124
     *
125
     * @param int $productId
126
     * @param string $cf
127
     *
128
     * @return Collection|PaymentStatusByCfResponse[]
129
     */
130
    public function paymentStatusByCf(int $productId, string $cf)
131
    {
132
        $parameters = [
133
            'opcode' => 2,
134
            'product_id' => $productId,
135
            'cf' => $cf,
136
            'token' => md5($this->merchantId.$productId.$cf.$this->secretWord),
137
        ];
138
139
        $response = $this->send($parameters);
140
141
        $xml = new DOMDocument;
142
        $xml->formatOutput = true;
143
        $xml->loadXML($response);
144
145
        // один платеж
146
        if ($xml->getElementsByTagName('payments')->length === 0) {
147
            return collect([$this->deserialize($response, PaymentStatusByCfResponse::class)]);
148
        }
149
150
        $payments = collect();
151
        $elements = $xml->getElementsByTagName('payments')->item(0)->getElementsByTagName('payment');
152
153
        /** @var DOMElement $element */
154
        foreach ($elements as $element) {
155
            $payments->push($this->deserialize($xml->saveXML($element), PaymentStatusByCfResponse::class));
156
        }
157
158
        return $payments;
159
    }
160
161
    public function getRequest(): ?array
162
    {
163
        return $this->request;
164
    }
165
166
    private function send(array $parameters): string
167
    {
168
        $this->request = $parameters;
169
170
        $response = $this->http->post($this->url, ['form_params' => $parameters, 'verify' => false]);
171
172
        return (string) $response->getBody();
173
    }
174
175
    private function deserialize(string $data, string $class)
176
    {
177
        $normalizers = [new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter)];
178
        $encoders = [new XmlEncoder];
179
180
        return (new Serializer($normalizers, $encoders))->deserialize($data, $class, 'xml');
181
    }
182
183
    private function formatAmount(float $amount): string
184
    {
185
        return number_format($amount, 2, '.', '');
186
    }
187
}
188