Issues (150)

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.

code/checkout/PaymentProcessor.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
 * PaymentProcessor.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 24/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use SS_Object;
12
use Payment;
13
use SilverStripe\Omnipay\Exception\Exception;
14
use SilverStripe\Omnipay\GatewayInfo;
15
use SilverStripe\Omnipay\Service\ServiceFactory;
16
use SilverStripe\Omnipay\Service\ServiceResponse;
17
18
/**
19
 * Class PaymentProcessor
20
 *
21
 * @package Broarm\EventTickets
22
 */
23
class PaymentProcessor extends SS_Object
24
{
25
    /**
26
     * @config
27
     * @var string
28
     */
29
    private static $currency = 'EUR';
30
31
    /**
32
     * @var Reservation
33
     */
34
    protected $reservation;
35
36
    /**
37
     * @var Payment
38
     */
39
    protected $payment;
40
41
    /**
42
     * @var array
43
     */
44
    protected $gatewayData = array(
45
        'transactionId' => null,
46
        'firstName' => null,
47
        'lastName' => null,
48
        'email' => null,
49
        'company' => null,
50
        'billingAddress1' => null,
51
        'billingAddress2' => null,
52
        'billingCity' => null,
53
        'billingPostcode' => null,
54
        'billingState' => null,
55
        'billingCountry' => null,
56
        'billingPhone' => null,
57
        'shippingAddress1' => null,
58
        'shippingAddress2' => null,
59
        'shippingCity' => null,
60
        'shippingPostcode' => null,
61
        'shippingState' => null,
62
        'shippingCountry' => null,
63
        'shippingPhone' => null,
64
        'description' => null
65
    );
66
67
    /**
68
     * PaymentProcessor constructor.
69
     *
70
     * @param Reservation $reservation
71
     */
72
    public function __construct(Reservation $reservation)
73
    {
74
        $this->reservation = $reservation;
75
        $this->setGatewayData(array(
76
            'transactionId' => $reservation->Status,
77
            'firstName' => $reservation->MainContact()->FirstName,
0 ignored issues
show
The property FirstName does not exist on object<Broarm\EventTickets\Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
78
            'lastName' => $reservation->MainContact()->Surname,
0 ignored issues
show
The property Surname does not exist on object<Broarm\EventTickets\Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
79
            'email' => $reservation->MainContact()->Email,
0 ignored issues
show
The property Email does not exist on object<Broarm\EventTickets\Attendee>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
80
            'description' => $reservation->ReservationCode
81
        ));
82
83
        parent::__construct();
84
        $this->extend('updatePaymentProcessor');
85
    }
86
87
    /**
88
     * Create a payment trough the given payment gateway
89
     *
90
     * @param string $gateway
91
     *
92
     * @return Payment
93
     */
94
    public function createPayment($gateway)
95
    {
96
        if (!GatewayInfo::isSupported($gateway)) {
97
            user_error(_t(
98
                "PaymentProcessor.INVALID_GATEWAY",
99
                "`{gateway}` is not supported.",
100
                null,
101
                array('gateway' => (string)$gateway)
0 ignored issues
show
array('gateway' => (string) $gateway) is of type array<string,string,{"gateway":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
            ), E_USER_ERROR);
103
        }
104
105
        // Create a payment
106
        $this->payment = Payment::create()->init(
107
            $gateway,
108
            $this->reservation->Total,
109
            self::config()->get('currency')
110
        );
111
112
        // Set a reference to the reservation
113
        $this->payment->ReservationID = $this->reservation->ID;
114
115
        return $this->payment;
116
    }
117
118
    /**
119
     * Create the service factory
120
     * Catch any exceptions that might occur
121
     *
122
     * @return null|ServiceResponse
123
     */
124
    public function createServiceFactory()
125
    {
126
        $factory = ServiceFactory::create();
127
        $service = $factory->getService($this->payment, ServiceFactory::INTENT_PAYMENT);
128
129
        try {
130
            $serviceResponse = $service->initiate($this->getGatewayData());
131
        } catch (Exception $ex) {
132
            // error out when an exception occurs
133
            user_error($ex->getMessage(), E_USER_WARNING);
134
            return null;
135
        }
136
137
        return $serviceResponse;
138
    }
139
140
    /**
141
     * Set and merges the gateway data
142
     *
143
     * @param array $data
144
     */
145
    public function setGatewayData($data = array())
146
    {
147
        $this->gatewayData = array_merge($this->gatewayData, $data);
148
    }
149
150
    /**
151
     * Get the gateway data
152
     *
153
     * @return array
154
     */
155
    public function getGateWayData()
156
    {
157
        return $this->gatewayData;
158
    }
159
160
    /**
161
     * Get the reservation
162
     *
163
     * @return Reservation
164
     */
165
    public function getReservation()
166
    {
167
        return $this->reservation;
168
    }
169
}
170