Failed Conditions
Push — develop ( 057d72...1c4468 )
by Remco
21:12 queued 16:59
created

src/Integration.php (1 issue)

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-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.0
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
		// Actions
32
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
33
34
		if ( ! has_action( 'wp_loaded', $function ) ) {
35
			add_action( 'wp_loaded', $function );
36
		}
37
	}
38
39
	public function get_settings_fields() {
40
		$fields = array();
41
42
		// Website Key.
43
		$fields[] = array(
44
			'section'  => 'general',
45
			'filter'   => FILTER_SANITIZE_STRING,
46
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
47
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
48
			'type'     => 'text',
49
			'classes'  => array( 'code' ),
50
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
51
		);
52
53
		// Secret Key.
54
		$fields[] = array(
55
			'section'  => 'general',
56
			'filter'   => FILTER_SANITIZE_STRING,
57
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
58
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
59
			'type'     => 'text',
60
			'classes'  => array( 'regular-text', 'code' ),
61
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboardb on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
62
		);
63
64
		// Excluded services.
65
		$fields[] = array(
66
			'section'  => 'advanced',
67
			'filter'   => FILTER_SANITIZE_STRING,
68
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
69
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
70
			'type'     => 'text',
71
			'classes'  => array( 'regular-text', 'code' ),
72
			'tooltip'  => sprintf(
73
				/* translators: %s: <code>brq_exludedservices</code> */
74
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
75
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
76
			),
77
		);
78
79
		// Invoice number.
80
		$fields[] = array(
81
			'section'     => 'advanced',
82
			'filter'      => FILTER_SANITIZE_STRING,
83
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
84
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
85
			'type'        => 'text',
86
			'classes'     => array( 'regular-text', 'code' ),
87
			'tooltip'     => sprintf(
88
				/* translators: %s: <code>brq_invoicenumber</code> */
89
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
90
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
91
			),
92
			'description' => sprintf(
93
				'%s<br />%s',
94
				/* translators: %s: <code>{order_id}</code> <code>{payment_id}</code> */
95
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
96
				/* translators: %s: <code>{payment_id}</code> */
97
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
98
			),
99
		);
100
101
		// Push URL.
102
		$fields[] = array(
103
			'section'  => 'feedback',
104
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
105
			'type'     => 'text',
106
			'classes'  => array( 'large-text', 'code' ),
107
			'value'    => add_query_arg( 'buckaroo_push', '', home_url( '/' ) ),
108
			'readonly' => true,
109
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
110
		);
111
112
		return $fields;
113
	}
114
115
	public function get_config( $post_id ) {
116
		$config = new Config();
117
118
		$config->website_key       = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true );
119
		$config->secret_key        = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true );
120
		$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true );
121
		$config->invoice_number    = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true );
122
		$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...
123
124
		return $config;
125
	}
126
127
	/**
128
	 * Get gateway.
129
	 *
130
	 * @param int $post_id Post ID.
131
	 * @return Gateway
132
	 */
133
	public function get_gateway( $post_id ) {
134
		return new Gateway( $this->get_config( $post_id ) );
135
	}
136
}
137