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\Gateways\Common\AbstractIntegration; |
||
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 AbstractIntegration { |
||
25 | /** |
||
26 | * REST route namespace. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | const REST_ROUTE_NAMESPACE = 'pronamic-pay/adyen/v1'; |
||
31 | |||
32 | /** |
||
33 | * Integration constructor. |
||
34 | 5 | */ |
|
35 | 5 | public function __construct() { |
|
36 | 5 | parent::__construct(); |
|
37 | 5 | ||
38 | 5 | $this->id = 'adyen'; |
|
39 | 5 | $this->name = 'Adyen'; |
|
40 | 5 | $this->provider = 'adyen'; |
|
41 | 5 | $this->url = __( 'https://www.adyen.com/', 'pronamic_ideal' ); |
|
42 | 5 | $this->product_url = __( 'https://www.adyen.com/pricing', 'pronamic_ideal' ); |
|
43 | $this->dashboard_url = array( |
||
44 | 5 | __( 'test', 'pronamic_ideal' ) => 'https://ca-test.adyen.com/ca/ca/login.shtml', |
|
45 | __( 'live', 'pronamic_ideal' ) => 'https://ca-live.adyen.com/ca/ca/login.shtml', |
||
46 | ); |
||
47 | $this->supports = array( |
||
48 | 'webhook', |
||
49 | 5 | 'webhook_log', |
|
50 | ); |
||
51 | |||
52 | 5 | $this->set_manual_url( __( 'https://www.pronamic.eu/manuals/using-adyen-pronamic-pay/', 'pronamic_ideal' ) ); |
|
53 | |||
54 | 5 | // Dependencies. |
|
55 | $dependencies = $this->get_dependencies(); |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | 5 | $dependencies->add( new PhpExtensionDependency( 'intl' ) ); |
|
58 | |||
59 | 5 | // Notifications controller. |
|
60 | $notifications_controller = new NotificationsController(); |
||
61 | |||
62 | 5 | $notifications_controller->setup(); |
|
63 | |||
64 | 5 | // Payments controller. |
|
65 | $payments_controller = new PaymentsController(); |
||
66 | |||
67 | 5 | $payments_controller->setup(); |
|
68 | |||
69 | 5 | // Payments result controller. |
|
70 | $payments_result_controller = new PaymentsResultController(); |
||
71 | |||
72 | 5 | $payments_result_controller->setup(); |
|
73 | 5 | ||
74 | 5 | // Site Health controller. |
|
75 | $site_healht_controller = new SiteHealthController(); |
||
76 | |||
77 | $site_healht_controller->setup(); |
||
78 | |||
79 | // Settings. |
||
80 | add_action( 'init', array( $this, 'init' ) ); |
||
81 | 1 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | 1 | * Initialize. |
|
86 | 1 | * |
|
87 | 1 | * @return void |
|
88 | */ |
||
89 | 1 | public function init() { |
|
90 | /* |
||
91 | * Authentication - User Name |
||
92 | */ |
||
93 | register_setting( |
||
94 | 'pronamic_pay', |
||
95 | 'pronamic_pay_adyen_notification_authentication_username', |
||
96 | array( |
||
97 | 1 | 'type' => 'string', |
|
98 | 1 | 'sanitize_callback' => 'sanitize_text_field', |
|
99 | 1 | ) |
|
100 | ); |
||
101 | 1 | ||
102 | /* |
||
103 | * Authentication - Password |
||
104 | */ |
||
105 | 1 | register_setting( |
|
106 | 'pronamic_pay', |
||
107 | 'pronamic_pay_adyen_notification_authentication_password', |
||
108 | array( |
||
109 | 'type' => 'string', |
||
110 | 'sanitize_callback' => 'sanitize_text_field', |
||
111 | ) |
||
112 | 1 | ); |
|
113 | 1 | } |
|
114 | 1 | ||
115 | /** |
||
116 | 1 | * Admin initialize. |
|
117 | 1 | * |
|
118 | 1 | * @return void |
|
119 | */ |
||
120 | public function admin_init() { |
||
121 | 1 | add_settings_section( |
|
122 | 1 | 'pronamic_pay_adyen_notification_authentication', |
|
123 | 1 | /* translators: Translate 'notification' the same as in the Adyen dashboard. */ |
|
124 | 1 | _x( 'Adyen Notification Authentication', 'Adyen', 'pronamic_ideal' ), |
|
125 | 1 | array( $this, 'settings_section_notification_authentication' ), |
|
126 | 1 | 'pronamic_pay' |
|
127 | ); |
||
128 | 1 | ||
129 | add_settings_field( |
||
130 | 'pronamic_pay_adyen_notification_authentication_username', |
||
131 | __( 'User Name', 'pronamic_ideal' ), |
||
132 | 1 | array( __CLASS__, 'input_element' ), |
|
133 | 1 | 'pronamic_pay', |
|
134 | 1 | 'pronamic_pay_adyen_notification_authentication', |
|
135 | 1 | array( |
|
136 | 1 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_username', |
|
137 | 1 | ) |
|
138 | ); |
||
139 | 1 | ||
140 | add_settings_field( |
||
141 | 'pronamic_pay_adyen_notification_authentication_password', |
||
142 | 1 | __( 'Password', 'pronamic_ideal' ), |
|
143 | array( __CLASS__, 'input_element' ), |
||
144 | 'pronamic_pay', |
||
145 | 'pronamic_pay_adyen_notification_authentication', |
||
146 | array( |
||
147 | 'label_for' => 'pronamic_pay_adyen_notification_authentication_password', |
||
148 | ) |
||
149 | 1 | ); |
|
150 | 1 | } |
|
151 | 1 | ||
152 | 1 | /** |
|
153 | 1 | * Settings section notification authentication. |
|
154 | 1 | * |
|
155 | * @return void |
||
156 | */ |
||
157 | 1 | public function settings_section_notification_authentication() { |
|
158 | printf( |
||
159 | '<p>%s</p>', |
||
160 | esc_html__( |
||
161 | 'Set the user name and password below and in the webhook authentication settings in the Adyen dashboard for increased security (recommended).', |
||
162 | 'pronamic_ideal' |
||
163 | ) |
||
164 | ); |
||
165 | 1 | } |
|
166 | 1 | ||
167 | /** |
||
168 | 1 | * Input text. |
|
169 | 1 | * |
|
170 | * @param array<string,string> $args Arguments. |
||
171 | 1 | * @return void |
|
172 | 1 | */ |
|
173 | 1 | public static function input_element( $args ) { |
|
174 | 1 | $name = $args['label_for']; |
|
175 | 1 | ||
176 | $value = get_option( $name ); |
||
177 | 1 | $value = strval( $value ); |
|
178 | |||
179 | printf( |
||
180 | '<input name="%s" id="%s" value="%s" type="text" class="regular-text" />', |
||
181 | esc_attr( $name ), |
||
182 | esc_attr( $name ), |
||
183 | esc_attr( $value ) |
||
184 | 1 | ); |
|
185 | 1 | } |
|
186 | |||
187 | /** |
||
188 | 1 | * Get settings fields. |
|
189 | 1 | * |
|
190 | 1 | * @return array<int, array<string, int|string|bool|array<int,string>>> |
|
191 | 1 | */ |
|
192 | 1 | public function get_settings_fields() { |
|
193 | 1 | $fields = array(); |
|
194 | |||
195 | 1 | // Merchant Account. |
|
196 | $fields[] = array( |
||
197 | 'section' => 'general', |
||
198 | 'filter' => FILTER_SANITIZE_STRING, |
||
199 | 1 | 'meta_key' => '_pronamic_gateway_adyen_merchant_account', |
|
200 | 1 | 'title' => _x( 'Merchant Account', 'adyen', 'pronamic_ideal' ), |
|
201 | 1 | 'type' => 'text', |
|
202 | 1 | 'classes' => array( 'regular-text', 'code' ), |
|
203 | 1 | 'tooltip' => __( 'The merchant account identifier, with which you want to process the transaction.', 'pronamic_ideal' ), |
|
204 | 1 | ); |
|
205 | |||
206 | 1 | // API Key. |
|
207 | 1 | $fields[] = array( |
|
208 | 1 | 'section' => 'general', |
|
209 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|
210 | 1 | 'meta_key' => '_pronamic_gateway_adyen_api_key', |
|
211 | 'title' => _x( 'API Key', 'adyen', 'pronamic_ideal' ), |
||
212 | 'type' => 'textarea', |
||
213 | 'classes' => array( 'code' ), |
||
214 | 'tooltip' => __( 'API key as mentioned in the payment provider dashboard.', 'pronamic_ideal' ), |
||
215 | 1 | 'description' => sprintf( |
|
216 | 1 | '<a href="%s" target="_blank">%s</a>', |
|
217 | 1 | esc_url( 'https://docs.adyen.com/developers/user-management/how-to-get-the-api-key' ), |
|
218 | 1 | esc_html__( 'Adyen documentation: "How to get the API key".', 'pronamic_ideal' ) |
|
219 | 1 | ), |
|
220 | 1 | ); |
|
221 | |||
222 | 1 | // Live API URL prefix. |
|
223 | 1 | $fields[] = array( |
|
224 | 1 | 'section' => 'general', |
|
225 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|
226 | 1 | 'meta_key' => '_pronamic_gateway_adyen_api_live_url_prefix', |
|
227 | 'title' => _x( 'API Live URL Prefix', 'adyen', 'pronamic_ideal' ), |
||
228 | 'type' => 'text', |
||
229 | 'classes' => array( 'regular-text', 'code' ), |
||
230 | 'tooltip' => __( 'The unique prefix for the live API URL, as mentioned at <strong>Account » API URLs</strong> in the Adyen dashboard.', 'pronamic_ideal' ), |
||
231 | 1 | 'description' => sprintf( |
|
232 | 1 | '<a href="%s" target="_blank">%s</a>', |
|
233 | 1 | esc_url( 'https://docs.adyen.com/developers/development-resources/live-endpoints#liveurlprefix' ), |
|
234 | 1 | esc_html__( 'Adyen documentation: "Live URL prefix".', 'pronamic_ideal' ) |
|
235 | 1 | ), |
|
236 | 1 | ); |
|
237 | |||
238 | // Origin Key. |
||
239 | $fields[] = array( |
||
240 | 'section' => 'general', |
||
241 | 'filter' => FILTER_SANITIZE_STRING, |
||
242 | 1 | 'meta_key' => '_pronamic_gateway_adyen_origin_key', |
|
243 | 1 | 'title' => _x( 'Origin Key', 'adyen', 'pronamic_ideal' ), |
|
244 | 1 | 'type' => 'text', |
|
245 | 1 | 'classes' => array( |
|
246 | 1 | 'regular-text', |
|
247 | 'code', |
||
248 | 'pronamic-pay-form-control-lg', |
||
249 | ), |
||
250 | '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' ), |
||
251 | 1 | 'description' => sprintf( |
|
252 | 1 | '<a href="%s" target="_blank">%s</a>', |
|
253 | 1 | esc_url( 'https://docs.adyen.com/user-management/how-to-get-an-origin-key' ), |
|
254 | 1 | esc_html__( 'Adyen documentation: "How to get an origin key".', 'pronamic_ideal' ) |
|
255 | ), |
||
256 | 1 | ); |
|
257 | |||
258 | 1 | // Webhook URL. |
|
259 | $fields[] = array( |
||
260 | 1 | 'section' => 'feedback', |
|
261 | 1 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
|
262 | 1 | 'type' => 'text', |
|
263 | 'classes' => array( 'large-text', 'code' ), |
||
264 | 1 | 'value' => rest_url( self::REST_ROUTE_NAMESPACE . '/notifications' ), |
|
265 | 'readonly' => true, |
||
266 | 'tooltip' => sprintf( |
||
267 | /* translators: %s: Adyen */ |
||
268 | __( |
||
269 | 'Copy the Webhook URL to the %s dashboard to receive automatic transaction status updates.', |
||
270 | 'pronamic_ideal' |
||
271 | ), |
||
272 | __( 'Adyen', 'pronamic_ideal' ) |
||
273 | ), |
||
274 | 1 | ); |
|
275 | 1 | ||
276 | 1 | /** |
|
277 | 1 | * SSL Version. |
|
278 | 1 | * |
|
279 | * @link https://docs.adyen.com/developers/development-resources/notifications/set-up-notifications#step3configurenotificationsinthecustomerarea |
||
280 | * @link https://www.howsmyssl.com/a/check |
||
281 | */ |
||
282 | $fields[] = array( |
||
283 | 'section' => 'feedback', |
||
284 | 'title' => __( 'SSL Version', 'pronamic_ideal' ), |
||
285 | 'type' => 'description', |
||
286 | 'html' => __( 'Choose the SSL Version of your server on the Adyen Customer Area.', 'pronamic_ideal' ), |
||
287 | 1 | ); |
|
288 | 1 | ||
289 | 1 | /** |
|
290 | 1 | * Method. |
|
291 | 1 | * |
|
292 | * @link https://docs.adyen.com/developers/development-resources/notifications/set-up-notifications#step3configurenotificationsinthecustomerarea |
||
293 | * @link https://www.howsmyssl.com/a/check |
||
294 | */ |
||
295 | 1 | $fields[] = array( |
|
296 | 1 | 'section' => 'feedback', |
|
297 | 1 | 'title' => _x( 'Method', 'adyen notification', 'pronamic_ideal' ), |
|
298 | 1 | 'type' => 'description', |
|
299 | 1 | 'html' => __( 'JSON', 'pronamic_ideal' ), |
|
300 | 1 | ); |
|
301 | 1 | ||
302 | 1 | // Webhook authentication settings. |
|
303 | $fields[] = array( |
||
304 | 1 | 'section' => 'feedback', |
|
305 | 'title' => __( 'Authentication', 'pronamic_ideal' ), |
||
306 | 1 | 'type' => 'description', |
|
307 | 'html' => sprintf( |
||
308 | 'For webhook authentication settings, please visit <a href="%2$s" title="Settings">%1$s settings</a>.', |
||
309 | __( 'Pronamic Pay', 'pronamic_ideal' ), |
||
310 | add_query_arg( |
||
311 | array( |
||
312 | 1 | 'page' => 'pronamic_pay_settings', |
|
313 | ), |
||
314 | admin_url( 'admin.php' ) |
||
315 | ) |
||
316 | ), |
||
317 | ); |
||
318 | |||
319 | // Return fields. |
||
320 | return $fields; |
||
321 | 1 | } |
|
322 | 1 | ||
323 | /** |
||
324 | 1 | * Get configuration by post ID. |
|
325 | 1 | * |
|
326 | 1 | * @param int $post_id Post ID. |
|
327 | 1 | * @return Config |
|
328 | 1 | */ |
|
329 | public function get_config( $post_id ) { |
||
330 | 1 | $config = new Config(); |
|
331 | |||
332 | $config->mode = $this->get_meta( $post_id, 'mode' ); |
||
333 | $config->api_key = $this->get_meta( $post_id, 'adyen_api_key' ); |
||
334 | $config->api_live_url_prefix = $this->get_meta( $post_id, 'adyen_api_live_url_prefix' ); |
||
335 | $config->merchant_account = $this->get_meta( $post_id, 'adyen_merchant_account' ); |
||
336 | $config->origin_key = $this->get_meta( $post_id, 'adyen_origin_key' ); |
||
337 | |||
338 | return $config; |
||
339 | 1 | } |
|
340 | 1 | ||
341 | /** |
||
342 | 1 | * Get gateway. |
|
343 | 1 | * |
|
344 | * @param int $post_id Post ID. |
||
345 | * @return AbstractGateway |
||
346 | */ |
||
347 | public function get_gateway( $post_id ) { |
||
348 | $config = $this->get_config( $post_id ); |
||
349 | |||
350 | if ( empty( $config->origin_key ) ) { |
||
351 | return new WebSdkGateway( $config ); |
||
352 | } |
||
353 | |||
354 | return new DropInGateway( $config ); |
||
355 | } |
||
356 | } |
||
357 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.