Issues (42)

Security Analysis    not enabled

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/onepay/PaymentGateway.php (4 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
 * @link https://github.com/yiiviet/yii2-payment
4
 * @copyright Copyright (c) 2017 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\payment\onepay;
9
10
use GatewayClients\DataInterface;
11
12
use yiiviet\payment\BasePaymentGateway;
13
14
/**
15
 * Lớp PaymentGateway thực thi các phương thức trừu tượng dùng hổ trợ kết nối đến OnePay.
16
 * Hiện tại nó hổ trợ 100% các tính năng từ cổng thanh toán OnePay v2.
17
 *
18
 * @method ResponseData purchase(array $data, $clientId = null)
19
 * @method ResponseData queryDR(array $data, $clientId = null)
20
 * @method bool|VerifiedData verifyRequestIPN($clientId = null, \yii\web\Request $request = null)
21
 * @method bool|VerifiedData verifyRequestPurchaseSuccess($clientId = null, \yii\web\Request $request = null)
22
 * @method PaymentClient getClient($id = null)
23
 * @method PaymentClient getDefaultClient()
24
 *
25
 * @property PaymentClient $client
26
 * @property PaymentClient $defaultClient
27
 *
28
 * @author Vuong Minh <[email protected]>
29
 * @since 1.0
30
 */
31
class PaymentGateway extends BasePaymentGateway
32
{
33
    /**
34
     * Đường dẫn API của thanh toán nội địa.
35
     */
36
    const PURCHASE_DOMESTIC_URL = '/onecomm-pay/vpc.op';
37
38
    /**
39
     * Đường dẫn API để truy vấn thông tin giao dịch nội địa.
40
     */
41
    const QUERY_DR_DOMESTIC_URL = '/onecomm-pay/Vpcdps.op';
42
43
    /**
44
     * Đường dẫn API của thanh toán quốc tế.
45
     */
46
    const PURCHASE_INTERNATIONAL_URL = '/vpcpay/vpcpay.op';
47
48
    /**
49
     * Đường dẫn API để truy vấn thông tin giao dịch quốc tế.
50
     */
51
    const QUERY_DR_INTERNATIONAL_URL = '/vpcpay/Vpcdps.op';
52
53
    /**
54
     * Id của client trong môi trường thử nghiệm dùng để giao tiếp với OnePay ở cổng quốc tế.
55
     */
56
    const ID_CLIENT_SANDBOX_INTERNATIONAL = '__sandboxInternational';
57
58
    /**
59
     * Id của client trong môi trường thử nghiệm dùng để giao tiếp với OnePay ở cổng nội địa.
60
     */
61
    const ID_CLIENT_SANDBOX_DOMESTIC = '__sandboxDomestic';
62
63
    /**
64
     * @var bool Optional to use international gateway. Set to TRUE if you want use methods (requests, verifies) with international mode.
65
     */
66
    public $international = false;
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public $clientConfig = ['class' => PaymentClient::class];
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public $requestDataConfig = ['class' => RequestData::class];
77
78
    /**
79
     * @inheritdoc
80
     */
81
    public $responseDataConfig = ['class' => ResponseData::class];
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public $verifiedDataConfig = ['class' => VerifiedData::class];
87
88
    /**
89
     * @inheritdoc
90
     */
91 4
    public function getBaseUrl(): string
92
    {
93 4
        return $this->sandbox ? 'https://mtf.onepay.vn' : 'https://onepay.vn';
94
    }
95
96
    /**
97
     * @inheritdoc
98
     * @since 1.0.3
99
     */
100 4
    public function requestCommands(): array
101
    {
102 4
        return [self::RC_PURCHASE, self::RC_QUERY_DR];
103
    }
104
105
    /**
106
     * @return ResponseData|DataInterface
107
     * @inheritdoc
108
     */
109 4 View Code Duplication
    public function request($command, array $data, $clientId = null): DataInterface
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111 4
        if ($clientId === null && $this->sandbox) {
112 4
            $clientId = $this->international ? self::ID_CLIENT_SANDBOX_INTERNATIONAL : self::ID_CLIENT_SANDBOX_DOMESTIC;
113
        }
114
115 4
        return parent::request($command, $data, $clientId);
116
    }
117
118
    /**
119
     * @return bool|VerifiedData
120
     * @inheritdoc
121
     */
122 4 View Code Duplication
    public function verifyRequest($command, \yii\web\Request $request = null, $clientId = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124 4
        if ($clientId === null && $this->sandbox) {
125 4
            $clientId = $this->international ? self::ID_CLIENT_SANDBOX_INTERNATIONAL : self::ID_CLIENT_SANDBOX_DOMESTIC;
126
        }
127
128 4
        return parent::verifyRequest($command, $request, $clientId);
129
    }
130
131
    /**
132
     * @inheritdoc
133
     */
134 4
    protected function defaultVersion(): string
135
    {
136 4
        return '2';
137
    }
138
139
    /**
140
     * @inheritdoc
141
     * @throws \yii\base\InvalidConfigException
142
     */
143 9
    protected function initSandboxEnvironment()
144
    {
145 9
        $clientDomesticConfig = require(__DIR__ . '/sandbox-client-domestic.php');
146 9
        $clientInternationalConfig = require(__DIR__ . '/sandbox-client-international.php');
147
148 9
        $this->setClient(static::ID_CLIENT_SANDBOX_DOMESTIC, $clientDomesticConfig);
149 9
        $this->setClient(static::ID_CLIENT_SANDBOX_INTERNATIONAL, $clientInternationalConfig);
150 9
    }
151
152
    /**
153
     * @inheritdoc
154
     * @throws \yii\base\InvalidConfigException|\yii\httpclient\Exception
155
     */
156 4
    protected function requestInternal(\vxm\gatewayclients\RequestData $requestData, \yii\httpclient\Client $httpClient): array
157
    {
158 4
        $command = $requestData->getCommand();
159
        $commandUrls = [
160 4
            self::RC_PURCHASE => $this->international ? self::PURCHASE_INTERNATIONAL_URL : self::PURCHASE_DOMESTIC_URL,
161 4
            self::RC_QUERY_DR => $this->international ? self::QUERY_DR_INTERNATIONAL_URL : self::QUERY_DR_DOMESTIC_URL,
162
        ];
163
164 4
        $data = $requestData->get();
165 4
        $data[0] = $commandUrls[$command];
166
167 4 View Code Duplication
        if ($command === self::RC_PURCHASE) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168 2
            return ['redirect_url' => $httpClient->createRequest()->setUrl($data)->getFullUrl()];
169
        } else {
170 2
            return $httpClient->get($data)->send()->getData();
171
        }
172
    }
173
174
    /**
175
     * @inheritdoc
176
     */
177 4 View Code Duplication
    protected function getVerifyRequestData($command, \yii\web\Request $request): array
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
178
    {
179 4
        $data = [];
180
181 4
        foreach ($request->get() as $param => $value) {
182
            if (strpos($param, 'vpc_') === 0) {
183
                $data[$param] = $value;
184
            }
185
        }
186
187 4
        return $data;
188
    }
189
190
}
191