|
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<string, array<string>> $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, callable|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
|
|
|
/* translators: %s: Pronamic Pay settings page URL. */ |
|
406
|
1 |
|
__( 'Go to the <a href="%s">Pronamic Pay settings page</a> for webhook authentication settings.', 'pronamic_ideal' ), |
|
407
|
1 |
|
\esc_url( |
|
408
|
1 |
|
\add_query_arg( |
|
409
|
|
|
array( |
|
410
|
1 |
|
'page' => 'pronamic_pay_settings', |
|
411
|
|
|
), |
|
412
|
1 |
|
\admin_url( 'admin.php' ) |
|
413
|
|
|
) |
|
414
|
|
|
) |
|
415
|
|
|
), |
|
416
|
|
|
); |
|
417
|
|
|
|
|
418
|
|
|
// Return fields. |
|
419
|
1 |
|
return $fields; |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* Field certificate. |
|
424
|
|
|
* |
|
425
|
|
|
* @param array<string> $field Field. |
|
426
|
|
|
* @return void |
|
427
|
|
|
*/ |
|
428
|
|
|
public function field_certificate( $field ) { |
|
429
|
|
|
if ( ! \array_key_exists( 'meta_key', $field ) ) { |
|
430
|
|
|
return; |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
$post_id = \get_the_ID(); |
|
434
|
|
|
|
|
435
|
|
|
if ( false === $post_id ) { |
|
436
|
|
|
return; |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
$certificate = \get_post_meta( $post_id, $field['meta_key'], true ); |
|
440
|
|
|
|
|
441
|
|
|
if ( ! empty( $certificate ) ) { |
|
442
|
|
|
$fingerprint = Security::get_sha_fingerprint( $certificate ); |
|
443
|
|
|
|
|
444
|
|
|
echo '<dl>'; |
|
445
|
|
|
|
|
446
|
|
|
if ( null !== $fingerprint ) { |
|
447
|
|
|
$fingerprint = \str_split( $fingerprint, 2 ); |
|
448
|
|
|
$fingerprint = \implode( ':', $fingerprint ); |
|
449
|
|
|
|
|
450
|
|
|
echo '<dt>', \esc_html__( 'SHA Fingerprint', 'pronamic_ideal' ), '</dt>'; |
|
451
|
|
|
echo '<dd>', \esc_html( $fingerprint ), '</dd>'; |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
$info = \openssl_x509_parse( $certificate ); |
|
455
|
|
|
|
|
456
|
|
|
if ( $info ) { |
|
|
|
|
|
|
457
|
|
|
$date_format = __( 'M j, Y @ G:i', 'pronamic_ideal' ); |
|
458
|
|
|
|
|
459
|
|
|
if ( isset( $info['validFrom_time_t'] ) ) { |
|
460
|
|
|
echo '<dt>', \esc_html__( 'Valid From', 'pronamic_ideal' ), '</dt>'; |
|
461
|
|
|
echo '<dd>', \esc_html( \date_i18n( $date_format, $info['validFrom_time_t'] ) ), '</dd>'; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
if ( isset( $info['validTo_time_t'] ) ) { |
|
465
|
|
|
echo '<dt>', \esc_html__( 'Valid To', 'pronamic_ideal' ), '</dt>'; |
|
466
|
|
|
echo '<dd>', \esc_html( \date_i18n( $date_format, $info['validTo_time_t'] ) ), '</dd>'; |
|
467
|
|
|
} |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
|
echo '</dl>'; |
|
471
|
|
|
} elseif ( false !== \strpos( $field['meta_key'], 'apple_pay' ) ) { |
|
472
|
|
|
\printf( |
|
473
|
|
|
'<p class="pronamic-pay-description description">%s</p><p> </p>', |
|
474
|
|
|
\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' ) |
|
475
|
|
|
); |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
?> |
|
479
|
|
|
<p> |
|
480
|
|
|
<?php |
|
481
|
|
|
|
|
482
|
|
|
if ( ! empty( $certificate ) ) { |
|
483
|
|
|
\submit_button( |
|
484
|
|
|
__( 'Download', 'pronamic_ideal' ), |
|
485
|
|
|
'secondary', |
|
486
|
|
|
'download' . $field['meta_key'], |
|
487
|
|
|
false |
|
488
|
|
|
); |
|
489
|
|
|
|
|
490
|
|
|
echo ' '; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
\printf( |
|
494
|
|
|
'<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
|
495
|
|
|
\esc_html__( 'Upload', 'pronamic_ideal' ), |
|
496
|
|
|
\esc_attr( $field['meta_key'] . '_file' ) |
|
497
|
|
|
); |
|
498
|
|
|
|
|
499
|
|
|
?> |
|
500
|
|
|
</p> |
|
501
|
|
|
<?php |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Field private key. |
|
506
|
|
|
* |
|
507
|
|
|
* @param array<string> $field Field. |
|
508
|
|
|
* @return void |
|
509
|
|
|
*/ |
|
510
|
|
|
public function field_private_key( $field ) { |
|
511
|
|
|
if ( ! \array_key_exists( 'meta_key', $field ) ) { |
|
512
|
|
|
return; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
$post_id = \get_the_ID(); |
|
516
|
|
|
|
|
517
|
|
|
if ( false === $post_id ) { |
|
518
|
|
|
return; |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
$private_key = \get_post_meta( $post_id, $field['meta_key'], true ); |
|
522
|
|
|
|
|
523
|
|
|
?> |
|
524
|
|
|
<p> |
|
525
|
|
|
<?php |
|
526
|
|
|
|
|
527
|
|
|
if ( ! empty( $private_key ) ) { |
|
528
|
|
|
\submit_button( |
|
529
|
|
|
__( 'Download', 'pronamic_ideal' ), |
|
530
|
|
|
'secondary', |
|
531
|
|
|
'download' . $field['meta_key'], |
|
532
|
|
|
false |
|
533
|
|
|
); |
|
534
|
|
|
|
|
535
|
|
|
echo ' '; |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
if ( empty( $private_key ) && false !== \strpos( $field['meta_key'], 'apple_pay' ) ) { |
|
539
|
|
|
\printf( |
|
540
|
|
|
'<p class="pronamic-pay-description description">%s</p><p> </p>', |
|
541
|
|
|
\esc_html__( 'Leave empty to auto fill when uploading an Apple Pay Merchant Identity PKCS#12 certificate file.', 'pronamic_ideal' ) |
|
542
|
|
|
); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
\printf( |
|
546
|
|
|
'<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
|
547
|
|
|
\esc_html__( 'Upload', 'pronamic_ideal' ), |
|
548
|
|
|
\esc_attr( $field['meta_key'] . '_file' ) |
|
549
|
|
|
); |
|
550
|
|
|
|
|
551
|
|
|
?> |
|
552
|
|
|
</p> |
|
553
|
|
|
<?php |
|
554
|
|
|
} |
|
555
|
|
|
|
|
556
|
|
|
/** |
|
557
|
|
|
* Download certificate or key in Privacy Enhanced Mail (PEM) format. |
|
558
|
|
|
* |
|
559
|
|
|
* @return void |
|
560
|
|
|
*/ |
|
561
|
|
|
public function maybe_download_certificate_or_key() { |
|
562
|
|
|
// Certificate fields and download filename. |
|
563
|
|
|
$fields = array( |
|
564
|
|
|
'_pronamic_gateway_adyen_apple_pay_merchant_id_certificate' => 'apple-pay-merchant-identity-certificate-%s.pem', |
|
565
|
|
|
'_pronamic_gateway_adyen_apple_pay_merchant_id_private_key' => 'apple-pay-merchant-identity-private-key-%s.pem', |
|
566
|
|
|
); |
|
567
|
|
|
|
|
568
|
|
|
// Check download actions. |
|
569
|
|
|
$is_download_action = false; |
|
570
|
|
|
|
|
571
|
|
|
foreach ( $fields as $meta_key => $filename ) { |
|
572
|
|
|
if ( \filter_has_var( \INPUT_POST, 'download' . $meta_key ) ) { |
|
573
|
|
|
$is_download_action = true; |
|
574
|
|
|
|
|
575
|
|
|
break; |
|
576
|
|
|
} |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
// No valid download action found. |
|
580
|
|
|
if ( false === $is_download_action ) { |
|
581
|
|
|
return; |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
$post_id = filter_input( \INPUT_POST, 'post_ID', \FILTER_SANITIZE_STRING ); |
|
585
|
|
|
|
|
586
|
|
|
$filename = sprintf( $filename, $post_id ); |
|
|
|
|
|
|
587
|
|
|
|
|
588
|
|
|
header( 'Content-Description: File Transfer' ); |
|
589
|
|
|
header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
590
|
|
|
header( 'Content-Type: application/x-pem-file; charset=' . get_option( 'blog_charset' ), true ); |
|
|
|
|
|
|
591
|
|
|
|
|
592
|
|
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
593
|
|
|
echo get_post_meta( $post_id, $meta_key, true ); |
|
|
|
|
|
|
594
|
|
|
|
|
595
|
|
|
exit; |
|
|
|
|
|
|
596
|
|
|
} |
|
597
|
|
|
|
|
598
|
|
|
/** |
|
599
|
|
|
* Save post. |
|
600
|
|
|
* |
|
601
|
|
|
* @param int $post_id Post ID. |
|
602
|
|
|
* @return void |
|
603
|
|
|
*/ |
|
604
|
|
|
public function save_post( $post_id ) { |
|
605
|
|
|
// Files. |
|
606
|
|
|
$files = array( |
|
607
|
|
|
'_pronamic_gateway_adyen_apple_pay_merchant_id_certificate_file' => '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', |
|
608
|
|
|
'_pronamic_gateway_adyen_apple_pay_merchant_id_private_key_file' => '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key', |
|
609
|
|
|
); |
|
610
|
|
|
|
|
611
|
|
|
foreach ( $files as $name => $meta_key ) { |
|
612
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
|
613
|
|
|
if ( isset( $_FILES[ $name ] ) && \UPLOAD_ERR_OK === $_FILES[ $name ]['error'] ) { |
|
614
|
|
|
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
|
615
|
|
|
$value = file_get_contents( $_FILES[ $name ]['tmp_name'], true ); |
|
616
|
|
|
|
|
617
|
|
|
update_post_meta( $post_id, $meta_key, $value ); |
|
618
|
|
|
} |
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
// Update Apple Pay Merchant Identity certificate and private key from uploaded PKCS#12 file. |
|
622
|
|
|
$apple_pay_merchant_id_pkcs12 = get_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', true ); |
|
623
|
|
|
|
|
624
|
|
|
if ( ! empty( $apple_pay_merchant_id_pkcs12 ) ) { |
|
625
|
|
|
// Try to read file without using password. |
|
626
|
|
|
$pkcs12_read = \openssl_pkcs12_read( $apple_pay_merchant_id_pkcs12, $certs, '' ); |
|
627
|
|
|
|
|
628
|
|
|
$password = \get_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key_password', true ); |
|
629
|
|
|
|
|
630
|
|
|
// Try to read file with private key password. |
|
631
|
|
|
if ( false === $pkcs12_read ) { |
|
632
|
|
|
$pkcs12_read = \openssl_pkcs12_read( $apple_pay_merchant_id_pkcs12, $certs, $password ); |
|
|
|
|
|
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
if ( true === $pkcs12_read ) { |
|
636
|
|
|
if ( isset( $certs['cert'] ) ) { |
|
637
|
|
|
\update_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_certificate', $certs['cert'] ); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
if ( isset( $certs['pkey'] ) ) { |
|
641
|
|
|
$private_key = $certs['pkey']; |
|
642
|
|
|
|
|
643
|
|
|
$cipher = null; |
|
644
|
|
|
|
|
645
|
|
|
// Try to export the private key encrypted. |
|
646
|
|
|
if ( defined( 'OPENSSL_CIPHER_AES_128_CBC' ) ) { |
|
647
|
|
|
$cipher = \OPENSSL_CIPHER_AES_128_CBC; |
|
648
|
|
|
} elseif ( defined( 'OPENSSL_CIPHER_3DES' ) ) { |
|
649
|
|
|
$cipher = \OPENSSL_CIPHER_3DES; |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
if ( null !== $cipher && '' !== $password ) { |
|
653
|
|
|
$args = array( |
|
654
|
|
|
'digest_alg' => 'SHA256', |
|
655
|
|
|
'private_key_bits' => 2048, |
|
656
|
|
|
'private_key_type' => \OPENSSL_KEYTYPE_RSA, |
|
657
|
|
|
'encrypt_key' => true, |
|
658
|
|
|
'encrypt_key_cipher' => $cipher, |
|
659
|
|
|
'subjectKeyIdentifier' => 'hash', |
|
660
|
|
|
'authorityKeyIdentifier' => 'keyid:always,issuer:always', |
|
661
|
|
|
'basicConstraints' => 'CA:true', |
|
662
|
|
|
); |
|
663
|
|
|
|
|
664
|
|
|
\openssl_pkey_export( $certs['pkey'], $private_key, $password, $args ); |
|
|
|
|
|
|
665
|
|
|
} |
|
666
|
|
|
|
|
667
|
|
|
\update_post_meta( $post_id, '_pronamic_gateway_adyen_apple_pay_merchant_id_private_key', $private_key ); |
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
|
|
673
|
|
|
/** |
|
674
|
|
|
* Get configuration by post ID. |
|
675
|
|
|
* |
|
676
|
|
|
* @param int $post_id Post ID. |
|
677
|
|
|
* @return Config |
|
678
|
|
|
*/ |
|
679
|
1 |
|
public function get_config( $post_id ) { |
|
680
|
1 |
|
$config = new Config(); |
|
681
|
|
|
|
|
682
|
1 |
|
$config->mode = $this->get_meta( $post_id, 'mode' ); |
|
683
|
1 |
|
$config->api_key = $this->get_meta( $post_id, 'adyen_api_key' ); |
|
684
|
1 |
|
$config->api_live_url_prefix = $this->get_meta( $post_id, 'adyen_api_live_url_prefix' ); |
|
685
|
1 |
|
$config->merchant_account = $this->get_meta( $post_id, 'adyen_merchant_account' ); |
|
686
|
1 |
|
$config->origin_key = $this->get_meta( $post_id, 'adyen_origin_key' ); |
|
687
|
1 |
|
$config->apple_pay_merchant_id = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id' ); |
|
688
|
1 |
|
$config->apple_pay_merchant_id_certificate = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_certificate' ); |
|
689
|
1 |
|
$config->apple_pay_merchant_id_private_key = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_private_key' ); |
|
690
|
1 |
|
$config->apple_pay_merchant_id_private_key_password = $this->get_meta( $post_id, 'adyen_apple_pay_merchant_id_private_key_password' ); |
|
691
|
1 |
|
$config->google_pay_merchant_identifier = $this->get_meta( $post_id, 'adyen_google_pay_merchant_identifier' ); |
|
692
|
|
|
|
|
693
|
1 |
|
return $config; |
|
694
|
|
|
} |
|
695
|
|
|
|
|
696
|
|
|
/** |
|
697
|
|
|
* Get gateway. |
|
698
|
|
|
* |
|
699
|
|
|
* @param int $post_id Post ID. |
|
700
|
|
|
* @return AbstractGateway |
|
701
|
|
|
*/ |
|
702
|
1 |
|
public function get_gateway( $post_id ) { |
|
703
|
1 |
|
$config = $this->get_config( $post_id ); |
|
704
|
|
|
|
|
705
|
1 |
|
if ( empty( $config->origin_key ) ) { |
|
706
|
1 |
|
return new WebSdkGateway( $config ); |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
return new DropInGateway( $config ); |
|
710
|
|
|
} |
|
711
|
|
|
} |
|
712
|
|
|
|
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
empty(..)or! empty(...)instead.