Failed Conditions
Push — develop ( e677c4...516c53 )
by Remco
06:52
created

Integration::get_settings_class()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
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\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
14
15
/**
16
 * Integration
17
 *
18
 * @author  Remco Tolsma
19
 * @version 2.1.0
20
 * @since   1.0.0
21
 */
22
class Integration extends AbstractIntegration {
23
	/**
24
	 * Construct and initialize integration.
25
	 */
26
	public function __construct() {
27
		$this->id            = 'rabobank-omnikassa-2';
28
		$this->name          = 'Rabobank - OmniKassa 2.0';
29
		$this->product_url   = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/';
30
		$this->dashboard_url = 'https://bankieren.rabobank.nl/omnikassa-dashboard/';
31
		$this->provider      = 'rabobank';
32
33
		/**
34
		 * Webhook listener function.
35
		 *
36
		 * @var callable $webhook_listener_function
37
		 */
38
		$webhook_listener_function = array( __NAMESPACE__ . '\WebhookListener', 'listen' );
39
40
		if ( ! has_action( 'wp_loaded', $webhook_listener_function ) ) {
41
			add_action( 'wp_loaded', $webhook_listener_function );
42
		}
43
44
		/**
45
		 * Save post.
46
		 *
47
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736
48
		 *
49
		 * @var callable $delete_access_token_meta_function
50
		 */
51
		$delete_access_token_meta_function = array( __NAMESPACE__ . '\ConfigFactory', 'delete_access_token_meta' );
52
53
		if ( ! has_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ) ) {
54
			add_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function );
55
		}
56
57
		/**
58
		 * Admin notices.
59
		 *
60
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
61
		 *
62
		 * @var callable $admin_notices_function
63
		 */
64
		$admin_notices_function = array( $this, 'admin_notice_tld_test' );
65
66
		if ( ! has_action( 'admin_notices', $admin_notices_function ) ) {
67
			add_action( 'admin_notices', $admin_notices_function );
68
		}
69
	}
70
71
	/**
72
	 * Admin notice TLD .test.
73
	 *
74
	 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
75
	 * @link https://developer.wordpress.org/reference/hooks/admin_notices/
76
	 * @link https://developer.wordpress.org/reference/functions/get_current_screen/
77
	 */
78
	public function admin_notice_tld_test() {
79
		if ( has_filter( 'pronamic_pay_omnikassa_2_merchant_return_url' ) ) {
80
			return;
81
		}
82
83
		$screen = get_current_screen();
84
85
		if ( null === $screen ) {
86
			return;
87
		}
88
89
		if ( 'pronamic_gateway' !== $screen->id ) {
90
			return;
91
		}
92
93
		$host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
94
95
		if ( is_array( $host ) ) {
96
			return;
97
		}
98
99
		if ( '.test' !== substr( $host, -5 ) ) {
100
			return;
101
		}
102
103
		$post_id = get_the_ID();
104
105
		if ( empty( $post_id ) ) {
106
			return;
107
		}
108
109
		$gateway_id = get_post_meta( $post_id, '_pronamic_gateway_id', true );
110
111
		if ( 'rabobank-omnikassa-2' !== $gateway_id ) {
112
			return;
113
		}
114
115
		$class   = 'notice notice-error';
116
		$message = sprintf(
117
			/* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */
118
			__( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ),
119
			sprintf(
120
				'<strong>%s</strong>',
121
				__( 'Pronamic Pay', 'pronamic_ideal' )
122
			),
123
			'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address',
124
			'<code>.test</code>'
125
		);
126
127
		printf(
128
			'<div class="%1$s"><p>%2$s</p></div>',
129
			esc_attr( $class ),
130
			wp_kses(
131
				$message,
132
				array(
133
					'a'      => array(
134
						'href' => true,
135
					),
136
					'code'   => array(),
137
					'strong' => array(),
138
				)
139
			)
140
		);
141
	}
142
143
	/**
144
	 * Get config factory class.
145
	 *
146
	 * @return string
147
	 */
148
	public function get_config_factory_class() {
149
		return __NAMESPACE__ . '\ConfigFactory';
150
	}
151
152
	/**
153
	 * Get settings fields.
154
	 *
155
	 * @return array
156
	 */
157
	public function get_settings_fields() {
158
		$fields = array();
159
160
		// Refresh Token.
161
		$fields[] = array(
162
			'section'  => 'general',
163
			'filter'   => FILTER_SANITIZE_STRING,
164
			'meta_key' => '_pronamic_gateway_omnikassa_2_refresh_token',
165
			'title'    => _x( 'Refresh Token', 'omnikassa', 'pronamic_ideal' ),
166
			'type'     => 'textarea',
167
			'classes'  => array( 'code' ),
168
		);
169
170
		// Signing Key.
171
		$fields[] = array(
172
			'section'  => 'general',
173
			'filter'   => FILTER_SANITIZE_STRING,
174
			'meta_key' => '_pronamic_gateway_omnikassa_2_signing_key',
175
			'title'    => _x( 'Signing Key', 'omnikassa', 'pronamic_ideal' ),
176
			'type'     => 'text',
177
			'classes'  => array( 'large-text', 'code' ),
178
		);
179
180
		// Purchase ID.
181
		$fields[] = array(
182
			'section'     => 'advanced',
183
			'filter'      => FILTER_SANITIZE_STRING,
184
			'meta_key'    => '_pronamic_gateway_omnikassa_2_order_id',
185
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
186
			'type'        => 'text',
187
			'classes'     => array( 'regular-text', 'code' ),
188
			'tooltip'     => sprintf(
189
				/* translators: %s: Parameter */
190
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
191
				sprintf( '<code>%s</code>', 'orderId' )
192
			),
193
			'description' => sprintf(
194
				'%s %s<br />%s',
195
				__( 'Available tags:', 'pronamic_ideal' ),
196
				sprintf(
197
					'<code>%s</code> <code>%s</code>',
198
					'{order_id}',
199
					'{payment_id}'
200
				),
201
				sprintf(
202
					/* translators: %s: {payment_id} */
203
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
204
					'{payment_id}'
205
				)
206
			),
207
		);
208
209
		// Webhook.
210
		$fields[] = array(
211
			'section'  => 'feedback',
212
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
213
			'type'     => 'text',
214
			'classes'  => array( 'large-text', 'code' ),
215
			'value'    => add_query_arg( 'omnikassa2_webhook', '', home_url( '/' ) ),
216
			'readonly' => true,
217
			'tooltip'  => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
218
		);
219
220
		return $fields;
221
	}
222
}
223