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