Test Failed
Push — develop ( ddec6d...8b01ad )
by Remco
07:58
created

Integration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 268
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 136
dl 0
loc 268
ccs 79
cts 79
cp 1
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

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