Issues (12)

src/Integration.php (5 issues)

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-2022 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
					'payment_status_request',
42
					'refunds',
43
					'webhook',
44
					'webhook_log',
45
					'webhook_no_config',
46
				),
47
				'manual_url'    => \__( 'https://www.pronamic.eu/support/how-to-connect-buckaroo-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ),
48
			)
49
		);
50
51
		parent::__construct( $args );
52
53
		/**
54
		 * CLI.
55
		 *
56
		 * @link https://github.com/woocommerce/woocommerce/blob/3.9.0/includes/class-woocommerce.php#L453-L455
57
		 */
58
		if ( defined( 'WP_CLI' ) && WP_CLI ) {
59
			new CLI( $this );
60
		}
61
	}
62
63
	/**
64
	 * Setup.
65
	 */
66
	public function setup() {
67
		\add_filter(
68
			'pronamic_gateway_configuration_display_value_' . $this->get_id(),
69
			array( $this, 'gateway_configuration_display_value' ),
70
			10,
71
			2
72
		);
73
74
		// Push controller.
75
		$push_controller = new PushController();
76
77
		$push_controller->setup();
78
	}
79
80
	/**
81
	 * Gateway configuration display value.
82
	 *
83
	 * @param string $display_value Display value.
84
	 * @param int    $post_id       Gateway configuration post ID.
85
	 * @return string
86
	 */
87
	public function gateway_configuration_display_value( $display_value, $post_id ) {
88
		$config = $this->get_config( $post_id );
89
90
		return (string) $config->website_key;
91
	}
92
93
	/**
94
	 * Get settings fields.
95
	 *
96
	 * @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
97
	 */
98
	public function get_settings_fields() {
99
		$fields = array();
100
101
		// Website Key.
102
		$fields[] = array(
103
			'section'  => 'general',
104
			'filter'   => FILTER_SANITIZE_STRING,
105
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
106
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
107
			'type'     => 'text',
108
			'classes'  => array( 'code' ),
109
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
110
		);
111
112
		// Secret Key.
113
		$fields[] = array(
114
			'section'  => 'general',
115
			'filter'   => FILTER_SANITIZE_STRING,
116
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
117
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
118
			'type'     => 'text',
119
			'classes'  => array( 'regular-text', 'code' ),
120
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboard on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
121
		);
122
123
		// Excluded services.
124
		$fields[] = array(
125
			'section'  => 'advanced',
126
			'filter'   => FILTER_SANITIZE_STRING,
127
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
128
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
129
			'type'     => 'text',
130
			'classes'  => array( 'regular-text', 'code' ),
131
			'tooltip'  => sprintf(
132
				/* translators: %s: <code>brq_parameter</code> */
133
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
134
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
135
			),
136
		);
137
138
		// Invoice number.
139
		$fields[] = array(
140
			'section'     => 'advanced',
141
			'filter'      => FILTER_SANITIZE_STRING,
142
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
143
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
144
			'type'        => 'text',
145
			'classes'     => array( 'regular-text', 'code' ),
146
			'tooltip'     => sprintf(
147
				/* translators: %s: <code>brq_parameter</code> */
148
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
149
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
150
			),
151
			'description' => sprintf(
152
				'%s<br />%s',
153
				/* translators: %s: <code>{tag}</code> */
154
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
155
				/* translators: %s: default code */
156
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
157
			),
158
		);
159
160
		// Push URL.
161
		$fields[] = array(
162
			'section'  => 'feedback',
163
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
164
			'type'     => 'text',
165
			'classes'  => array( 'large-text', 'code' ),
166
			'value'    => \rest_url( self::REST_ROUTE_NAMESPACE . '/push' ),
167
			'readonly' => true,
168
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
169
		);
170
171
		return $fields;
172
	}
173
174
	/**
175
	 * Get config.
176
	 *
177
	 * @param int $post_id Gateway config post ID.
178
	 *
179
	 * @return Config
180
	 */
181
	public function get_config( $post_id ) {
182
		$config = new Config();
183
184
		$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...
185
		$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...
186
		$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...
187
		$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...
188
		$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...
189
190
		return $config;
191
	}
192
193
	/**
194
	 * Get gateway.
195
	 *
196
	 * @param int $post_id Post ID.
197
	 * @return Gateway
198
	 */
199
	public function get_gateway( $post_id ) {
200
		return new Gateway( $this->get_config( $post_id ) );
201
	}
202
}
203