Failed Conditions
Push — feature/webhook-status ( 7d098e )
by Reüel
05:54
created

Settings   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 57
dl 0
loc 119
ccs 0
cts 74
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sections() 0 26 1
A feedback_status() 0 4 1
A __construct() 0 3 1
A fields() 0 57 1
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\ING\KassaCompleet
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\ING\KassaCompleet;
12
13
use Pronamic\WordPress\Pay\Core\GatewaySettings;
14
use Pronamic\WordPress\Pay\WebhookManager;
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\WebhookManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Title: ING Kassa Compleet gateway settings
18
 * Description:
19
 * Copyright: 2005-2019 Pronamic
20
 * Company: Pronamic
21
 *
22
 * @author  Remco Tolsma
23
 * @version 2.0.0
24
 * @since   1.0.0
25
 */
26
class Settings extends GatewaySettings {
27
	/**
28
	 * Settings constructor.
29
	 */
30
	public function __construct() {
31
		add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) );
32
		add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) );
33
	}
34
35
	/**
36
	 * Settings sections.
37
	 *
38
	 * @param array $sections Sections.
39
	 *
40
	 * @return array
41
	 */
42
	public function sections( array $sections ) {
43
		// ING Kassa Compleet.
44
		$sections['ing_kassa_compleet'] = array(
45
			'title'       => __( 'ING Kassa Compleet', 'pronamic_ideal' ),
46
			'methods'     => array( 'ing_kassa_compleet' ),
47
			'description' => sprintf(
48
				/* translators: 1: ING */
49
				__( 'Account details are provided by %1$s after registration. These settings need to match with the %1$s dashboard.', 'pronamic_ideal' ),
50
				__( 'ING', 'pronamic_ideal' )
51
			),
52
		);
53
54
		// Transaction feedback.
55
		$sections['ing_kassa_compleet_feedback'] = array(
56
			'title'       => __( 'Transaction feedback', 'pronamic_ideal' ),
57
			'methods'     => array( 'ing_kassa_compleet' ),
58
			'description' => sprintf(
59
				/* translators: %s: ING Kassa Compleet */
60
				__( 'Set the Webhook URL in the %s dashboard to receive automatic transaction status updates.', 'pronamic_ideal' ),
61
				__( 'ING Kassa Compleet', 'pronamic_ideal' )
62
			),
63
			'features'    => Gateway::get_supported_features(),
64
		);
65
66
		// Return sections.
67
		return $sections;
68
	}
69
70
	/**
71
	 * Settings fields.
72
	 *
73
	 * @param array $fields Fields.
74
	 *
75
	 * @return array
76
	 */
77
	public function fields( array $fields ) {
78
		// API Key.
79
		$fields[] = array(
80
			'filter'   => FILTER_SANITIZE_STRING,
81
			'section'  => 'ing_kassa_compleet',
82
			'meta_key' => '_pronamic_gateway_ing_kassa_compleet_api_key',
83
			'title'    => _x( 'API Key', 'ing_kassa_compleet', 'pronamic_ideal' ),
84
			'type'     => 'text',
85
			'classes'  => array( 'regular-text', 'code' ),
86
			'methods'  => array( 'ing_kassa_compleet' ),
87
			'tooltip'  => sprintf(
88
				'%s %s.',
89
				__( 'API key', 'pronamic_ideal' ),
90
				sprintf(
91
					/* translators: %s: ING Kassa Compleet */
92
					__( 'as mentioned in the %s dashboard', 'pronamic_ideal' ),
93
					__( 'ING Kassa Compleet', 'pronamic_ideal' )
94
				)
95
			),
96
		);
97
98
		// Transaction feedback.
99
		$fields[] = array(
100
			'section'  => 'ing_kassa_compleet',
101
			'methods'  => array( 'ing_kassa_compleet' ),
102
			'title'    => __( 'Transaction feedback', 'pronamic_ideal' ),
103
			'type'     => 'description',
104
			'html'     => __( 'Receiving payment status updates needs additional configuration.', 'pronamic_ideal' ),
105
			'features' => Gateway::get_supported_features(),
106
		);
107
108
		// Webhook URL.
109
		$fields[] = array(
110
			'section'  => 'ing_kassa_compleet_feedback',
111
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
112
			'type'     => 'text',
113
			'classes'  => array( 'large-text', 'code' ),
114
			'value'    => add_query_arg( 'ing_kassa_compleet_webhook', '', home_url( '/' ) ),
115
			'readonly' => true,
116
			'tooltip'  => sprintf(
117
				/* translators: %s: ING Kassa Compleet */
118
				__( 'Copy the Webhook URL to the %s dashboard to receive automatic transaction status updates.', 'pronamic_ideal' ),
119
				__( 'ING Kassa Compleet', 'pronamic_ideal' )
120
			),
121
		);
122
123
		// Webhook status.
124
		$fields[] = array(
125
			'section'  => 'ing_kassa_compleet_feedback',
126
			'methods'  => array( 'ing_kassa_compleet' ),
127
			'title'    => __( 'Status', 'pronamic_ideal' ),
128
			'type'     => 'description',
129
			'callback' => array( $this, 'feedback_status' ),
130
		);
131
132
		// Return fields.
133
		return $fields;
134
	}
135
136
	/**
137
	 * Transaction feedback status.
138
	 *
139
	 * @param array $field Settings field.
140
	 */
141
	public function feedback_status( $field ) {
142
		$features = Gateway::get_supported_features();
143
144
		WebhookManager::settings_status( $field, $features );
145
	}
146
}
147