Conditions | 1 |
Paths | 1 |
Total Lines | 4 |
Code Lines | 2 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Metric | Value |
---|---|
c | 1 |
b | 0 |
f | 0 |
dl | 0 |
loc | 4 |
rs | 10 |
cc | 1 |
eloc | 2 |
nc | 1 |
nop | 0 |
1 | <?php |
||
2 | |||
3 | namespace Omnipay\FirstAtlanticCommerce\Message; |
||
4 | |||
5 | use Alcohol\ISO3166; |
||
6 | use Omnipay\Common\Exception\InvalidRequestException; |
||
7 | use Omnipay\FirstAtlanticCommerce\Message\AbstractRequest; |
||
8 | |||
9 | /** |
||
10 | * FACPG2 Authorize Request |
||
11 | */ |
||
12 | class AuthorizeRequest extends AbstractRequest |
||
13 | { |
||
14 | /** |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
15 | * @var string; |
||
0 ignored issues
–
show
|
|||
16 | */ |
||
0 ignored issues
–
show
|
|||
17 | protected $requestName = 'AuthorizeRequest'; |
||
0 ignored issues
–
show
|
|||
18 | |||
19 | /** |
||
0 ignored issues
–
show
|
|||
20 | * Transaction code (flag as a authorization) |
||
0 ignored issues
–
show
|
|||
21 | * |
||
0 ignored issues
–
show
|
|||
22 | * @var int; |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
0 ignored issues
–
show
|
|||
24 | protected $transactionCode = 0; |
||
0 ignored issues
–
show
|
|||
25 | |||
26 | /** |
||
0 ignored issues
–
show
|
|||
27 | * Returns the signature for the request. |
||
0 ignored issues
–
show
|
|||
28 | * |
||
0 ignored issues
–
show
|
|||
29 | * @return string base64 encoded sha1 hash of the merchantPassword, merchantId, |
||
0 ignored issues
–
show
|
|||
30 | * acquirerId, transactionId, amount and currency code. |
||
0 ignored issues
–
show
|
|||
31 | */ |
||
0 ignored issues
–
show
|
|||
32 | protected function generateSignature() |
||
0 ignored issues
–
show
|
|||
33 | { |
||
0 ignored issues
–
show
|
|||
34 | $signature = $this->getMerchantPassword(); |
||
0 ignored issues
–
show
|
|||
35 | $signature .= $this->getMerchantId(); |
||
0 ignored issues
–
show
|
|||
36 | $signature .= $this->getAcquirerId(); |
||
0 ignored issues
–
show
|
|||
37 | $signature .= $this->getTransactionId(); |
||
0 ignored issues
–
show
|
|||
38 | $signature .= $this->formatAmount(); |
||
0 ignored issues
–
show
|
|||
39 | $signature .= $this->getCurrencyNumeric(); |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | return base64_encode( sha1($signature, true) ); |
||
0 ignored issues
–
show
|
|||
42 | } |
||
0 ignored issues
–
show
|
|||
43 | |||
44 | /** |
||
0 ignored issues
–
show
|
|||
45 | * Validate and construct the data for the request |
||
0 ignored issues
–
show
|
|||
46 | * |
||
0 ignored issues
–
show
|
|||
47 | * @return array |
||
0 ignored issues
–
show
|
|||
48 | */ |
||
0 ignored issues
–
show
|
|||
49 | public function getData() |
||
0 ignored issues
–
show
|
|||
50 | { |
||
0 ignored issues
–
show
|
|||
51 | $this->validate('merchantId', 'merchantPassword', 'acquirerId', 'transactionId', 'amount', 'currency', 'card'); |
||
0 ignored issues
–
show
|
|||
52 | |||
53 | // Check for AVS and require billingAddress1 and billingPostcode |
||
0 ignored issues
–
show
|
|||
54 | if ( $this->getRequireAvsCheck() ) |
||
0 ignored issues
–
show
|
|||
55 | { |
||
0 ignored issues
–
show
|
|||
56 | $this->getCard()->validate('billingAddress1', 'billingPostcode'); |
||
0 ignored issues
–
show
The call to
CreditCard::validate() has too many arguments starting with 'billingAddress1' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
57 | } |
||
0 ignored issues
–
show
|
|||
58 | |||
59 | // Tokenized cards require the CVV and nothing else, token replaces the card number |
||
0 ignored issues
–
show
|
|||
60 | if ( $this->getCardReference() ) |
||
0 ignored issues
–
show
|
|||
61 | { |
||
0 ignored issues
–
show
|
|||
62 | $this->validate('cardReference'); |
||
0 ignored issues
–
show
|
|||
63 | $this->getCard()->validate('cvv', 'expiryMonth', 'expiryYear'); |
||
0 ignored issues
–
show
The call to
CreditCard::validate() has too many arguments starting with 'cvv' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
64 | |||
65 | $cardDetails = [ |
||
0 ignored issues
–
show
|
|||
66 | 'CardCVV2' => $this->getCard()->getCvv(), |
||
0 ignored issues
–
show
|
|||
67 | 'CardExpiryDate' => $this->getCard()->getExpiryDate('my'), |
||
0 ignored issues
–
show
|
|||
68 | 'CardNumber' => $this->getCardReference() |
||
0 ignored issues
–
show
|
|||
69 | ]; |
||
0 ignored issues
–
show
|
|||
70 | } |
||
0 ignored issues
–
show
|
|||
71 | else |
||
0 ignored issues
–
show
|
|||
72 | { |
||
0 ignored issues
–
show
|
|||
73 | $this->getCard()->validate(); |
||
0 ignored issues
–
show
|
|||
74 | |||
75 | $cardDetails = [ |
||
0 ignored issues
–
show
|
|||
76 | 'CardCVV2' => $this->getCard()->getCvv(), |
||
0 ignored issues
–
show
|
|||
77 | 'CardExpiryDate' => $this->getCard()->getExpiryDate('my'), |
||
0 ignored issues
–
show
|
|||
78 | 'CardNumber' => $this->getCard()->getNumber(), |
||
0 ignored issues
–
show
|
|||
79 | 'IssueNumber' => $this->getCard()->getIssueNumber() |
||
0 ignored issues
–
show
|
|||
80 | ]; |
||
0 ignored issues
–
show
|
|||
81 | } |
||
0 ignored issues
–
show
|
|||
82 | |||
83 | // Only pass the StartDate if year/month are set otherwise it returns 1299 |
||
0 ignored issues
–
show
|
|||
84 | if ( $this->getCard()->getStartYear() && $this->getCard()->getStartMonth() ) |
||
0 ignored issues
–
show
|
|||
85 | { |
||
0 ignored issues
–
show
|
|||
86 | $cardDetails['StartDate'] = $this->getCard()->getStartDate('my'); |
||
0 ignored issues
–
show
|
|||
87 | } |
||
0 ignored issues
–
show
|
|||
88 | |||
89 | $transactionDetails = [ |
||
0 ignored issues
–
show
|
|||
90 | 'AcquirerId' => $this->getAcquirerId(), |
||
0 ignored issues
–
show
|
|||
91 | 'Amount' => $this->formatAmount(), |
||
0 ignored issues
–
show
|
|||
92 | 'Currency' => $this->getCurrencyNumeric(), |
||
0 ignored issues
–
show
|
|||
93 | 'CurrencyExponent' => $this->getCurrencyDecimalPlaces(), |
||
0 ignored issues
–
show
|
|||
94 | 'IPAddress' => $this->getClientIp(), |
||
0 ignored issues
–
show
|
|||
95 | 'MerchantId' => $this->getMerchantId(), |
||
0 ignored issues
–
show
|
|||
96 | 'OrderNumber' => $this->getTransactionId(), |
||
0 ignored issues
–
show
|
|||
97 | 'Signature' => $this->generateSignature(), |
||
0 ignored issues
–
show
|
|||
98 | 'SignatureMethod' => 'SHA1', |
||
0 ignored issues
–
show
|
|||
99 | 'TransactionCode' => $this->getTransactionCode() |
||
0 ignored issues
–
show
|
|||
100 | ]; |
||
0 ignored issues
–
show
|
|||
101 | |||
102 | $billingDetails = [ |
||
0 ignored issues
–
show
|
|||
103 | 'BillToAddress' => $this->getCard()->getAddress1(), |
||
0 ignored issues
–
show
|
|||
104 | 'BillToZipPostCode' => $this->formatPostcode(), |
||
0 ignored issues
–
show
|
|||
105 | 'BillToFirstName' => $this->getCard()->getFirstName(), |
||
0 ignored issues
–
show
|
|||
106 | 'BillToLastName' => $this->getCard()->getLastName(), |
||
0 ignored issues
–
show
|
|||
107 | 'BillToCity' => $this->getCard()->getCity(), |
||
0 ignored issues
–
show
|
|||
108 | 'BillToCountry' => $this->formatCountry(), |
||
0 ignored issues
–
show
|
|||
109 | 'BillToEmail' => $this->getCard()->getEmail(), |
||
0 ignored issues
–
show
|
|||
110 | 'BillToTelephone' => $this->getCard()->getPhone(), |
||
0 ignored issues
–
show
|
|||
111 | 'BillToFax' => $this->getCard()->getFax() |
||
0 ignored issues
–
show
|
|||
112 | ]; |
||
0 ignored issues
–
show
|
|||
113 | |||
114 | // FAC only accepts two digit state abbreviations from the USA |
||
0 ignored issues
–
show
|
|||
115 | if ( $billingDetails['BillToCountry'] == 840 ) |
||
0 ignored issues
–
show
|
|||
116 | { |
||
0 ignored issues
–
show
|
|||
117 | $billingDetails['BillToState'] = $this->formatState(); |
||
0 ignored issues
–
show
|
|||
118 | } |
||
0 ignored issues
–
show
|
|||
119 | |||
120 | $data = [ |
||
0 ignored issues
–
show
|
|||
121 | 'TransactionDetails' => $transactionDetails, |
||
0 ignored issues
–
show
|
|||
122 | 'CardDetails' => $cardDetails, |
||
0 ignored issues
–
show
|
|||
123 | 'BillingDetails' => $billingDetails |
||
0 ignored issues
–
show
|
|||
124 | ]; |
||
0 ignored issues
–
show
|
|||
125 | |||
126 | return $data; |
||
0 ignored issues
–
show
|
|||
127 | } |
||
0 ignored issues
–
show
|
|||
128 | |||
129 | /** |
||
0 ignored issues
–
show
|
|||
130 | * Returns the country as the numeric ISO 3166-1 code |
||
0 ignored issues
–
show
|
|||
131 | * |
||
0 ignored issues
–
show
|
|||
132 | * @throws Omnipay\Common\Exception\InvalidRequestException |
||
0 ignored issues
–
show
|
|||
133 | * |
||
0 ignored issues
–
show
|
|||
134 | * @return int ISO 3166-1 numeric country |
||
0 ignored issues
–
show
|
|||
135 | */ |
||
0 ignored issues
–
show
|
|||
136 | protected function formatCountry() |
||
0 ignored issues
–
show
|
|||
137 | { |
||
0 ignored issues
–
show
|
|||
138 | $country = $this->getCard()->getCountry(); |
||
0 ignored issues
–
show
|
|||
139 | |||
140 | if ( !is_null($country) && !is_numeric($country) ) |
||
0 ignored issues
–
show
|
|||
141 | { |
||
0 ignored issues
–
show
|
|||
142 | $iso3166 = new ISO3166; |
||
0 ignored issues
–
show
|
|||
143 | |||
144 | if ( strlen($country) == 2 ) |
||
0 ignored issues
–
show
|
|||
145 | { |
||
0 ignored issues
–
show
|
|||
146 | $country = $iso3166->getByAlpha2($country)['numeric']; |
||
0 ignored issues
–
show
|
|||
147 | } |
||
0 ignored issues
–
show
|
|||
148 | elseif ( strlen($country) == 3 ) |
||
0 ignored issues
–
show
|
|||
149 | { |
||
0 ignored issues
–
show
|
|||
150 | $country = $iso3166->getByAlpha3($country)['numeric']; |
||
0 ignored issues
–
show
|
|||
151 | } |
||
0 ignored issues
–
show
|
|||
152 | else |
||
0 ignored issues
–
show
|
|||
153 | { |
||
0 ignored issues
–
show
|
|||
154 | throw new InvalidRequestException("The country parameter must be ISO 3166-1 numeric, aplha2 or alpha3."); |
||
0 ignored issues
–
show
The string literal
The country parameter mu...eric, aplha2 or alpha3. does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
155 | } |
||
0 ignored issues
–
show
|
|||
156 | } |
||
0 ignored issues
–
show
|
|||
157 | |||
158 | return $country; |
||
0 ignored issues
–
show
|
|||
159 | } |
||
0 ignored issues
–
show
|
|||
160 | |||
161 | /** |
||
0 ignored issues
–
show
|
|||
162 | * Returns the billing state if its a US abbreviation or throws an exception |
||
0 ignored issues
–
show
|
|||
163 | * |
||
0 ignored issues
–
show
|
|||
164 | * @throws Omnipay\Common\Exception\InvalidRequestException |
||
0 ignored issues
–
show
|
|||
165 | * |
||
0 ignored issues
–
show
|
|||
166 | * @return string State abbreviation |
||
0 ignored issues
–
show
|
|||
167 | */ |
||
0 ignored issues
–
show
|
|||
168 | public function formatState() |
||
0 ignored issues
–
show
|
|||
169 | { |
||
0 ignored issues
–
show
|
|||
170 | $state = $this->getCard()->getState(); |
||
0 ignored issues
–
show
|
|||
171 | |||
172 | if ( strlen($state) != 2 ) |
||
0 ignored issues
–
show
|
|||
173 | { |
||
0 ignored issues
–
show
|
|||
174 | throw new InvalidRequestException("The state must be a two character abbreviation."); |
||
0 ignored issues
–
show
The string literal
The state must be a two character abbreviation. does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
175 | } |
||
0 ignored issues
–
show
|
|||
176 | |||
177 | return $state; |
||
0 ignored issues
–
show
|
|||
178 | } |
||
0 ignored issues
–
show
|
|||
179 | |||
180 | /** |
||
0 ignored issues
–
show
|
|||
181 | * Returns the postal code sanitizing dashes and spaces and throws exceptions with other |
||
0 ignored issues
–
show
|
|||
182 | * non-alphanumeric characters |
||
0 ignored issues
–
show
|
|||
183 | * |
||
0 ignored issues
–
show
|
|||
184 | * @throws Omnipay\Common\Exception\InvalidRequestException |
||
0 ignored issues
–
show
|
|||
185 | * |
||
0 ignored issues
–
show
|
|||
186 | * @return string Postal code |
||
0 ignored issues
–
show
|
|||
187 | */ |
||
0 ignored issues
–
show
|
|||
188 | public function formatPostcode() |
||
0 ignored issues
–
show
|
|||
189 | { |
||
0 ignored issues
–
show
|
|||
190 | $postal = preg_replace( '/[\s\-]/', '', $this->getCard()->getPostcode() ); |
||
0 ignored issues
–
show
|
|||
191 | |||
192 | if ( preg_match('/[^a-z0-9]/i', $postal) ) |
||
0 ignored issues
–
show
|
|||
193 | { |
||
0 ignored issues
–
show
|
|||
194 | throw new InvalidRequestException("The postal code must be alpha-numeric."); |
||
0 ignored issues
–
show
The string literal
The postal code must be alpha-numeric. does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
195 | } |
||
0 ignored issues
–
show
|
|||
196 | |||
197 | return $postal; |
||
0 ignored issues
–
show
|
|||
198 | } |
||
0 ignored issues
–
show
|
|||
199 | |||
200 | /** |
||
0 ignored issues
–
show
|
|||
201 | * Returns endpoint for authorize requests |
||
0 ignored issues
–
show
|
|||
202 | * |
||
0 ignored issues
–
show
|
|||
203 | * @return string Endpoint URL |
||
0 ignored issues
–
show
|
|||
204 | */ |
||
0 ignored issues
–
show
|
|||
205 | protected function getEndpoint() |
||
0 ignored issues
–
show
|
|||
206 | { |
||
0 ignored issues
–
show
|
|||
207 | return parent::getEndpoint() . 'Authorize'; |
||
0 ignored issues
–
show
|
|||
208 | } |
||
0 ignored issues
–
show
|
|||
209 | |||
210 | /** |
||
0 ignored issues
–
show
|
|||
211 | * Returns the transaction code based on the AVS check requirement |
||
0 ignored issues
–
show
|
|||
212 | * |
||
0 ignored issues
–
show
|
|||
213 | * @return int Transaction Code |
||
0 ignored issues
–
show
|
|||
214 | */ |
||
0 ignored issues
–
show
|
|||
215 | protected function getTransactionCode() |
||
0 ignored issues
–
show
|
|||
216 | { |
||
0 ignored issues
–
show
|
|||
217 | return $this->getRequireAvsCheck() ? $this->transactionCode + 1 : $this->transactionCode; |
||
0 ignored issues
–
show
|
|||
218 | } |
||
0 ignored issues
–
show
|
|||
219 | |||
220 | /** |
||
0 ignored issues
–
show
|
|||
221 | * Return the authorize response object |
||
0 ignored issues
–
show
|
|||
222 | * |
||
0 ignored issues
–
show
|
|||
223 | * @param \SimpleXMLElement $xml Response xml object |
||
0 ignored issues
–
show
|
|||
224 | * |
||
0 ignored issues
–
show
|
|||
225 | * @return AuthorizeResponse |
||
0 ignored issues
–
show
|
|||
226 | */ |
||
0 ignored issues
–
show
|
|||
227 | protected function newResponse($xml) |
||
0 ignored issues
–
show
|
|||
228 | { |
||
0 ignored issues
–
show
|
|||
229 | return new AuthorizeResponse($this, $xml); |
||
0 ignored issues
–
show
The return type of
return new \Omnipay\Firs...eResponse($this, $xml); (Omnipay\FirstAtlanticCom...ssage\AuthorizeResponse ) is incompatible with the return type declared by the abstract method Omnipay\FirstAtlanticCom...actRequest::newResponse of type Omnipay\FirstAtlanticCom...ssage\ResponseInterface .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
230 | } |
||
0 ignored issues
–
show
|
|||
231 | } |
||
232 |