Failed Conditions
Push — develop ( edbb50...772119 )
by Reüel
06:34
created

src/Integration.php (1 issue)

Labels
Severity
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.8
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
		$this->supports      = array(
33
			'webhook',
34
			'webhook_log',
35
		);
36
37
		$this->set_manual_url( \__( 'https://www.pronamic.eu/support/how-to-connect-rabo-omnikassa-2-0-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) );
0 ignored issues
show
The method set_manual_url() does not exist on Pronamic\WordPress\Pay\G...\OmniKassa2\Integration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
		$this->/** @scrutinizer ignore-call */ 
38
         set_manual_url( \__( 'https://www.pronamic.eu/support/how-to-connect-rabo-omnikassa-2-0-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
		/**
40
		 * Webhook listener function.
41
		 *
42
		 * @var callable $webhook_listener_function
43
		 */
44
		$webhook_listener_function = array( __NAMESPACE__ . '\WebhookListener', 'listen' );
45
46
		if ( ! \has_action( 'wp_loaded', $webhook_listener_function ) ) {
47
			\add_action( 'wp_loaded', $webhook_listener_function );
48
		}
49
50
		/**
51
		 * Save post.
52
		 *
53
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736
54
		 * @var callable $delete_access_token_meta_function
55
		 */
56
		$delete_access_token_meta_function = array( $this, 'delete_access_token_meta' );
57
58
		if ( ! \has_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function ) ) {
59
			\add_action( 'save_post_pronamic_gateway', $delete_access_token_meta_function );
60
		}
61
62
		/**
63
		 * Admin notices.
64
		 *
65
		 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
66
		 * @var callable $admin_notices_function
67
		 */
68
		$admin_notices_function = array( $this, 'admin_notice_tld_test' );
69
70
		if ( ! \has_action( 'admin_notices', $admin_notices_function ) ) {
71
			\add_action( 'admin_notices', $admin_notices_function );
72
		}
73
	}
74
75
	/**
76
	 * Admin notice TLD .test.
77
	 *
78
	 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-admin/admin-header.php#L259-L264
79
	 * @link https://developer.wordpress.org/reference/hooks/admin_notices/
80
	 * @link https://developer.wordpress.org/reference/functions/get_current_screen/
81
	 */
82
	public function admin_notice_tld_test() {
83
		if ( \has_filter( 'pronamic_pay_omnikassa_2_merchant_return_url' ) ) {
84
			return;
85
		}
86
87
		$screen = \get_current_screen();
88
89
		if ( null === $screen ) {
90
			return;
91
		}
92
93
		if ( 'pronamic_gateway' !== $screen->id ) {
94
			return;
95
		}
96
97
		$host = \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST );
98
99
		if ( \is_array( $host ) ) {
100
			return;
101
		}
102
103
		if ( '.test' !== \substr( $host, -5 ) ) {
104
			return;
105
		}
106
107
		$post_id = \get_the_ID();
108
109
		if ( empty( $post_id ) ) {
110
			return;
111
		}
112
113
		$gateway_id = \get_post_meta( $post_id, '_pronamic_gateway_id', true );
114
115
		if ( 'rabobank-omnikassa-2' !== $gateway_id ) {
116
			return;
117
		}
118
119
		$class   = 'notice notice-error';
120
		$message = \sprintf(
121
			/* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */
122
			\__( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ),
123
			\sprintf(
124
				'<strong>%s</strong>',
125
				\__( 'Pronamic Pay', 'pronamic_ideal' )
126
			),
127
			'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address',
128
			'<code>.test</code>'
129
		);
130
131
		\printf(
132
			'<div class="%1$s"><p>%2$s</p></div>',
133
			\esc_attr( $class ),
134
			\wp_kses(
135
				$message,
136
				array(
137
					'a'      => array(
138
						'href' => true,
139
					),
140
					'code'   => array(),
141
					'strong' => array(),
142
				)
143
			)
144
		);
145
	}
146
147
	/**
148
	 * Get settings fields.
149
	 *
150
	 * @return array<int, array<string, array<int, string>|int|string|true>>
151
	 */
152
	public function get_settings_fields() {
153
		$fields = array();
154
155
		// Refresh Token.
156
		$fields[] = array(
157
			'section'  => 'general',
158
			'filter'   => \FILTER_SANITIZE_STRING,
159
			'meta_key' => '_pronamic_gateway_omnikassa_2_refresh_token',
160
			'title'    => \_x( 'Refresh Token', 'omnikassa', 'pronamic_ideal' ),
161
			'type'     => 'textarea',
162
			'classes'  => array( 'code' ),
163
		);
164
165
		// Signing Key.
166
		$fields[] = array(
167
			'section'  => 'general',
168
			'filter'   => \FILTER_SANITIZE_STRING,
169
			'meta_key' => '_pronamic_gateway_omnikassa_2_signing_key',
170
			'title'    => \_x( 'Signing Key', 'omnikassa', 'pronamic_ideal' ),
171
			'type'     => 'text',
172
			'classes'  => array( 'large-text', 'code' ),
173
		);
174
175
		// Purchase ID.
176
		$code_field = \sprintf( '<code>%s</code>', 'merchantOrderId' );
177
178
		$fields[] = array(
179
			'section'     => 'advanced',
180
			'filter'      => \FILTER_SANITIZE_STRING,
181
			'meta_key'    => '_pronamic_gateway_omnikassa_2_order_id',
182
			'title'       => \__( 'Order ID', 'pronamic_ideal' ),
183
			'type'        => 'text',
184
			'classes'     => array( 'regular-text', 'code' ),
185
			'tooltip'     => \sprintf(
186
				/* translators: %s: <code>merchantOrderId</code> */
187
				\__( 'This setting defines the OmniKassa 2.0 %s field.', 'pronamic_ideal' ),
188
				$code_field
189
			),
190
			'description' => \sprintf(
191
				'%s<br />%s %s<br />%s',
192
				\sprintf(
193
					/* translators: %s: <code>merchantOrderId</code> */
194
					\__( 'The OmniKassa 2.0 %s field must consist strictly of 24 alphanumeric characters, other characters, such as ".", "@", " " (space), etc. are not allowed.', 'pronamic_ideal' ),
195
					$code_field
196
				),
197
				\__( 'Available tags:', 'pronamic_ideal' ),
198
				\sprintf(
199
					'<code>%s</code> <code>%s</code>',
200
					'{order_id}',
201
					'{payment_id}'
202
				),
203
				\sprintf(
204
					/* translators: %s: {payment_id} */
205
					\__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
206
					'{payment_id}'
207
				)
208
			),
209
		);
210
211
		// Webhook.
212
		$fields[] = array(
213
			'section'  => 'feedback',
214
			'title'    => \__( 'Webhook URL', 'pronamic_ideal' ),
215
			'type'     => 'text',
216
			'classes'  => array( 'large-text', 'code' ),
217
			'value'    => \add_query_arg( 'omnikassa2_webhook', '', \home_url( '/' ) ),
218
			'readonly' => true,
219
			'tooltip'  => \__( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
220
		);
221
222
		return $fields;
223
	}
224
225
	/**
226
	 * Get configuration by post ID.
227
	 *
228
	 * @param int $post_id Post ID.
229
	 * @return Config
230
	 */
231
	public function get_config( $post_id ) {
232
		$config = new Config();
233
234
		$config->post_id                  = \intval( $post_id );
235
		$config->mode                     = $this->get_meta( $post_id, 'mode' );
236
		$config->refresh_token            = $this->get_meta( $post_id, 'omnikassa_2_refresh_token' );
237
		$config->signing_key              = $this->get_meta( $post_id, 'omnikassa_2_signing_key' );
238
		$config->access_token             = $this->get_meta( $post_id, 'omnikassa_2_access_token' );
239
		$config->access_token_valid_until = $this->get_meta( $post_id, 'omnikassa_2_access_token_valid_until' );
240
		$config->order_id                 = $this->get_meta( $post_id, 'omnikassa_2_order_id' );
241
242
		return $config;
243
	}
244
245
	/**
246
	 * Delete access token meta for the specified post ID.
247
	 *
248
	 * @link https://github.com/WordPress/WordPress/blob/5.0/wp-includes/post.php#L3724-L3736
249
	 * @link https://codex.wordpress.org/Function_Reference/delete_post_meta
250
	 * @param int $post_id Post ID.
251
	 */
252
	public static function delete_access_token_meta( $post_id ) {
253
		\delete_post_meta( $post_id, '_pronamic_gateway_omnikassa_2_access_token' );
254
		\delete_post_meta( $post_id, '_pronamic_gateway_omnikassa_2_access_token_valid_until' );
255
	}
256
257
	/**
258
	 * Get gateway.
259
	 *
260
	 * @param int $post_id Post ID.
261
	 * @return Gateway
262
	 */
263
	public function get_gateway( $post_id ) {
264
		return new Gateway( $this->get_config( $post_id ) );
265
	}
266
}
267