Issues (9)

src/Integration.php (1 issue)

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