Failed Conditions
Push — develop ( 46d4a4...6f5241 )
by Reüel
07:19 queued 11s
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.3
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
	 * Get settings 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( __( 'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.', 'pronamic_ideal' ), 'https://download.omnikassa.rabobank.nl/' ),
75
		);
76
77
		// Purchase ID
78
		$fields[] = array(
79
			'section'     => 'advanced',
80
			'filter'      => FILTER_SANITIZE_STRING,
81
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
82
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
83
			'type'        => 'text',
84
			'classes'     => array( 'regular-text', 'code' ),
85
			'tooltip'     => sprintf(
86
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
87
				sprintf( '<code>%s</code>', 'orderId' )
88
			),
89
			'description' => sprintf(
90
				'%s %s<br />%s',
91
				__( 'Available tags:', 'pronamic_ideal' ),
92
				sprintf(
93
					'<code>%s</code> <code>%s</code>',
94
					'{order_id}',
95
					'{payment_id}'
96
				),
97
				sprintf(
98
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
99
					'{payment_id}'
100
				)
101
			),
102
		);
103
104
		return $fields;
105
	}
106
107
	public function get_config( $post_id ) {
108
		$config = new Config();
109
110
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
111
		$config->secret_key  = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_secret_key', true );
112
		$config->key_version = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_key_version', true );
113
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_order_id', true );
114
		$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...
115
116
		return $config;
117
	}
118
119
	/**
120
	 * Get gateway.
121
	 *
122
	 * @param int $post_id Post ID.
123
	 * @return Gateway
124
	 */
125
	public function get_gateway( $post_id ) {
126
		return new Gateway( $this->get_config( $post_id ) );
127
	}
128
}
129