Failed Conditions
Push — feature/json-api ( 16ac3f...a04173 )
by Remco
06:07
created

Integration::gateway_configuration_display_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo;
4
5
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
6
7
/**
8
 * Title: Buckaroo integration
9
 * Description:
10
 * Copyright: 2005-2021 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.4
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractGatewayIntegration {
18
	/**
19
	 * REST route namespace.
20
	 *
21
	 * @var string
22
	 */
23
	const REST_ROUTE_NAMESPACE = 'pronamic-pay/buckaroo/v1';
24
25
	/**
26
	 * Construct Buckaroo integration.
27
	 *
28
	 * @param array $args Arguments.
29
	 */
30
	public function __construct( $args = array() ) {
31
		$args = wp_parse_args(
32
			$args,
33
			array(
34
				'id'            => 'buckaroo',
35
				'name'          => 'Buckaroo',
36
				'url'           => 'https://plaza.buckaroo.nl/',
37
				'product_url'   => \__( 'http://www.buckaroo-payments.com', 'pronamic_ideal' ),
38
				'dashboard_url' => 'https://plaza.buckaroo.nl/',
39
				'provider'      => 'buckaroo',
40
				'supports'      => array(
41
					'webhook',
42
					'webhook_log',
43
					'webhook_no_config',
44
				),
45
				'manual_url'    => \__( 'https://www.pronamic.eu/support/how-to-connect-buckaroo-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ),
46
			)
47
		);
48
49
		parent::__construct( $args );
50
51
		// Actions
52
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
53
54
		if ( ! has_action( 'wp_loaded', $function ) ) {
55
			add_action( 'wp_loaded', $function );
56
		}
57
	}
58
59
	/**
60
	 * Setup.
61
	 */
62
	public function setup() {
63
		\add_filter(
64
			'pronamic_gateway_configuration_display_value_' . $this->get_id(),
65
			array( $this, 'gateway_configuration_display_value' ),
66
			10,
67
			2
68
		);
69
70
		// Push controller.
71
		$push_controller = new PushController();
72
73
		$push_controller->setup();
74
	}
75
76
	/**
77
	 * Gateway configuration display value.
78
	 *
79
	 * @param string $display_value Display value.
80
	 * @param int    $post_id       Gateway configuration post ID.
81
	 * @return string
82
	 */
83
	public function gateway_configuration_display_value( $display_value, $post_id ) {
84
		$config = $this->get_config( $post_id );
85
86
		$display_value = $config->website_key;
87
88
		return $display_value;
89
	}
90
91
	/**
92
	 * Get settings fields.
93
	 *
94
	 * @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
95
	 */
96
	public function get_settings_fields() {
97
		$fields = array();
98
99
		// Website Key.
100
		$fields[] = array(
101
			'section'  => 'general',
102
			'filter'   => FILTER_SANITIZE_STRING,
103
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
104
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
105
			'type'     => 'text',
106
			'classes'  => array( 'code' ),
107
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
108
		);
109
110
		// Secret Key.
111
		$fields[] = array(
112
			'section'  => 'general',
113
			'filter'   => FILTER_SANITIZE_STRING,
114
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
115
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
116
			'type'     => 'text',
117
			'classes'  => array( 'regular-text', 'code' ),
118
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboard on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
119
		);
120
121
		// Excluded services.
122
		$fields[] = array(
123
			'section'  => 'advanced',
124
			'filter'   => FILTER_SANITIZE_STRING,
125
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
126
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
127
			'type'     => 'text',
128
			'classes'  => array( 'regular-text', 'code' ),
129
			'tooltip'  => sprintf(
130
				/* translators: %s: <code>brq_parameter</code> */
131
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
132
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
133
			),
134
		);
135
136
		// Invoice number.
137
		$fields[] = array(
138
			'section'     => 'advanced',
139
			'filter'      => FILTER_SANITIZE_STRING,
140
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
141
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
142
			'type'        => 'text',
143
			'classes'     => array( 'regular-text', 'code' ),
144
			'tooltip'     => sprintf(
145
				/* translators: %s: <code>brq_parameter</code> */
146
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
147
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
148
			),
149
			'description' => sprintf(
150
				'%s<br />%s',
151
				/* translators: %s: <code>{tag}</code> */
152
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
153
				/* translators: %s: default code */
154
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
155
			),
156
		);
157
158
		// Push URL.
159
		$fields[] = array(
160
			'section'  => 'feedback',
161
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
162
			'type'     => 'text',
163
			'classes'  => array( 'large-text', 'code' ),
164
			'value'    => add_query_arg( 'buckaroo_push', '', home_url( '/' ) ),
165
			'readonly' => true,
166
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
167
		);
168
169
		return $fields;
170
	}
171
172
	/**
173
	 * Get config.
174
	 *
175
	 * @param int $post_id Gateway config post ID.
176
	 *
177
	 * @return Config
178
	 */
179
	public function get_config( $post_id ) {
180
		$config = new Config();
181
182
		$config->website_key       = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...roo_website_key', true) can also be of type false. However, the property $website_key is declared as type null|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
183
		$config->secret_key        = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...aroo_secret_key', true) can also be of type false. However, the property $secret_key is declared as type null|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
184
		$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...cluded_services', true) can also be of type false. However, the property $excluded_services is declared as type null|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
185
		$config->invoice_number    = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ..._invoice_number', true) can also be of type false. However, the property $invoice_number is declared as type null|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
186
		$config->mode              = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...ic_gateway_mode', true) can also be of type false. However, the property $mode is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
187
188
		return $config;
189
	}
190
191
	/**
192
	 * Get gateway.
193
	 *
194
	 * @param int $post_id Post ID.
195
	 * @return Gateway
196
	 */
197
	public function get_gateway( $post_id ) {
198
		return new Gateway( $this->get_config( $post_id ) );
199
	}
200
}
201