GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#81)
by
unknown
02:58
created

AbstractRequest::setOgoneUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of the Marlon Ogone package.
4
 *
5
 * (c) Marlon BVBA <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Ogone;
12
13
use InvalidArgumentException;
14
use RuntimeException;
15
use BadMethodCallException;
16
use Ogone\ShaComposer\ShaComposer;
17
18
abstract class AbstractRequest implements Request
19
{
20
    /** @var ShaComposer */
21
    protected $shaComposer;
22
23
    protected $ogoneUri;
24
25
    protected $parameters = array();
26
27
    /** Note this is public to allow easy modification, if need be. */
28
    public $allowedlanguages = array(
29
        'en_US' => 'English', 'cs_CZ' => 'Czech', 'de_DE' => 'German',
30
        'dk_DK' => 'Danish', 'el_GR' => 'Greek', 'es_ES' => 'Spanish',
31
        'fr_FR' => 'French', 'it_IT' => 'Italian', 'ja_JP' => 'Japanese',
32
        'nl_BE' => 'Flemish', 'nl_NL' => 'Dutch', 'no_NO' => 'Norwegian',
33
        'pl_PL' => 'Polish', 'pt_PT' => 'Portugese', 'ru_RU' => 'Russian',
34
        'se_SE' => 'Swedish', 'sk_SK' => 'Slovak', 'tr_TR' => 'Turkish'
35
    );
36
37
    protected $ogoneFields = array(
38
        'pspid', 'orderid', 'com', 'amount', 'currency', 'language', 'cn', 'email',
39
        'cardno', 'cvc', 'ed', 'ownerzip', 'owneraddress', 'ownercty', 'ownertown', 'ownertelno',
40
        'homeurl', 'catalogurl', 'accepturl', 'declineurl', 'exceptionurl', 'cancelurl', 'backurl',
41
        'complus', 'paramplus', 'pm', 'brand', 'title', 'bgcolor', 'txtcolor', 'tblbgcolor',
42
        'tbltxtcolor', 'buttonbgcolor', 'buttontxtcolor', 'logo', 'fonttype', 'tp', 'paramvar',
43
        'alias', 'aliasoperation', 'aliasusage', 'aliaspersistedafteruse', 'device', 'pmlisttype',
44
        'ecom_payment_card_verification', 'operation', 'withroot', 'remote_addr', 'rtimeout',
45
        // DirectLink with 3-D Secure: Extra request parameters.
46
        // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/directlink-3-d/3-d-transaction-flow-via-directlink#extrarequestparameters
47
        'flag3d', 'http_accept', 'http_user_agent', 'win3ds',
48
        // Optional integration data: Delivery and Invoicing data.
49
        // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/delivery-and-invoicing-data
50
        'civility', 'cuid', 'ecom_billto_postal_city', 'ecom_billto_postal_countrycode',
51
        'ecom_billto_postal_name_first', 'ecom_billto_postal_name_last', 'ecom_billto_postal_postalcode',
52
        'ecom_billto_postal_street_line1', 'ecom_billto_postal_street_number', 'ecom_shipto_dob',
53
        'ecom_shipto_online_email', 'ecom_shipto_postal_city', 'ecom_shipto_postal_countrycode',
54
        'ecom_shipto_postal_name_first', 'ecom_shipto_postal_name_last', 'ecom_shipto_postal_name_prefix',
55
        'ecom_shipto_postal_postalcode', 'ecom_shipto_postal_state', 'ecom_shipto_postal_street_line1',
56
        'ecom_shipto_postal_street_number', 'ordershipcost', 'ordershipmeth', 'ordershiptaxcode',
57
        // Optional integration data: Order data ("ITEM" parameters).
58
        // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/order-data
59
        'itemattributes*', 'itemcategory*', 'itemcomments*', 'itemdesc*', 'itemdiscount*',
60
        'itemid*', 'itemname*', 'itemprice*', 'itemquant*', 'itemquantorig*',
61
        'itemunitofmeasure*', 'itemvat*', 'itemvatcode*', 'itemweight*',
62
        // Optional integration data: Travel data.
63
        // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/additional-data/travel-data
64
        'datatype', 'aiairname', 'aitinum', 'aitidate', 'aiconjti', 'aipasname',
65
        'aiextrapasname*', 'aichdet', 'aiairtax', 'aivatamnt', 'aivatappl', 'aitypch',
66
        'aieycd', 'aiirst', 'aiorcity*', 'aiorcityl*', 'aidestcity*', 'aidestcityl*',
67
        'aistopov*', 'aicarrier*', 'aibookind*', 'aiflnum*', 'aifldate*', 'aiclass*',
68
        // Subscription Manager.
69
        // https://payment-services.ingenico.com/int/en/ogone/support/guides/integration%20guides/subscription-manager/via-e-commerce-and-directlink#input
70
        'subscription_id', 'sub_amount', 'sub_com', 'sub_orderid', 'sub_period_unit',
71
        'sub_period_number', 'sub_period_moment', 'sub_startdate', 'sub_enddate',
72
        'sub_status', 'sub_comment',
73
    );
74
75
    /** @return string */
76 4
    public function getShaSign()
77
    {
78 4
        return $this->shaComposer->compose($this->toArray());
79
    }
80
81
    /** @return string */
82 4
    public function getOgoneUri()
83
    {
84 4
        return $this->ogoneUri;
85
    }
86
87
    /** Ogone uri to send the customer to. Usually PaymentRequest::TEST or PaymentRequest::PRODUCTION */
88 15
    public function setOgoneUri($ogoneUri)
89
    {
90 15
        $this->validateOgoneUri($ogoneUri);
91 10
        $this->ogoneUri = $ogoneUri;
92 10
    }
93
94 25
    public function setPspid($pspid)
95
    {
96 25
        if (strlen($pspid) > 30) {
97 1
            throw new InvalidArgumentException("PSPId is too long");
98
        }
99 24
        $this->parameters['pspid'] = $pspid;
100 24
    }
101
102 6
    public function setSecure()
103
    {
104 6
      $this->parameters['win3ds'] = 'MAINW';
105 6
    }
106
107
    /**
108
     * ISO code eg nl_BE
109
     */
110 2
    public function setLanguage($language)
111
    {
112 2
        if (!array_key_exists($language, $this->allowedlanguages)) {
113 1
            throw new InvalidArgumentException("Invalid language ISO code");
114
        }
115 1
        $this->parameters['language'] = $language;
116 1
    }
117
118
    /** Alias for setCn */
119 6
    public function setCustomername($customername)
120
    {
121 6
        $this->setCn($customername);
122 6
    }
123
124 6
    public function setCn($cn)
125
    {
126 6
        $this->parameters['cn'] = str_replace(array("'", '"'), '', $cn); // replace quotes
127 6
    }
128
129
    public function setHomeurl($homeurl)
130
    {
131
        if (!empty($homeurl)) {
132
            $this->validateUri($homeurl);
133
        }
134
        $this->parameters['homeurl'] = $homeurl;
135
    }
136
137 6
    public function setAccepturl($accepturl)
138
    {
139 6
        $this->validateUri($accepturl);
140 5
        $this->parameters['accepturl'] = $accepturl;
141 5
    }
142
143 2
    public function setDeclineurl($declineurl)
144
    {
145 2
        $this->validateUri($declineurl);
146 1
        $this->parameters['declineurl'] = $declineurl;
147 1
    }
148
149 6
    public function setExceptionurl($exceptionurl)
150
    {
151 6
        $this->validateUri($exceptionurl);
152 5
        $this->parameters['exceptionurl'] = $exceptionurl;
153 5
    }
154
155 3
    public function setCancelurl($cancelurl)
156
    {
157 3
        $this->validateUri($cancelurl);
158 1
        $this->parameters['cancelurl'] = $cancelurl;
159 1
    }
160
161 1
    public function setBackurl($backurl)
162
    {
163 1
        $this->validateUri($backurl);
164 1
        $this->parameters['backurl'] = $backurl;
165 1
    }
166
167
    /** Alias for setParamplus */
168 1
    public function setFeedbackParams(array $feedbackParams)
169
    {
170 1
        $this->setParamplus($feedbackParams);
171 1
    }
172
173 1
    public function setParamplus(array $paramplus)
174
    {
175 1
        $this->parameters['paramplus'] = http_build_query($paramplus);
176 1
    }
177
178 25
    public function validate()
179
    {
180 25
        foreach ($this->getRequiredFields() as $field) {
181 25
            if (empty($this->parameters[$field])) {
182 6
                throw new RuntimeException("$field can not be empty");
183
            }
184 20
        }
185 19
    }
186
187 23 View Code Duplication
    protected function validateUri($uri)
0 ignored issues
show
Duplication introduced by
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...
188
    {
189 23
        if (!filter_var($uri, FILTER_VALIDATE_URL)) {
190 6
            throw new InvalidArgumentException("Uri is not valid");
191
        }
192 17
        if (strlen($uri) > 200) {
193 1
            throw new InvalidArgumentException("Uri is too long");
194
        }
195 16
    }
196
197 15
    protected function validateOgoneUri($uri)
198
    {
199 15
        $this->validateUri($uri);
200
201 14
        if (!in_array($uri, $this->getValidOgoneUris())) {
202 4
            throw new InvalidArgumentException('No valid Ogone url');
203
        }
204 10
    }
205
206
    /**
207
     * Allows setting ogone parameters that don't have a setter -- usually only
208
     * the unimportant ones like bgcolor, which you'd call with setBgcolor()
209
     *
210
     * @param $method
211
     * @param $args
212
     */
213 3
    public function __call($method, $args)
214
    {
215 3
        if (substr($method, 0, 3) == 'set') {
216 1
            $field = strtolower(substr($method, 3));
217
            // Also search for numbered fields, like ITEMID1, ITEMID2 etc.
218 1
            $numbered_field = preg_replace('/\d+$/', '*', $field);
219 1
            if (in_array($field, $this->ogoneFields) || in_array($numbered_field, $this->ogoneFields)) {
220 1
                $this->parameters[$field] = $args[0];
221 1
                return;
222
            }
223
        }
224
225 3
        if (substr($method, 0, 3) == 'get') {
226 3
            $field = strtolower(substr($method, 3));
227 3
            if (array_key_exists($field, $this->parameters)) {
228 2
                return $this->parameters[$field];
229
            }
230 1
        }
231
232 1
        throw new BadMethodCallException("Unknown method $method");
233
    }
234
235 4
    public function toArray()
236
    {
237 4
        $this->validate();
238 4
        return array_change_key_case($this->parameters, CASE_UPPER);
239
    }
240
}
241