This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace zaporylie\Vipps\Api; |
||
4 | |||
5 | use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException; |
||
6 | use zaporylie\Vipps\Model\Payment\CustomerInfo; |
||
7 | use zaporylie\Vipps\Model\Payment\MerchantInfo; |
||
8 | use zaporylie\Vipps\Model\Payment\RequestCancelPayment; |
||
9 | use zaporylie\Vipps\Model\Payment\RequestCapturePayment; |
||
10 | use zaporylie\Vipps\Model\Payment\RequestInitiatePayment; |
||
11 | use zaporylie\Vipps\Model\Payment\RequestRefundPayment; |
||
12 | use zaporylie\Vipps\Model\Payment\Transaction; |
||
13 | use zaporylie\Vipps\Resource\Payment\CancelPayment; |
||
14 | use zaporylie\Vipps\Resource\Payment\CapturePayment; |
||
15 | use zaporylie\Vipps\Resource\Payment\GetOrderStatus; |
||
16 | use zaporylie\Vipps\Resource\Payment\GetPaymentDetails; |
||
17 | use zaporylie\Vipps\Resource\Payment\InitiatePayment; |
||
18 | use zaporylie\Vipps\Resource\Payment\RefundPayment; |
||
19 | use zaporylie\Vipps\VippsInterface; |
||
20 | |||
21 | /** |
||
22 | * Class Payment |
||
23 | * |
||
24 | * @package Vipps\Api |
||
25 | */ |
||
26 | class Payment extends ApiBase implements PaymentInterface |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $merchantSerialNumber; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $customPath; |
||
38 | |||
39 | /** |
||
40 | * Gets merchantSerialNumber value. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getMerchantSerialNumber() |
||
45 | { |
||
46 | if (empty($this->merchantSerialNumber)) { |
||
47 | throw new InvalidArgumentException('Missing merchant serial number'); |
||
48 | } |
||
49 | return $this->merchantSerialNumber; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getCustomPath() |
||
56 | { |
||
57 | return $this->customPath; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Payment constructor. |
||
62 | * |
||
63 | * Payments API needs one extra param - merchant serial number. |
||
64 | * |
||
65 | * @param \zaporylie\Vipps\VippsInterface $app |
||
66 | * @param string $subscription_key |
||
67 | * @param $merchant_serial_number |
||
68 | * @param $custom_path |
||
69 | */ |
||
70 | public function __construct( |
||
71 | VippsInterface $app, |
||
72 | $subscription_key, |
||
73 | $merchant_serial_number, |
||
74 | $custom_path = 'ecomm' |
||
75 | ) { |
||
76 | parent::__construct($app, $subscription_key); |
||
77 | $this->merchantSerialNumber = $merchant_serial_number; |
||
78 | $this->customPath = $custom_path; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function cancelPayment($order_id, $text) |
||
85 | { |
||
86 | // Build request object from data passed to method. |
||
87 | $request = (new RequestCancelPayment()) |
||
88 | ->setMerchantInfo( |
||
89 | (new MerchantInfo()) |
||
90 | ->setMerchantSerialNumber($this->getMerchantSerialNumber()) |
||
91 | ) |
||
92 | ->setTransaction( |
||
93 | (new Transaction()) |
||
94 | ->setTransactionText($text) |
||
95 | ); |
||
96 | $resource = new CancelPayment($this->app, $this->getSubscriptionKey(), $order_id, $request); |
||
97 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
98 | /** @var \zaporylie\Vipps\Model\Payment\ResponseCancelPayment $response */ |
||
99 | $response = $resource->call(); |
||
100 | return $response; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | View Code Duplication | public function capturePayment($order_id, $text, $amount = 0) |
|
0 ignored issues
–
show
|
|||
107 | { |
||
108 | // Build request object from data passed to method. |
||
109 | $request = (new RequestCapturePayment()) |
||
110 | ->setMerchantInfo( |
||
111 | (new MerchantInfo()) |
||
112 | ->setMerchantSerialNumber($this->getMerchantSerialNumber()) |
||
113 | ) |
||
114 | ->setTransaction( |
||
115 | (new Transaction()) |
||
116 | ->setTransactionText($text) |
||
117 | ); |
||
118 | // If amount is 0 (default) all remaining founds will be captured. |
||
119 | if ($amount !== 0) { |
||
120 | $request->getTransaction()->setAmount($amount); |
||
121 | } |
||
122 | $resource = new CapturePayment($this->app, $this->getSubscriptionKey(), $order_id, $request); |
||
123 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
124 | /** @var \zaporylie\Vipps\Model\Payment\ResponseCapturePayment $response */ |
||
125 | $response = $resource->call(); |
||
126 | return $response; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | View Code Duplication | public function getOrderStatus($order_id) |
|
0 ignored issues
–
show
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. ![]() |
|||
133 | { |
||
134 | // Get order status. |
||
135 | // this is GET request so no need to create request object. |
||
136 | $resource = new GetOrderStatus( |
||
137 | $this->app, |
||
138 | $this->getSubscriptionKey(), |
||
139 | $order_id |
||
140 | ); |
||
141 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
142 | /** @var \zaporylie\Vipps\Model\Payment\ResponseGetOrderStatus $response */ |
||
143 | $response = $resource->call(); |
||
144 | return $response; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | View Code Duplication | public function getPaymentDetails($order_id) |
|
0 ignored issues
–
show
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. ![]() |
|||
151 | { |
||
152 | // Get payment details. |
||
153 | // this is GET request so no need to create request object. |
||
154 | $resource = new GetPaymentDetails( |
||
155 | $this->app, |
||
156 | $this->getSubscriptionKey(), |
||
157 | $order_id |
||
158 | ); |
||
159 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
160 | /** @var \zaporylie\Vipps\Model\Payment\ResponseGetPaymentDetails $response */ |
||
161 | $response = $resource->call(); |
||
162 | return $response; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function initiatePayment( |
||
169 | $order_id, |
||
170 | $amount, |
||
171 | $text, |
||
172 | $callbackPrefix, |
||
173 | $fallback, |
||
174 | $options = [] |
||
175 | ) { |
||
176 | // Create Request object based on data passed to this method. |
||
177 | $request = (new RequestInitiatePayment()) |
||
178 | ->setCustomerInfo( |
||
179 | (new CustomerInfo()) |
||
180 | ) |
||
181 | ->setMerchantInfo( |
||
182 | (new MerchantInfo()) |
||
183 | ->setCallbackPrefix($callbackPrefix) |
||
184 | ->setFallBack($fallback) |
||
185 | ->setMerchantSerialNumber($this->getMerchantSerialNumber()) |
||
186 | ) |
||
187 | ->setTransaction( |
||
188 | (new Transaction()) |
||
189 | ->setTransactionText($text) |
||
190 | ->setAmount($amount) |
||
191 | ->setOrderId($order_id) |
||
192 | ); |
||
193 | |||
194 | // Set optional values. |
||
195 | foreach ($options as $option => $value) { |
||
196 | switch ($option) { |
||
197 | case 'mobileNumber': |
||
198 | $request->getCustomerInfo()->setMobileNumber($value); |
||
199 | break; |
||
200 | case 'authToken': |
||
201 | $request->getMerchantInfo()->setAuthToken($value); |
||
202 | break; |
||
203 | case 'consentRemovalPrefix': |
||
204 | $request->getMerchantInfo()->setConsentRemovalPrefix($value); |
||
205 | break; |
||
206 | case 'isApp': |
||
207 | $request->getMerchantInfo()->setIsApp($value); |
||
208 | break; |
||
209 | case 'paymentType': |
||
210 | $request->getMerchantInfo()->setPaymentType($value); |
||
211 | break; |
||
212 | case 'shippingDetailsPrefix': |
||
213 | $request->getMerchantInfo()->setShippingDetailsPrefix($value); |
||
214 | break; |
||
215 | case 'refOrderId': |
||
216 | $request->getTransaction()->setRefOrderId($value); |
||
217 | break; |
||
218 | case 'timeStamp': |
||
219 | $request->getTransaction()->setTimeStamp($value); |
||
220 | break; |
||
221 | } |
||
222 | } |
||
223 | // Pass request object along with all data required by InitiatePayment |
||
224 | // to make a call. |
||
225 | $resource = new InitiatePayment($this->app, $this->getSubscriptionKey(), $request); |
||
226 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
227 | /** @var \zaporylie\Vipps\Model\Payment\ResponseInitiatePayment $response */ |
||
228 | $response = $resource->call(); |
||
229 | return $response; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * {@inheritdoc} |
||
234 | */ |
||
235 | View Code Duplication | public function refundPayment($order_id, $text, $amount = 0) |
|
0 ignored issues
–
show
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. ![]() |
|||
236 | { |
||
237 | // Prepare request object based on data passed to method. |
||
238 | $request = (new RequestRefundPayment()) |
||
239 | ->setMerchantInfo( |
||
240 | (new MerchantInfo()) |
||
241 | ->setMerchantSerialNumber($this->getMerchantSerialNumber()) |
||
242 | ) |
||
243 | ->setTransaction( |
||
244 | (new Transaction()) |
||
245 | ->setTransactionText($text) |
||
246 | ); |
||
247 | |||
248 | // If amount is 0 all remaining founds will be refunded. |
||
249 | if ($amount !== 0) { |
||
250 | $request->getTransaction()->setAmount($amount); |
||
251 | } |
||
252 | // Create a resource. |
||
253 | $resource = new RefundPayment($this->app, $this->getSubscriptionKey(), $order_id, $request); |
||
254 | $resource->setPath(str_replace('ecomm', $this->customPath, $resource->getPath())); |
||
255 | /** @var \zaporylie\Vipps\Model\Payment\ResponseRefundPayment $response */ |
||
256 | $response = $resource->call(); |
||
257 | return $response; |
||
258 | } |
||
259 | } |
||
260 |
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.