Test Failed
Push — develop ( 0087d3...a49019 )
by Reüel
12:40
created

src/Integration.php (2 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: OmniKassa integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.0
15
 * @since   1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	public function __construct() {
19
		$this->id            = 'rabobank-omnikassa';
20
		$this->name          = 'Rabobank - OmniKassa';
21
		$this->product_url   = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/';
22
		$this->dashboard_url = array(
23
			__( 'admin', 'pronamic_ideal' )    => 'https://dashboard.omnikassa.rabobank.nl/',
24
			__( 'download', 'pronamic_ideal' ) => 'https://download.omnikassa.rabobank.nl/',
25
		);
26
		$this->provider      = 'rabobank';
27
		$this->deprecated    = true;
0 ignored issues
show
Bug Best Practice introduced by
The property deprecated does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
29
		// Actions
30
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
31
32
		if ( ! has_action( 'wp_loaded', $function ) ) {
33
			add_action( 'wp_loaded', $function );
34
		}
35
	}
36
37
	/**
38
	 * Fields.
39
	 *
40
	 * @return array
41
	 */
42
	public function get_settings_fields() {
43
		$fields = array();
44
45
		// Merchant ID.
46
		$fields[] = array(
47
			'section'  => 'general',
48
			'filter'   => FILTER_SANITIZE_STRING,
49
			'meta_key' => '_pronamic_gateway_omnikassa_merchant_id',
50
			'title'    => __( 'Merchant ID', 'pronamic_ideal' ),
51
			'type'     => 'text',
52
			'classes'  => array( 'code' ),
53
		);
54
55
		// Secret Key..
56
		$fields[] = array(
57
			'section'  => 'general',
58
			'filter'   => FILTER_SANITIZE_STRING,
59
			'meta_key' => '_pronamic_gateway_omnikassa_secret_key',
60
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
61
			'type'     => 'text',
62
			'classes'  => array( 'large-text', 'code' ),
63
		);
64
65
		// Key Version.
66
		$fields[] = array(
67
			'section'     => 'general',
68
			'filter'      => FILTER_SANITIZE_STRING,
69
			'meta_key'    => '_pronamic_gateway_omnikassa_key_version',
70
			'title'       => __( 'Key Version', 'pronamic_ideal' ),
71
			'type'        => 'text',
72
			'classes'     => array( 'code' ),
73
			'size'        => 5,
74
			'description' => sprintf(
75
				/* translators: %s: dashboard URL */
76
				__(
77
					'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.',
78
					'pronamic_ideal'
79
				),
80
				'https://download.omnikassa.rabobank.nl/'
81
			),
82
		);
83
84
		// Purchase ID.
85
		$fields[] = array(
86
			'section'     => 'advanced',
87
			'filter'      => FILTER_SANITIZE_STRING,
88
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
89
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
90
			'type'        => 'text',
91
			'classes'     => array( 'regular-text', 'code' ),
92
			'tooltip'     => sprintf(
93
				/* translators: %s: <code>orderId</code> */
94
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
95
				sprintf( '<code>%s</code>', 'orderId' )
96
			),
97
			'description' => sprintf(
98
				'%s %s<br />%s',
99
				__( 'Available tags:', 'pronamic_ideal' ),
100
				sprintf(
101
					'<code>%s</code> <code>%s</code>',
102
					'{order_id}',
103
					'{payment_id}'
104
				),
105
				sprintf(
106
					/* translators: %s: {payment_id} */
107
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
108
					'{payment_id}'
109
				)
110
			),
111
		);
112
113
		return $fields;
114
	}
115
116
	public function get_config( $post_id ) {
117
		$config = new Config();
118
119
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
120
		$config->secret_key  = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_secret_key', true );
121
		$config->key_version = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_key_version', true );
122
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_order_id', true );
123
		$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...
124
125
		return $config;
126
	}
127
128
	/**
129
	 * Get gateway.
130
	 *
131
	 * @param int $post_id Post ID.
132
	 * @return Gateway
133
	 */
134
	public function get_gateway( $post_id ) {
135
		return new Gateway( $this->get_config( $post_id ) );
136
	}
137
}
138