Failed Conditions
Push — develop ( fc7b68...4eeca8 )
by Reüel
05:13
created

src/Integration.php (5 issues)

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