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/vtcpay/PaymentGateway.php (1 issue)

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
9
namespace yiiviet\payment\vtcpay;
10
11
use GatewayClients\DataInterface;
12
13
use yii\base\NotSupportedException;
14
use yii\httpclient\Client as HttpClient;
15
16
use yiiviet\payment\BasePaymentGateway;
17
18
/**
19
 * 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 VTCPay.
20
 * Hiện tại nó hổ trợ 100% các tính năng từ cổng thanh toán VTCPay.
21
 *
22
 * @method ResponseData purchase(array $data, $clientId = null)
23
 * @method VerifiedData verifyRequestIPN(\yii\web\Request $request = null, $clientId = null)
24
 * @method VerifiedData verifyRequestPurchaseSuccess(\yii\web\Request $request = null, $clientId = null)
25
 * @method PaymentClient getClient($id = null)
26
 * @method PaymentClient getDefaultClient()
27
 *
28
 * @author Vuong Minh <[email protected]>
29
 * @since 1.0.2
30
 */
31
class PaymentGateway extends BasePaymentGateway
32
{
33
34
    /**
35
     * Đường dẫn API để yêu cầu tạo giao dịch thanh toán.
36
     */
37
    const PURCHASE_URL = '/checkout.html';
38
39
    /**
40
     * Phương thức thanh toán bằng ví điện tử VTCPay.
41
     */
42
    const PAYMENT_METHOD_VTCPAY = 'VTCPay';
43
44
    /**
45
     * Phương thức thanh toán bằng ngân hàng trong nước.
46
     */
47
    const PAYMENT_METHOD_DOMESTIC_BANK = 'DomesticBank';
48
49
    /**
50
     * Phương thức thanh toán bằng thẻ quốc tế (visa/master).
51
     */
52
    const PAYMENT_METHOD_INTERNATIONAL_CARD = 'InternationalCard';
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public $clientConfig = ['class' => PaymentClient::class];
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public $requestDataConfig = ['class' => RequestData::class];
63
64
    /**
65
     * @inheritdoc
66
     */
67
    public $responseDataConfig = ['class' => ResponseData::class];
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public $verifiedDataConfig = ['class' => VerifiedData::class];
73
74
    /**
75
     * @inheritdoc
76
     */
77 2
    public function getBaseUrl(): string
78
    {
79 2
        return $this->sandbox ? 'http://alpha1.vtcpay.vn/portalgateway' : 'https://vtcpay.vn/bank-gateway';
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 3
    public function requestCommands(): array
86
    {
87 3
        return [self::RC_PURCHASE];
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93 13
    protected function initSandboxEnvironment()
94
    {
95 13
        $clientConfig = require(__DIR__ . '/sandbox-client.php');
96 13
        $this->setClient($clientConfig);
97 13
    }
98
99
    /**
100
     * @inheritdoc
101
     * @throws NotSupportedException
102
     */
103 1
    public function queryDR(array $data, $clientId = null): DataInterface
104
    {
105 1
        throw new NotSupportedException('queryDR doesnt\'t supported in VTCPay!');
106
    }
107
108
    /**
109
     * @inheritdoc
110
     * @throws \yii\base\InvalidConfigException
111
     */
112 2
    protected function requestInternal(\vxm\gatewayclients\RequestData $requestData, HttpClient $httpClient): array
113
    {
114 2
        $data = $requestData->get();
115 1
        $data[0] = self::PURCHASE_URL;
116
117 1
        return ['redirect_url' => $httpClient->createRequest()->setUrl($data)->getFullUrl()];
118
    }
119
120
    /**
121
     * @param int|string $command
122
     * @param \yii\web\Request $request
123
     * @return array
124
     */
125 5
    protected function getVerifyRequestData($command, \yii\web\Request $request): array
126
    {
127 5
        if ($command === self::VRC_IPN) {
128 4
            $params = ['data', 'signature'];
129 4
            $requestMethod = 'post';
130
        } else {
131 1
            $params = ['amount', 'message', 'payment_type', 'reference_number', 'status', 'trans_ref_no', 'website_id', 'signature'];
132 1
            $requestMethod = 'get';
133
        }
134
135 5
        $data = [];
136
137 5 View Code Duplication
        foreach ($params as $param) {
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...
138 5
            if (($value = call_user_func([$request, $requestMethod], $param)) !== null) {
139 5
                $data[$param] = $value;
140
            }
141
        }
142
143 5
        return $data;
144
    }
145
146
}
147