Failed Conditions
Push — develop ( 93d3d3...1fe35c )
by Remco
03:21
created

Settings::save_post()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * Settings
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\Core\GatewaySettings;
14
15
/**
16
 * Settings
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.0.0
20
 * @since   1.0.0
21
 */
22
class Settings extends GatewaySettings {
23
	/**
24
	 * Constructs and initialize settings.
25
	 */
26
	public function __construct() {
27
		add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) );
28
		add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) );
29
	}
30
31
	/**
32
	 * Sections.
33
	 *
34
	 * @param array $sections Sections.
35
	 * @return array
36
	 */
37
	public function sections( array $sections ) {
38
		$sections['adyen'] = array(
39
			'title'   => __( 'Adyen', 'pronamic_ideal' ),
40
			'methods' => array( 'adyen' ),
41
		);
42
43
		// Transaction feedback.
44
		$sections['adyen_feedback'] = array(
45
			'title'       => __( 'Transaction feedback', 'pronamic_ideal' ),
46
			'methods'     => array( 'adyen' ),
47
			'description' => sprintf(
48
				'%s %s',
49
				__(
50
					'The URLs below need to be copied to the payment provider dashboard to receive automatic transaction status updates.',
51
					'pronamic_ideal'
52
				),
53
				__(
54
					'Set the user name and password below and in the webhook authentication settings in the Adyen dashboard for increased security (recommended).',
55
					'pronamic_ideal'
56
				)
57
			),
58
		);
59
60
		return $sections;
61
	}
62
63
	/**
64
	 * Fields.
65
	 *
66
	 * @param array $fields Fields.
67
	 * @return array
68
	 */
69
	public function fields( array $fields ) {
70
		// API Key.
71
		$fields[] = array(
72
			'filter'   => FILTER_SANITIZE_STRING,
73
			'section'  => 'adyen',
74
			'meta_key' => '_pronamic_gateway_adyen_api_key',
75
			'title'    => _x( 'API Key', 'adyen', 'pronamic_ideal' ),
76
			'type'     => 'textarea',
77
			'classes'  => array( 'code' ),
78
			'methods'  => array( 'adyen' ),
79
			'tooltip'  => __( 'API key as mentioned in the payment provider dashboard', 'pronamic_ideal' ),
80
		);
81
82
		// Live API URL prefix.
83
		$fields[] = array(
84
			'filter'   => FILTER_SANITIZE_STRING,
85
			'section'  => 'adyen',
86
			'meta_key' => '_pronamic_gateway_adyen_live_url_prefix',
87
			'title'    => _x( 'API Live URL Prefix', 'adyen', 'pronamic_ideal' ),
88
			'type'     => 'text',
89
			'classes'  => array( 'regular-text', 'code' ),
90
			'methods'  => array( 'adyen' ),
91
			'tooltip'  => __( 'The unique prefix for the live API URL, as mentioned at <strong>Account » API URLs</strong> in the Adyen dashboard', 'pronamic_ideal' ),
92
		);
93
94
		// Merchant Account.
95
		$fields[] = array(
96
			'filter'   => FILTER_SANITIZE_STRING,
97
			'section'  => 'adyen',
98
			'meta_key' => '_pronamic_gateway_adyen_merchant_account',
99
			'title'    => _x( 'Merchant Account', 'adyen', 'pronamic_ideal' ),
100
			'type'     => 'text',
101
			'classes'  => array( 'regular-text', 'code' ),
102
			'methods'  => array( 'adyen' ),
103
			'tooltip'  => __( 'The merchant account identifier, with which you want to process the transaction', 'pronamic_ideal' ),
104
		);
105
106
		// Transaction feedback.
107
		$fields[] = array(
108
			'section' => 'adyen',
109
			'methods' => array( 'adyen' ),
110
			'title'   => __( 'Transaction feedback', 'pronamic_ideal' ),
111
			'type'    => 'description',
112
			'html'    => sprintf(
113
				'<span class="dashicons dashicons-warning"></span> %s',
114
				__(
115
					'Receiving payment status updates needs additional configuration, if not yet completed.',
116
					'pronamic_ideal'
117
				)
118
			),
119
		);
120
121
		// Webhook URL.
122
		$fields[] = array(
123
			'section'  => 'adyen_feedback',
124
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
125
			'type'     => 'text',
126
			'classes'  => array( 'large-text', 'code' ),
127
			'value'    => get_rest_url( null, NotificationsController::REST_ROUTE_NAMESPACE . '/notifications' ),
128
			'readonly' => true,
129
			'tooltip'  => sprintf(
130
				/* translators: %s: Adyen */
131
				__(
132
					'Copy the Webhook URL to the %s dashboard to receive automatic transaction status updates.',
133
					'pronamic_ideal'
134
				),
135
				__( 'Adyen', 'pronamic_ideal' )
136
			),
137
		);
138
139
		// Webhook authentication settings.
140
		$fields[] = array(
141
			'section' => 'adyen_feedback',
142
			'methods' => array( 'adyen' ),
143
			'title'   => __( 'Authentication', 'pronamic_ideal' ),
144
			'type'    => 'description',
145
			'html'    => sprintf(
146
				'For webhook authentication settings, please visit <a href="%2$s" title="Settings">%1$s settings</a>.',
147
				__( 'Pronamic Pay', 'pronamic_ideal' ),
148
				$url = add_query_arg(
149
					array(
150
						'page' => 'pronamic_pay_settings',
151
					),
152
					admin_url( 'admin.php' )
153
				)
154
			),
155
		);
156
157
		return $fields;
158
	}
159
}
160