Failed Conditions
Push — develop ( ae6d11...c6a3be )
by Reüel
07:54
created

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-2020 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
	 * Construct Buckaroo integration.
20
	 *
21
	 * @param array $args Arguments.
22
	 */
23
	public function __construct( $args = array() ) {
24
		$args = wp_parse_args(
25
			$args,
26
			array(
27
				'id'            => 'buckaroo',
28
				'name'          => 'Buckaroo - HTML',
29
				'url'           => 'https://plaza.buckaroo.nl/',
30
				'product_url'   => \__( 'http://www.buckaroo-payments.com', 'pronamic_ideal' ),
31
				'dashboard_url' => 'https://plaza.buckaroo.nl/',
32
				'provider'      => 'buckaroo',
33
				'supports'      => array(
34
					'webhook',
35
					'webhook_log',
36
					'webhook_no_config',
37
				),
38
				'manual_url'    => \__( 'https://www.pronamic.eu/support/how-to-connect-buckaroo-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ),
39
			)
40
		);
41
42
		parent::__construct( $args );
43
44
		// Actions
45
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
46
47
		if ( ! has_action( 'wp_loaded', $function ) ) {
48
			add_action( 'wp_loaded', $function );
49
		}
50
	}
51
52
	public function get_settings_fields() {
53
		$fields = array();
54
55
		// Website Key.
56
		$fields[] = array(
57
			'section'  => 'general',
58
			'filter'   => FILTER_SANITIZE_STRING,
59
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
60
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
61
			'type'     => 'text',
62
			'classes'  => array( 'code' ),
63
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
64
		);
65
66
		// Secret Key.
67
		$fields[] = array(
68
			'section'  => 'general',
69
			'filter'   => FILTER_SANITIZE_STRING,
70
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
71
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
72
			'type'     => 'text',
73
			'classes'  => array( 'regular-text', 'code' ),
74
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboardb on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
75
		);
76
77
		// Excluded services.
78
		$fields[] = array(
79
			'section'  => 'advanced',
80
			'filter'   => FILTER_SANITIZE_STRING,
81
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
82
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
83
			'type'     => 'text',
84
			'classes'  => array( 'regular-text', 'code' ),
85
			'tooltip'  => sprintf(
86
				/* translators: %s: <code>brq_parameter</code> */
87
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
88
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
89
			),
90
		);
91
92
		// Invoice number.
93
		$fields[] = array(
94
			'section'     => 'advanced',
95
			'filter'      => FILTER_SANITIZE_STRING,
96
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
97
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
98
			'type'        => 'text',
99
			'classes'     => array( 'regular-text', 'code' ),
100
			'tooltip'     => sprintf(
101
				/* translators: %s: <code>brq_parameter</code> */
102
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
103
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
104
			),
105
			'description' => sprintf(
106
				'%s<br />%s',
107
				/* translators: %s: <code>{tag}</code> */
108
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
109
				/* translators: %s: default code */
110
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
111
			),
112
		);
113
114
		// Push URL.
115
		$fields[] = array(
116
			'section'  => 'feedback',
117
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
118
			'type'     => 'text',
119
			'classes'  => array( 'large-text', 'code' ),
120
			'value'    => add_query_arg( 'buckaroo_push', '', home_url( '/' ) ),
121
			'readonly' => true,
122
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
123
		);
124
125
		return $fields;
126
	}
127
128
	public function get_config( $post_id ) {
129
		$config = new Config();
130
131
		$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...
132
		$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...
133
		$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...
134
		$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...
135
		$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...
136
137
		return $config;
138
	}
139
140
	/**
141
	 * Get gateway.
142
	 *
143
	 * @param int $post_id Post ID.
144
	 * @return Gateway
145
	 */
146
	public function get_gateway( $post_id ) {
147
		return new Gateway( $this->get_config( $post_id ) );
148
	}
149
}
150