Failed Conditions
Push — develop ( 6abeb3...763268 )
by Remco
06:45 queued 02:22
created

src/Integration.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Integration
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 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
		$screen = get_current_screen();
0 ignored issues
show
Are you sure the assignment to $screen is correct as get_current_screen() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
80
81
		if ( null === $screen ) {
82
			return;
83
		}
84
85
		if ( 'pronamic_gateway' !== $screen->id ) {
86
			return;
87
		}
88
89
		$host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
90
91
		if ( is_array( $host ) ) {
92
			return;
93
		}
94
95
		if ( '.test' !== substr( $host, -5 ) ) {
96
			return;
97
		}
98
99
		$post_id = get_the_ID();
100
101
		if ( empty( $post_id ) ) {
102
			return;
103
		}
104
105
		$gateway_id = get_post_meta( $post_id, '_pronamic_gateway_id', true );
106
107
		if ( 'rabobank-omnikassa-2' !== $gateway_id ) {
108
			return;
109
		}
110
111
		$class   = 'notice notice-error';
112
		$message = sprintf(
113
			/* translators: 1: Pronamic Pay, 2: Documentation link, 3: <code>.test</code> */
114
			__( '%1$s — <a href="%2$s">OmniKassa 2 does not accept payments from %3$s environments</a>.', 'pronamic_ideal' ),
115
			sprintf(
116
				'<strong>%s</strong>',
117
				__( 'Pronamic Pay', 'pronamic_ideal' )
118
			),
119
			'https://github.com/wp-pay-gateways/omnikassa-2/tree/develop/documentation#merchantreturnurl-is-not-a-valid-web-address',
120
			'<code>.test</code>'
121
		);
122
123
		printf(
124
			'<div class="%1$s"><p>%2$s</p></div>',
125
			esc_attr( $class ),
126
			wp_kses(
127
				$message,
128
				array(
129
					'a'      => array(
130
						'href' => true,
131
					),
132
					'code'   => array(),
133
					'strong' => array(),
134
				)
135
			)
136
		);
137
	}
138
139
	/**
140
	 * Get config factory class.
141
	 *
142
	 * @return string
143
	 */
144
	public function get_config_factory_class() {
145
		return __NAMESPACE__ . '\ConfigFactory';
146
	}
147
148
	/**
149
	 * Get settings class.
150
	 *
151
	 * @return string
152
	 */
153
	public function get_settings_class() {
154
		return __NAMESPACE__ . '\Settings';
155
	}
156
157
	/**
158
	 * Get required settings for this integration.
159
	 *
160
	 * @link https://github.com/wp-premium/gravityforms/blob/1.9.16/includes/fields/class-gf-field-multiselect.php#L21-L42
161
	 * @since 1.1.6
162
	 * @return array
163
	 */
164
	public function get_settings() {
165
		$settings = parent::get_settings();
166
167
		$settings[] = 'omnikassa-2';
168
169
		return $settings;
170
	}
171
}
172