1 | <?php |
||
2 | |||
3 | namespace Omnipay\Moneris\Message; |
||
4 | |||
5 | use Omnipay\Common\Exception\InvalidRequestException; |
||
6 | |||
7 | abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest |
||
8 | { |
||
9 | const MAIL_ORDER_TELEPHONE_ORDER_SINGLE = 1; |
||
10 | const MAIL_ORDER_TELEPHONE_ORDER_RECURRING = 2; |
||
11 | const MAIL_ORDER_TELEPHONE_ORDER_INSTALMENT = 3; |
||
12 | const MAIL_ORDER_TELEPHONE_ORDER_UNKNOWN_CLASSIFICATION = 4; |
||
13 | const AUTHENTICATED_E_COMMERCE_TRANSACTION_VBV = 5; |
||
14 | const NON_AUTHENTICATED_E_COMMERCE_TRANSACTION_VBV = 6; |
||
15 | const SSL_ENABLED_MERCHANT = 7; |
||
16 | |||
17 | /** |
||
18 | * Allowable values for the e-commerce transaction category being processed. |
||
19 | * |
||
20 | * @var array |
||
21 | * @link https://developer.moneris.com/en/Documentation/NA/E-Commerce%20Solutions/API/Purchase |
||
22 | */ |
||
23 | const ECOMMERCE_INDICATORS = [ |
||
24 | self::MAIL_ORDER_TELEPHONE_ORDER_SINGLE, |
||
25 | self::MAIL_ORDER_TELEPHONE_ORDER_RECURRING, |
||
26 | self::MAIL_ORDER_TELEPHONE_ORDER_INSTALMENT, |
||
27 | self::MAIL_ORDER_TELEPHONE_ORDER_UNKNOWN_CLASSIFICATION, |
||
28 | self::AUTHENTICATED_E_COMMERCE_TRANSACTION_VBV, |
||
29 | self::NON_AUTHENTICATED_E_COMMERCE_TRANSACTION_VBV, |
||
30 | self::SSL_ENABLED_MERCHANT, |
||
31 | ]; |
||
32 | |||
33 | public $testEndpoint = 'https://esqa.moneris.com:443/gateway2/servlet/MpgRequest'; |
||
34 | public $liveEndpoint = 'https://www3.moneris.com:443/gateway2/servlet/MpgRequest'; |
||
35 | |||
36 | 45 | public function getEndpoint() |
|
37 | { |
||
38 | 45 | return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
|
39 | } |
||
40 | |||
41 | 72 | public function getMerchantId() |
|
42 | { |
||
43 | 72 | return $this->getParameter('merchantId'); |
|
44 | } |
||
45 | |||
46 | 90 | public function setMerchantId($value) |
|
47 | { |
||
48 | 90 | return $this->setParameter('merchantId', $value); |
|
49 | } |
||
50 | |||
51 | 72 | public function getMerchantKey() |
|
52 | { |
||
53 | 72 | return $this->getParameter('merchantKey'); |
|
54 | } |
||
55 | |||
56 | 90 | public function setMerchantKey($value) |
|
57 | { |
||
58 | 90 | return $this->setParameter('merchantKey', $value); |
|
59 | } |
||
60 | |||
61 | 66 | public function getCryptType() |
|
62 | { |
||
63 | 66 | return $this->getParameter('cryptType'); |
|
64 | } |
||
65 | |||
66 | 123 | public function setCryptType($value) |
|
67 | { |
||
68 | 123 | return $this->setParameter('cryptType', $value); |
|
69 | } |
||
70 | |||
71 | 30 | public function getPaymentMethod() |
|
72 | { |
||
73 | 30 | return $this->getParameter('paymentMethod'); |
|
74 | } |
||
75 | |||
76 | 48 | public function setPaymentMethod($value) |
|
77 | { |
||
78 | 48 | return $this->setParameter('paymentMethod', $value); |
|
79 | } |
||
80 | |||
81 | 3 | public function getPaymentProfile() |
|
82 | { |
||
83 | 3 | return $this->getParameter('paymentProfile'); |
|
84 | } |
||
85 | |||
86 | 3 | public function setPaymentProfile($value) |
|
87 | { |
||
88 | 3 | return $this->setParameter('paymentProfile', $value); |
|
89 | } |
||
90 | |||
91 | 21 | public function getOrderNumber() |
|
92 | { |
||
93 | 21 | return $this->getParameter('orderNumber'); |
|
94 | } |
||
95 | |||
96 | 51 | public function setOrderNumber($value) |
|
97 | { |
||
98 | 51 | return $this->setParameter('orderNumber', $value); |
|
99 | } |
||
100 | |||
101 | 45 | protected function getHttpMethod() |
|
102 | { |
||
103 | 45 | return 'POST'; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Validate the request. |
||
108 | * |
||
109 | * @param string ... a variable length list of required parameters |
||
110 | * @throws InvalidRequestException |
||
111 | * @see Omnipay\Common\ParametersTrait::validate() |
||
112 | */ |
||
113 | 87 | public function validate(...$args) |
|
114 | { |
||
115 | 87 | foreach ($args as $key) { |
|
116 | 87 | $value = $this->parameters->get($key); |
|
117 | |||
118 | switch ($key) { |
||
119 | 87 | case 'orderNumber': |
|
120 | 48 | if (! isset($value)) { |
|
121 | 3 | throw new InvalidRequestException("The $key parameter is required"); |
|
122 | } elseif (empty($value)) { |
||
123 | 3 | throw new InvalidRequestException("The $key parameter cannot be empty"); |
|
124 | 42 | } elseif (strlen($value) > 50) { |
|
125 | throw new InvalidRequestException("The $key parameter cannot be longer than 50 characters"); |
||
126 | } |
||
127 | 42 | break; |
|
128 | |||
129 | 87 | case 'cryptType': |
|
130 | 33 | if (! isset($value)) { |
|
131 | 3 | throw new InvalidRequestException("The $key parameter is required"); |
|
132 | 30 | } elseif (! in_array($value, self::ECOMMERCE_INDICATORS)) { |
|
133 | 3 | throw new InvalidRequestException("The $key is invalid"); |
|
134 | } |
||
135 | 27 | break; |
|
136 | |||
137 | 87 | case 'description': |
|
138 | 24 | if (isset($value) && strlen($value) > 20) { |
|
139 | 3 | throw new InvalidRequestException("The $key parameter cannot be longer than 20 characters"); |
|
140 | } |
||
141 | 21 | break; |
|
142 | |||
143 | default: |
||
144 | 87 | if (! isset($value)) { |
|
145 | 12 | throw new InvalidRequestException("The $key parameter is required"); |
|
146 | } |
||
147 | 84 | break; |
|
148 | } |
||
149 | } |
||
150 | 66 | } |
|
151 | |||
152 | 45 | public function sendData($data) |
|
153 | { |
||
154 | $headers = [ |
||
155 | 45 | 'Content-Type' => 'application/xml', |
|
156 | ]; |
||
157 | |||
158 | 45 | $httpResponse = $this->httpClient->request($this->getHttpMethod(), $this->getEndpoint(), $headers, $data); |
|
159 | |||
160 | try { |
||
161 | 45 | $xmlResponse = simplexml_load_string($httpResponse->getBody()->getContents()); |
|
162 | 3 | } catch (\Exception $e) { |
|
163 | 3 | $xmlResponse = (string) $httpResponse->getBody(true); |
|
0 ignored issues
–
show
|
|||
164 | } |
||
165 | |||
166 | 45 | return $this->response = new Response($this, $xmlResponse); |
|
167 | } |
||
168 | } |
||
169 |
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. Please note the @ignore annotation hint above.