1 | <?php |
||||
2 | /** |
||||
3 | * Integration |
||||
4 | * |
||||
5 | * @author Pronamic <[email protected]> |
||||
6 | * @copyright 2005-2020 Pronamic |
||||
7 | * @license GPL-3.0-or-later |
||||
8 | * @package Pronamic\WordPress\Pay\Gateways\Adyen |
||||
9 | */ |
||||
10 | |||||
11 | namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
||||
12 | |||||
13 | use Pronamic\WordPress\Pay\Dependencies\PhpExtensionDependency; |
||||
14 | use Pronamic\WordPress\Pay\AbstractGatewayIntegration; |
||||
15 | use Pronamic\WordPress\Pay\Util as Pay_Util; |
||||
16 | |||||
17 | /** |
||||
18 | * Integration |
||||
19 | * |
||||
20 | * @author Remco Tolsma |
||||
21 | * @version 1.0.5 |
||||
22 | * @since 1.0.0 |
||||
23 | */ |
||||
24 | class Integration extends AbstractGatewayIntegration { |
||||
25 | /** |
||||
26 | * REST route namespace. |
||||
27 | * |
||||
28 | * @var string |
||||
29 | */ |
||||
30 | const REST_ROUTE_NAMESPACE = 'pronamic-pay/adyen/v1'; |
||||
31 | |||||
32 | /** |
||||
33 | * Construct Adyen integration. |
||||
34 | * |
||||
35 | * @param array $args Arguments. |
||||
36 | */ |
||||
37 | 5 | public function __construct( $args = array() ) { |
|||
38 | 5 | $args = wp_parse_args( |
|||
39 | 5 | $args, |
|||
40 | array( |
||||
41 | 5 | 'id' => 'adyen', |
|||
42 | 5 | 'name' => 'Adyen', |
|||
43 | 5 | 'provider' => 'adyen', |
|||
44 | 5 | 'url' => \__( 'https://www.adyen.com/', 'pronamic_ideal' ), |
|||
45 | 5 | 'product_url' => \__( 'https://www.adyen.com/pricing', 'pronamic_ideal' ), |
|||
46 | 'dashboard_url' => array( |
||||
47 | 5 | \__( 'test', 'pronamic_ideal' ) => 'https://ca-test.adyen.com/ca/ca/login.shtml', |
|||
48 | 5 | \__( 'live', 'pronamic_ideal' ) => 'https://ca-live.adyen.com/ca/ca/login.shtml', |
|||
49 | ), |
||||
50 | 5 | 'manual_url' => \__( 'https://www.pronamic.eu/manuals/using-adyen-pronamic-pay/', 'pronamic_ideal' ), |
|||
51 | 'supports' => array( |
||||
52 | 'webhook', |
||||
53 | 'webhook_log', |
||||
54 | ), |
||||
55 | ) |
||||
56 | ); |
||||
57 | |||||
58 | 5 | parent::__construct( $args ); |
|||
59 | |||||
60 | // Dependencies. |
||||
61 | 5 | $dependencies = $this->get_dependencies(); |
|||
62 | |||||
63 | 5 | $dependencies->add( new PhpExtensionDependency( 'intl' ) ); |
|||
64 | 5 | } |
|||
65 | |||||
66 | /** |
||||
67 | * Setup gateway integration. |
||||
68 | * |
||||
69 | * @return void |
||||
70 | */ |
||||
71 | 1 | public function setup() { |
|||
72 | // Check if dependencies are met and integration is active. |
||||
73 | 1 | if ( ! $this->is_active() ) { |
|||
74 | return; |
||||
75 | } |
||||
76 | |||||
77 | // Notifications controller. |
||||
78 | 1 | $notifications_controller = new NotificationsController(); |
|||
79 | |||||
80 | 1 | $notifications_controller->setup(); |
|||
81 | |||||
82 | // Payments controller. |
||||
83 | 1 | $payments_controller = new PaymentsController(); |
|||
84 | |||||
85 | 1 | $payments_controller->setup(); |
|||
86 | |||||
87 | // Payments result controller. |
||||
88 | 1 | $payments_result_controller = new PaymentsResultController(); |
|||
89 | |||||
90 | 1 | $payments_result_controller->setup(); |
|||
91 | |||||
92 | // Site Health controller. |
||||
93 | 1 | $site_healht_controller = new SiteHealthController(); |
|||
94 | |||||
95 | 1 | $site_healht_controller->setup(); |
|||
96 | |||||
97 | // Settings. |
||||
98 | 1 | add_action( 'init', array( $this, 'init' ) ); |
|||
99 | 1 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
|||
100 | |||||
101 | // Actions. |
||||
102 | 1 | add_action( 'current_screen', array( $this, 'maybe_download_certificate_or_key' ) ); |
|||
103 | 1 | } |
|||
104 | |||||
105 | /** |
||||
106 | * Initialize. |
||||
107 | * |
||||
108 | * @return void |
||||
109 | */ |
||||
110 | 1 | public function init() { |
|||
111 | /* |
||||
112 | * Authentication - User Name |
||||
113 | */ |
||||
114 | 1 | register_setting( |
|||
115 | 1 | 'pronamic_pay', |
|||
116 | 1 | 'pronamic_pay_adyen_notification_authentication_username', |
|||
117 | array( |
||||
118 | 1 | 'type' => 'string', |
|||
119 | 'sanitize_callback' => 'sanitize_text_field', |
||||
120 | ) |
||||
121 | ); |
||||
122 | |||||
123 | /* |
||||
124 | * Authentication - Password |
||||
125 | */ |
||||
126 | 1 | register_setting( |
|||
127 | 1 | 'pronamic_pay', |
|||
128 | 1 | 'pronamic_pay_adyen_notification_authentication_password', |
|||
129 | array( |
||||
130 | 1 | 'type' => 'string', |
|||
131 | 'sanitize_callback' => 'sanitize_text_field', |
||||
132 | ) |
||||
133 | ); |
||||
134 | 1 | } |
|||
135 | |||||
136 | /** |
||||
137 | * Admin initialize. |
||||
138 | * |
||||
139 | * @return void |
||||
140 | */ |
||||
141 | 1 | public function admin_init() { |
|||
142 | 1 | add_settings_section( |
|||
143 | 1 | 'pronamic_pay_adyen_notification_authentication', |
|||
144 | /* translators: Translate 'notification' the same as in the Adyen dashboard. */ |
||||
145 | 1 | _x( 'Adyen Notification Authentication', 'Adyen', 'pronamic_ideal' ), |
|||
146 | 1 | array( $this, 'settings_section_notification_authentication' ), |
|||
147 | 1 | 'pronamic_pay' |
|||
148 | ); |
||||
149 | |||||
150 | 1 | add_settings_field( |
|||
151 | 1 | 'pronamic_pay_adyen_notification_authentication_username', |
|||
152 | 1 | __( 'User Name', 'pronamic_ideal' ), |
|||
153 | 1 | array( __CLASS__, 'input_element' ), |
|||
154 | 1 | 'pronamic_pay', |
|||
155 | 1 | 'pronamic_pay_adyen_notification_authentication', |
|||
156 | array( |
||||
157 | 1 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_username', |
|||
158 | ) |
||||
159 | ); |
||||
160 | |||||
161 | 1 | add_settings_field( |
|||
162 | 1 | 'pronamic_pay_adyen_notification_authentication_password', |
|||
163 | 1 | __( 'Password', 'pronamic_ideal' ), |
|||
164 | 1 | array( __CLASS__, 'input_element' ), |
|||
165 | 1 | 'pronamic_pay', |
|||
166 | 1 | 'pronamic_pay_adyen_notification_authentication', |
|||
167 | array( |
||||
168 | 1 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_password', |
|||
169 | ) |
||||
170 | ); |
||||
171 | 1 | } |
|||
172 | |||||
173 | /** |
||||
174 | * Settings section notification authentication. |
||||
175 | * |
||||
176 | * @return void |
||||
177 | */ |
||||
178 | 1 | public function settings_section_notification_authentication() { |
|||
179 | 1 | printf( |
|||
180 | 1 | '<p>%s</p>', |
|||
181 | 1 | esc_html__( |
|||
182 | 1 | 'Set the user name and password below and in the webhook authentication settings in the Adyen dashboard for increased security (recommended).', |
|||
183 | 1 | 'pronamic_ideal' |
|||
184 | ) |
||||
185 | ); |
||||
186 | 1 | } |
|||
187 | |||||
188 | /** |
||||
189 | * Input text. |
||||
190 | * |
||||
191 | * @param array<string,string> $args Arguments. |
||||
192 | * @return void |
||||
193 | */ |
||||
194 | 1 | public static function input_element( $args ) { |
|||
195 | 1 | $name = $args['label_for']; |
|||
196 | |||||
197 | 1 | $value = get_option( $name ); |
|||
198 | 1 | $value = strval( $value ); |
|||
199 | |||||
200 | 1 | printf( |
|||
201 | 1 | '<input name="%s" id="%s" value="%s" type="text" class="regular-text" />', |
|||
202 | 1 | esc_attr( $name ), |
|||
203 | 1 | esc_attr( $name ), |
|||
204 | 1 | esc_attr( $value ) |
|||
205 | ); |
||||
206 | 1 | } |
|||
207 | |||||
208 | /** |
||||
209 | * Get settings fields. |
||||
210 | * |
||||
211 | * @return array<int, array<string, int|string|bool|array<int,string>>> |
||||
212 | */ |
||||
213 | 1 | public function get_settings_fields() { |
|||
214 | 1 | $fields = array(); |
|||
215 | |||||
216 | // Merchant Account. |
||||
217 | 1 | $fields[] = array( |
|||
218 | 1 | 'section' => 'general', |
|||
219 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|||
220 | 1 | 'meta_key' => '_pronamic_gateway_adyen_merchant_account', |
|||
221 | 1 | 'title' => _x( 'Merchant Account', 'adyen', 'pronamic_ideal' ), |
|||
222 | 1 | 'type' => 'text', |
|||
223 | 'classes' => array( 'regular-text', 'code' ), |
||||
224 | 1 | 'tooltip' => __( 'The merchant account identifier, with which you want to process the transaction.', 'pronamic_ideal' ), |
|||
225 | ); |
||||
226 | |||||
227 | // API Key. |
||||
228 | 1 | $fields[] = array( |
|||
229 | 1 | 'section' => 'general', |
|||
230 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|||
231 | 1 | 'meta_key' => '_pronamic_gateway_adyen_api_key', |
|||
232 | 1 | 'title' => _x( 'API Key', 'adyen', 'pronamic_ideal' ), |
|||
233 | 1 | 'type' => 'textarea', |
|||
234 | 'classes' => array( 'code' ), |
||||
235 | 1 | 'tooltip' => __( 'API key as mentioned in the payment provider dashboard.', 'pronamic_ideal' ), |
|||
236 | 1 | 'description' => sprintf( |
|||
237 | 1 | '<a href="%s" target="_blank">%s</a>', |
|||
238 | 1 | esc_url( 'https://docs.adyen.com/developers/user-management/how-to-get-the-api-key' ), |
|||
239 | 1 | esc_html__( 'Adyen documentation: "How to get the API key".', 'pronamic_ideal' ) |
|||
240 | ), |
||||
241 | ); |
||||
242 | |||||
243 | // Live API URL prefix. |
||||
244 | 1 | $fields[] = array( |
|||
245 | 1 | 'section' => 'general', |
|||
246 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|||
247 | 1 | 'meta_key' => '_pronamic_gateway_adyen_api_live_url_prefix', |
|||
248 | 1 | 'title' => _x( 'API Live URL Prefix', 'adyen', 'pronamic_ideal' ), |
|||
249 | 1 | 'type' => 'text', |
|||
250 | 'classes' => array( 'regular-text', 'code' ), |
||||
251 | 1 | 'tooltip' => __( 'The unique prefix for the live API URL, as mentioned at <strong>Account » API URLs</strong> in the Adyen dashboard.', 'pronamic_ideal' ), |
|||
252 | 1 | 'description' => sprintf( |
|||
253 | 1 | '<a href="%s" target="_blank">%s</a>', |
|||
254 | 1 | esc_url( 'https://docs.adyen.com/developers/development-resources/live-endpoints#liveurlprefix' ), |
|||
255 | 1 | esc_html__( 'Adyen documentation: "Live URL prefix".', 'pronamic_ideal' ) |
|||
256 | ), |
||||
257 | ); |
||||
258 | |||||
259 | // Origin Key. |
||||
260 | 1 | $fields[] = array( |
|||
261 | 1 | 'section' => 'general', |
|||
262 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|||
263 | 1 | 'meta_key' => '_pronamic_gateway_adyen_origin_key', |
|||
264 | 1 | 'title' => _x( 'Origin Key', 'adyen', 'pronamic_ideal' ), |
|||
265 | 1 | 'type' => 'text', |
|||
266 | 'classes' => array( |
||||
267 | 'regular-text', |
||||
268 | 'code', |
||||
269 | 'pronamic-pay-form-control-lg', |
||||
270 | ), |
||||
271 | 1 | 'tooltip' => __( 'An origin key is a client-side key that is used to validate Adyen\'s JavaScript component library. It is required for the Drop-in and Component integrations.', 'pronamic_ideal' ), |
|||
272 | 1 | 'description' => sprintf( |
|||
273 | 1 | '<a href="%s" target="_blank">%s</a>', |
|||
274 | 1 | esc_url( 'https://docs.adyen.com/user-management/how-to-get-an-origin-key' ), |
|||
275 | 1 | esc_html__( 'Adyen documentation: "How to get an origin key".', 'pronamic_ideal' ) |
|||
276 | ), |
||||
277 | ); |
||||
278 | |||||
279 | // Apple Pay - Merchant identifier. |
||||
280 | 1 | $fields[] = array( |
|||
281 | 1 | 'section' => 'advanced', |
|||
282 | 'filter' => \FILTER_SANITIZE_STRING, |
||||
283 | 1 | 'meta_key' => '_pronamic_gateway_adyen_apple_pay_merchant_id', |
|||
284 | 1 | 'title' => _x( 'Apple Pay Merchant ID', 'adyen', 'pronamic_ideal' ), |
|||
285 | 1 | 'type' => 'text', |
|||
286 | 'classes' => array( 'regular-text', 'code' ), |
||||
287 | 1 | 'tooltip' => __( 'Your Apple Pay Merchant ID. Required for accepting live payments.', 'pronamic_ideal' ), |
|||
288 | 1 | 'description' => sprintf( |
|||
289 | 1 | '<a href="%s" target="_blank">%s</a><br /><a href="%s" target="_blank">%s</a>', |
|||
290 | 1 | esc_url( 'https://docs.adyen.com/payment-methods/apple-pay/web-drop-in#before-you-begin' ), |
|||
291 | 1 | esc_html__( 'Adyen documentation: "Apple Pay Drop-in - Before you begin".', 'pronamic_ideal' ), |
|||
292 | 1 | esc_url( 'https://developer.apple.com/documentation/apple_pay_on_the_web/configuring_your_environment' ), |
|||
293 | 1 | esc_html__( 'Apple documentation: "Configuring your environment".', 'pronamic_ideal' ) |
|||
294 | ), |
||||
295 | ); |
||||
296 | |||||
297 | // Apple Pay - Merchant Identity PKCS#12. |
||||
298 | 1 | $fields[] = array( |
|||
299 | 1 | 'section' => 'advanced', |
|||
300 | 'filter' => \FILTER_SANITIZE_STRING, |
||||
301 | 1 | 'meta_key' => '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', |
|||
302 | 1 | 'title' => __( 'Apple Pay Merchant Identity Certificate', 'pronamic_ideal' ), |
|||
303 | 1 | 'type' => 'textarea', |
|||
304 | 1 | 'callback' => array( $this, 'field_certificate' ), |
|||
305 | 'classes' => array( 'code' ), |
||||
306 | 1 | 'tooltip' => __( 'The Apple Pay Merchant Identity certificate required for secure communication with Apple.', 'pronamic_ideal' ), |
|||
307 | 1 | 'description' => sprintf( |
|||
308 | 1 | '<a href="%s" target="_blank">%s</a>', |
|||
309 | 1 | esc_url( 'https://docs.adyen.com/payment-methods/apple-pay/enable-apple-pay#create-merchant-identity-certificate' ), |
|||
310 | 1 | esc_html__( 'Adyen documentation: "Enable Apple Pay - Create a merchant identity certificate".', 'pronamic_ideal' ) |
|||
311 | ), |
||||
312 | ); |
||||
313 | |||||
314 | // Apple Pay - Merchant Identity private key. |
||||
315 | 1 | $fields[] = array( |
|||
316 | 1 | 'section' => 'advanced', |
|||
317 | 'filter' => \FILTER_SANITIZE_STRING, |
||||
318 | 1 | 'meta_key' => '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key', |
|||
319 | 1 | 'title' => __( 'Apple Pay Merchant Identity Private Key', 'pronamic_ideal' ), |
|||
320 | 1 | 'type' => 'textarea', |
|||
321 | 1 | 'callback' => array( $this, 'field_private_key' ), |
|||
322 | 'classes' => array( 'code' ), |
||||
323 | 1 | 'tooltip' => __( 'The private key of the Apple Pay Merchant Identity certificate for secure communication with Apple.', 'pronamic_ideal' ), |
|||
324 | ); |
||||
325 | |||||
326 | // Apple Pay - Merchant Identity certificate private key password. |
||||
327 | 1 | $fields[] = array( |
|||
328 | 1 | 'section' => 'advanced', |
|||
329 | 'filter' => \FILTER_SANITIZE_STRING, |
||||
330 | 1 | 'meta_key' => '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key_password', |
|||
331 | 1 | 'title' => _x( 'Apple Pay Merchant Identity Private Key Password', 'adyen', 'pronamic_ideal' ), |
|||
332 | 1 | 'type' => 'text', |
|||
333 | 'classes' => array( 'regular-text', 'code' ), |
||||
334 | 1 | 'tooltip' => __( 'Your Apple Pay Merchant Identity Certificate private key password.', 'pronamic_ideal' ), |
|||
335 | ); |
||||
336 | |||||
337 | // Google Pay - Merchant identifier. |
||||
338 | 1 | $fields[] = array( |
|||
339 | 1 | 'section' => 'advanced', |
|||
340 | 'filter' => \FILTER_SANITIZE_STRING, |
||||
341 | 1 | 'meta_key' => '_pronamic_gateway_adyen_google_pay_merchant_identifier', |
|||
342 | 1 | 'title' => _x( 'Google Pay Merchant ID', 'adyen', 'pronamic_ideal' ), |
|||
343 | 1 | 'type' => 'text', |
|||
344 | 'classes' => array( 'regular-text', 'code' ), |
||||
345 | 1 | 'tooltip' => __( 'Your Google Merchant ID. Required for accepting live payments.', 'pronamic_ideal' ), |
|||
346 | 1 | 'description' => sprintf( |
|||
347 | 1 | '<a href="%s" target="_blank">%s</a><br /><a href="%s" target="_blank">%s</a>', |
|||
348 | 1 | esc_url( 'https://docs.adyen.com/payment-methods/google-pay/web-drop-in#test-and-go-live' ), |
|||
349 | 1 | esc_html__( 'Adyen documentation: "Google Pay Drop-in - Test and go live".', 'pronamic_ideal' ), |
|||
350 | 1 | esc_url( 'https://developers.google.com/pay/api/web/guides/test-and-deploy/deploy-production-environment' ), |
|||
351 | 1 | esc_html__( 'Google documentation: "Deploy production environment".', 'pronamic_ideal' ) |
|||
352 | ), |
||||
353 | ); |
||||
354 | |||||
355 | // Webhook URL. |
||||
356 | 1 | $fields[] = array( |
|||
357 | 1 | 'section' => 'feedback', |
|||
358 | 1 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
|||
359 | 1 | 'type' => 'text', |
|||
360 | 'classes' => array( 'large-text', 'code' ), |
||||
361 | 1 | 'value' => rest_url( self::REST_ROUTE_NAMESPACE . '/notifications' ), |
|||
362 | 'readonly' => true, |
||||
363 | 1 | 'tooltip' => sprintf( |
|||
364 | /* translators: %s: Adyen */ |
||||
365 | 1 | __( |
|||
366 | 1 | 'Copy the Webhook URL to the %s dashboard to receive automatic transaction status updates.', |
|||
367 | 1 | 'pronamic_ideal' |
|||
368 | ), |
||||
369 | 1 | __( 'Adyen', 'pronamic_ideal' ) |
|||
370 | ), |
||||
371 | ); |
||||
372 | |||||
373 | /** |
||||
374 | * SSL Version. |
||||
375 | * |
||||
376 | * @link https://docs.adyen.com/developers/development-resources/notifications/set-up-notifications#step3configurenotificationsinthecustomerarea |
||||
377 | * @link https://www.howsmyssl.com/a/check |
||||
378 | */ |
||||
379 | 1 | $fields[] = array( |
|||
380 | 1 | 'section' => 'feedback', |
|||
381 | 1 | 'title' => __( 'SSL Version', 'pronamic_ideal' ), |
|||
382 | 1 | 'type' => 'description', |
|||
383 | 1 | 'html' => __( 'Choose the SSL Version of your server on the Adyen Customer Area.', 'pronamic_ideal' ), |
|||
384 | ); |
||||
385 | |||||
386 | /** |
||||
387 | * Method. |
||||
388 | * |
||||
389 | * @link https://docs.adyen.com/developers/development-resources/notifications/set-up-notifications#step3configurenotificationsinthecustomerarea |
||||
390 | * @link https://www.howsmyssl.com/a/check |
||||
391 | */ |
||||
392 | 1 | $fields[] = array( |
|||
393 | 1 | 'section' => 'feedback', |
|||
394 | 1 | 'title' => _x( 'Method', 'adyen notification', 'pronamic_ideal' ), |
|||
395 | 1 | 'type' => 'description', |
|||
396 | 1 | 'html' => __( 'JSON', 'pronamic_ideal' ), |
|||
397 | ); |
||||
398 | |||||
399 | // Webhook authentication settings. |
||||
400 | 1 | $fields[] = array( |
|||
401 | 1 | 'section' => 'feedback', |
|||
402 | 1 | 'title' => __( 'Authentication', 'pronamic_ideal' ), |
|||
403 | 1 | 'type' => 'description', |
|||
404 | 1 | 'html' => sprintf( |
|||
405 | 1 | 'For webhook authentication settings, please visit <a href="%2$s" title="Settings">%1$s settings</a>.', |
|||
406 | 1 | __( 'Pronamic Pay', 'pronamic_ideal' ), |
|||
407 | 1 | add_query_arg( |
|||
408 | array( |
||||
409 | 1 | 'page' => 'pronamic_pay_settings', |
|||
410 | ), |
||||
411 | 1 | admin_url( 'admin.php' ) |
|||
412 | ) |
||||
413 | ), |
||||
414 | ); |
||||
415 | |||||
416 | // Return fields. |
||||
417 | 1 | return $fields; |
|||
418 | } |
||||
419 | |||||
420 | /** |
||||
421 | * Field certificate. |
||||
422 | * |
||||
423 | * @param array $field Field. |
||||
424 | * @return void |
||||
425 | */ |
||||
426 | public function field_certificate( $field ) { |
||||
427 | if ( ! \array_key_exists( 'meta_key', $field ) ) { |
||||
428 | return; |
||||
429 | } |
||||
430 | |||||
431 | $certificate = \get_post_meta( get_the_ID(), $field['meta_key'], true ); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
432 | |||||
433 | if ( ! empty( $certificate ) ) { |
||||
434 | $fingerprint = Security::get_sha_fingerprint( $certificate ); |
||||
435 | |||||
436 | echo '<dl>'; |
||||
437 | |||||
438 | if ( null !== $fingerprint ) { |
||||
439 | $fingerprint = \str_split( $fingerprint, 2 ); |
||||
440 | $fingerprint = \implode( ':', $fingerprint ); |
||||
441 | |||||
442 | echo '<dt>', \esc_html__( 'SHA Fingerprint', 'pronamic_ideal' ), '</dt>'; |
||||
443 | echo '<dd>', \esc_html( $fingerprint ), '</dd>'; |
||||
444 | } |
||||
445 | |||||
446 | $info = \openssl_x509_parse( $certificate ); |
||||
447 | |||||
448 | if ( $info ) { |
||||
0 ignored issues
–
show
The expression
$info of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
449 | $date_format = __( 'M j, Y @ G:i', 'pronamic_ideal' ); |
||||
450 | |||||
451 | if ( isset( $info['validFrom_time_t'] ) ) { |
||||
452 | echo '<dt>', \esc_html__( 'Valid From', 'pronamic_ideal' ), '</dt>'; |
||||
453 | echo '<dd>', \esc_html( \date_i18n( $date_format, $info['validFrom_time_t'] ) ), '</dd>'; |
||||
454 | } |
||||
455 | |||||
456 | if ( isset( $info['validTo_time_t'] ) ) { |
||||
457 | echo '<dt>', \esc_html__( 'Valid To', 'pronamic_ideal' ), '</dt>'; |
||||
458 | echo '<dd>', \esc_html( \date_i18n( $date_format, $info['validTo_time_t'] ) ), '</dd>'; |
||||
459 | } |
||||
460 | } |
||||
461 | |||||
462 | echo '</dl>'; |
||||
463 | } elseif ( false !== \strpos( $field['meta_key'], 'apple_pay' ) ) { |
||||
464 | \printf( |
||||
465 | '<p class="pronamic-pay-description description">%s</p><p> </p>', |
||||
466 | \esc_html__( 'Upload an Apple Pay Merchant Identity certificate, which can be exported from Keychain Access on Mac as a PKCS#12 (*.p12) file.', 'pronamic_ideal' ) |
||||
467 | ); |
||||
468 | } |
||||
469 | |||||
470 | ?> |
||||
471 | <p> |
||||
472 | <?php |
||||
473 | |||||
474 | if ( ! empty( $certificate ) ) { |
||||
475 | \submit_button( |
||||
476 | __( 'Download', 'pronamic_ideal' ), |
||||
477 | 'secondary', |
||||
478 | 'download' . $field['meta_key'], |
||||
479 | false |
||||
480 | ); |
||||
481 | |||||
482 | echo ' '; |
||||
483 | } |
||||
484 | |||||
485 | \printf( |
||||
486 | '<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
||||
487 | \esc_html__( 'Upload', 'pronamic_ideal' ), |
||||
488 | \esc_attr( $field['meta_key'] . '_file' ) |
||||
489 | ); |
||||
490 | |||||
491 | ?> |
||||
492 | </p> |
||||
493 | <?php |
||||
494 | } |
||||
495 | |||||
496 | /** |
||||
497 | * Field private key. |
||||
498 | * |
||||
499 | * @param array $field Field. |
||||
500 | * @return void |
||||
501 | */ |
||||
502 | public function field_private_key( $field ) { |
||||
503 | if ( ! \array_key_exists( 'meta_key', $field ) ) { |
||||
504 | return; |
||||
505 | } |
||||
506 | |||||
507 | $private_key = \get_post_meta( \get_the_ID(), $field['meta_key'], true ); |
||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
508 | |||||
509 | ?> |
||||
510 | <p> |
||||
511 | <?php |
||||
512 | |||||
513 | if ( ! empty( $private_key ) ) { |
||||
514 | \submit_button( |
||||
515 | __( 'Download', 'pronamic_ideal' ), |
||||
516 | 'secondary', |
||||
517 | 'download' . $field['meta_key'], |
||||
518 | false |
||||
519 | ); |
||||
520 | |||||
521 | echo ' '; |
||||
522 | } |
||||
523 | |||||
524 | if ( empty( $private_key ) && false !== \strpos( $field['meta_key'], 'apple_pay' ) ) { |
||||
525 | \printf( |
||||
526 | '<p class="pronamic-pay-description description">%s</p><p> </p>', |
||||
527 | \esc_html__( 'Leave empty to auto fill when uploading an Apple Pay Merchant Identity PKCS#12 certificate file.', 'pronamic_ideal' ) |
||||
528 | ); |
||||
529 | } |
||||
530 | |||||
531 | \printf( |
||||
532 | '<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
||||
533 | \esc_html__( 'Upload', 'pronamic_ideal' ), |
||||
534 | \esc_attr( $field['meta_key'] . '_file' ) |
||||
535 | ); |
||||
536 | |||||
537 | ?> |
||||
538 | </p> |
||||
539 | <?php |
||||
540 | } |
||||
541 | |||||
542 | /** |
||||
543 | * Download certificate or key in Privacy Enhanced Mail (PEM) format. |
||||
544 | * |
||||
545 | * @return void |
||||
546 | */ |
||||
547 | public function maybe_download_certificate_or_key() { |
||||
548 | // Certificate fields and download filename. |
||||
549 | $fields = array( |
||||
550 | '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate' => 'apple-pay-merchant-identity-certificate-%s.pem', |
||||
551 | '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key' => 'apple-pay-merchant-identity-private-key-%s.pem', |
||||
552 | ); |
||||
553 | |||||
554 | // Check download actions. |
||||
555 | $is_download_action = false; |
||||
556 | |||||
557 | foreach ( $fields as $meta_key => $filename ) { |
||||
558 | if ( \filter_has_var( \INPUT_POST, 'download' . $meta_key ) ) { |
||||
559 | $is_download_action = true; |
||||
560 | |||||
561 | break; |
||||
562 | } |
||||
563 | } |
||||
564 | |||||
565 | // No valid download action found. |
||||
566 | if ( false === $is_download_action ) { |
||||
567 | return; |
||||
568 | } |
||||
569 | |||||
570 | $post_id = filter_input( \INPUT_POST, 'post_ID', \FILTER_SANITIZE_STRING ); |
||||
571 | |||||
572 | $filename = sprintf( $filename, $post_id ); |
||||
573 | |||||
574 | header( 'Content-Description: File Transfer' ); |
||||
575 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
||||
576 | header( 'Content-Type: application/x-pem-file; charset=' . get_option( 'blog_charset' ), true ); |
||||
0 ignored issues
–
show
Are you sure
get_option('blog_charset') of type false|mixed can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
577 | |||||
578 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||||
579 | echo get_post_meta( $post_id, $meta_key, true ); |
||||
0 ignored issues
–
show
Are you sure
get_post_meta($post_id, $meta_key, true) of type false|mixed|string can be used in echo ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
580 | |||||
581 | exit; |
||||
582 | } |
||||
583 | |||||
584 | /** |
||||
585 | * Save post. |
||||
586 | * |
||||
587 | * @param int $post_id Post ID. |
||||
588 | * @return void |
||||
589 | */ |
||||
590 | public function save_post( $post_id ) { |
||||
591 | // Files. |
||||
592 | $files = array( |
||||
593 | '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate_file' => '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', |
||||
594 | '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key_file' => '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key', |
||||
595 | ); |
||||
596 | |||||
597 | foreach ( $files as $name => $meta_key ) { |
||||
598 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
||||
599 | if ( isset( $_FILES[ $name ] ) && \UPLOAD_ERR_OK === $_FILES[ $name ]['error'] ) { |
||||
600 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
||||
601 | $value = file_get_contents( $_FILES[ $name ]['tmp_name'] ); |
||||
602 | |||||
603 | if ( '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate' === $meta_key ) { |
||||
604 | $apple_pay_merchant_id_pkcs12 = $value; |
||||
605 | } |
||||
606 | |||||
607 | update_post_meta( $post_id, $meta_key, $value ); |
||||
608 | } |
||||
609 | } |
||||
610 | |||||
611 | // Update Apple Pay Merchant Identity certificate and private key from uploaded PKCS#12 file. |
||||
612 | if ( isset( $apple_pay_merchant_id_pkcs12 ) ) { |
||||
613 | // Try to read file without using password. |
||||
614 | $pkcs12_read = \openssl_pkcs12_read( $apple_pay_merchant_id_pkcs12, $certs, '' ); |
||||
615 | |||||
616 | $password = \get_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key_password', true ); |
||||
617 | |||||
618 | // Try to read file with private key password. |
||||
619 | if ( false === $pkcs12_read ) { |
||||
620 | $pkcs12_read = \openssl_pkcs12_read( $apple_pay_merchant_id_pkcs12, $certs, $password ); |
||||
0 ignored issues
–
show
It seems like
$password can also be of type false ; however, parameter $pass of openssl_pkcs12_read() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
621 | } |
||||
622 | |||||
623 | if ( true === $pkcs12_read ) { |
||||
624 | if ( isset( $certs['cert'] ) ) { |
||||
625 | \update_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', $certs['cert'] ); |
||||
626 | } |
||||
627 | |||||
628 | if ( isset( $certs['pkey'] ) ) { |
||||
629 | $private_key = $certs['pkey']; |
||||
630 | |||||
631 | $cipher = null; |
||||
632 | |||||
633 | // Try to export the private key encrypted. |
||||
634 | if ( defined( 'OPENSSL_CIPHER_AES_128_CBC' ) ) { |
||||
635 | $cipher = \OPENSSL_CIPHER_AES_128_CBC; |
||||
636 | } elseif ( defined( 'OPENSSL_CIPHER_3DES' ) ) { |
||||
637 | $cipher = \OPENSSL_CIPHER_3DES; |
||||
638 | } |
||||
639 | |||||
640 | if ( null !== $cipher && '' !== $password ) { |
||||
641 | $args = array( |
||||
642 | 'digest_alg' => 'SHA256', |
||||
643 | 'private_key_bits' => 2048, |
||||
644 | 'private_key_type' => \OPENSSL_KEYTYPE_RSA, |
||||
645 | 'encrypt_key' => true, |
||||
646 | 'encrypt_key_cipher' => $cipher, |
||||
647 | 'subjectKeyIdentifier' => 'hash', |
||||
648 | 'authorityKeyIdentifier' => 'keyid:always,issuer:always', |
||||
649 | 'basicConstraints' => 'CA:true', |
||||
650 | ); |
||||
651 | |||||
652 | \openssl_pkey_export( $certs['pkey'], $private_key, $password, $args ); |
||||
0 ignored issues
–
show
It seems like
$password can also be of type false ; however, parameter $passphrase of openssl_pkey_export() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
653 | } |
||||
654 | |||||
655 | \update_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key', $private_key ); |
||||
656 | } |
||||
657 | } |
||||
658 | } |
||||
659 | } |
||||
660 | |||||
661 | /** |
||||
662 | * Get configuration by post ID. |
||||
663 | * |
||||
664 | * @param int $post_id Post ID. |
||||
665 | * @return Config |
||||
666 | */ |
||||
667 | 1 | public function get_config( $post_id ) { |
|||
668 | 1 | $config = new Config(); |
|||
669 | |||||
670 | 1 | $config->mode = $this->get_meta( $post_id, 'mode' ); |
|||
671 | 1 | $config->api_key = $this->get_meta( $post_id, 'adyen_api_key' ); |
|||
672 | 1 | $config->api_live_url_prefix = $this->get_meta( $post_id, 'adyen_api_live_url_prefix' ); |
|||
673 | 1 | $config->merchant_account = $this->get_meta( $post_id, 'adyen_merchant_account' ); |
|||
674 | 1 | $config->origin_key = $this->get_meta( $post_id, 'adyen_origin_key' ); |
|||
675 | 1 | $config->apple_pay_merchant_id = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id' ); |
|||
676 | 1 | $config->apple_pay_merchant_id_certificate = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_certificate' ); |
|||
677 | 1 | $config->apple_pay_merchant_id_private_key = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_private_key' ); |
|||
678 | 1 | $config->apple_pay_merchant_id_private_key_password = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_private_key_password' ); |
|||
679 | 1 | $config->google_pay_merchant_identifier = $this->get_meta( $post_id, 'adyen_google_pay_merchant_identifier' ); |
|||
680 | |||||
681 | 1 | return $config; |
|||
682 | } |
||||
683 | |||||
684 | /** |
||||
685 | * Get gateway. |
||||
686 | * |
||||
687 | * @param int $post_id Post ID. |
||||
688 | * @return AbstractGateway |
||||
689 | */ |
||||
690 | 1 | public function get_gateway( $post_id ) { |
|||
691 | 1 | $config = $this->get_config( $post_id ); |
|||
692 | |||||
693 | 1 | if ( empty( $config->origin_key ) ) { |
|||
694 | 1 | return new WebSdkGateway( $config ); |
|||
695 | } |
||||
696 | |||||
697 | return new DropInGateway( $config ); |
||||
698 | } |
||||
699 | } |
||||
700 |