Passed
Push — develop ( 1937c8...5ee326 )
by Remco
03:35
created

settings_section_notification_authentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 2
	public function __construct() {
35 2
		$this->id            = 'adyen';
36 2
		$this->name          = 'Adyen';
37 2
		$this->provider      = 'adyen';
38 2
		$this->url           = 'https://www.adyen.com/';
39 2
		$this->dashboard_url = array(
40 2
			__( 'test', 'pronamic_ideal' ) => 'https://ca-test.adyen.com/ca/ca/login.shtml',
41 2
			__( 'live', 'pronamic_ideal' ) => 'https://ca-live.adyen.com/ca/ca/login.shtml',
42
		);
43
44
		// Notifications controller.
45 2
		$notifications_controller = new NotificationsController();
46
47 2
		$notifications_controller->setup();
48
49
		// Payments result controller.
50 2
		$payments_result_controller = new PaymentsResultController();
51
52 2
		$payments_result_controller->setup();
53
54
		// Settings.
55 2
		add_action( 'init', array( $this, 'init' ) );
56 2
		add_action( 'admin_init', array( $this, 'admin_init' ) );
57 2
	}
58
59
	/**
60
	 * Initialize.
61
	 */
62
	public function init() {
63
		/*
64
		 * Authentication - User Name
65
		 */
66
		register_setting(
67
			'pronamic_pay',
68
			'pronamic_pay_adyen_notification_authentication_username',
69
			array(
70
				'type'              => 'string',
71
				'sanitize_callback' => 'sanitize_text_field',
72
			)
73
		);
74
75
		/*
76
		 * Authentication - Password
77
		 */
78
		register_setting(
79
			'pronamic_pay',
80
			'pronamic_pay_adyen_notification_authentication_password',
81
			array(
82
				'type'              => 'string',
83
				'sanitize_callback' => 'sanitize_text_field',
84
			)
85
		);
86
	}
87
88
	/**
89
	 * Admin initialize.
90
	 */
91
	public function admin_init() {
92
		add_settings_section(
93
			'pronamic_pay_adyen_notification_authentication',
94
			__( 'Adyen Notification Authentication', 'pronamic_ideal' ),
95
			array( $this, 'settings_section_notification_authentication' ),
96
			'pronamic_pay'
97
		);
98
99
		add_settings_field(
100
			'pronamic_pay_adyen_notification_authentication_username',
101
			__( 'User Name', 'pronamic_ideal' ),
102
			array( __CLASS__, 'input_element' ),
103
			'pronamic_pay',
104
			'pronamic_pay_adyen_notification_authentication',
105
			array(
106
				'label_for' => 'pronamic_pay_adyen_notification_authentication_username',
107
			)
108
		);
109
110
		add_settings_field(
111
			'pronamic_pay_adyen_notification_authentication_password',
112
			__( 'Password', 'pronamic_ideal' ),
113
			array( __CLASS__, 'input_element' ),
114
			'pronamic_pay',
115
			'pronamic_pay_adyen_notification_authentication',
116
			array(
117
				'label_for' => 'pronamic_pay_adyen_notification_authentication_password',
118
			)
119
		);
120
	}
121
122
	/**
123
	 * Settings section notification authentication.
124
	 */
125
	public function settings_section_notification_authentication() {
126
		printf(
127
			'<p>%s</p>',
128
			esc_html__(
129
				'Set the user name and password below and in the webhook authentication settings in the Adyen dashboard for increased security (recommended).',
130
				'pronamic_ideal'
131
			)
132
		);
133
	}
134
135
	/**
136
	 * Input text.
137
	 *
138
	 * @param array $args Arguments.
139
	 */
140
	public static function input_element( $args ) {
141
		$defaults = array(
142
			'type'        => 'text',
143
			'classes'     => 'regular-text',
144
			'description' => '',
145
		);
146
147
		$args = wp_parse_args( $args, $defaults );
148
149
		$name  = $args['label_for'];
150
		$value = get_option( $name );
151
152
		$atts = array(
153
			'name'  => $name,
154
			'id'    => $name,
155
			'type'  => $args['type'],
156
			'class' => $args['classes'],
157
			'value' => $value,
158
		);
159
160
		printf(
161
			'<input %1$s />',
162
			// @codingStandardsIgnoreStart
163
			Pay_Util::array_to_html_attributes( $atts )
164
			// @codingStandardsIgnoreEnd
165
		);
166
167
		if ( ! empty( $args['description'] ) ) {
168
			printf(
169
				'<p class="description">%s</p>',
170
				esc_html( $args['description'] )
171
			);
172
		}
173
	}
174
175
	/**
176
	 * Get config factory class.
177
	 *
178
	 * @return string
179
	 */
180 1
	public function get_config_factory_class() {
181 1
		return __NAMESPACE__ . '\ConfigFactory';
182
	}
183
184
	/**
185
	 * Get settings class.
186
	 *
187
	 * @return string
188
	 */
189 1
	public function get_settings_class() {
190 1
		return __NAMESPACE__ . '\Settings';
191
	}
192
193
	/**
194
	 * Get required settings for this integration.
195
	 *
196
	 * @link https://github.com/wp-premium/gravityforms/blob/1.9.16/includes/fields/class-gf-field-multiselect.php#L21-L42
197
	 * @since 1.1.6
198
	 * @return array
199
	 */
200 1
	public function get_settings() {
201 1
		$settings = parent::get_settings();
202
203 1
		$settings[] = 'adyen';
204
205 1
		return $settings;
206
	}
207
}
208