Failed Conditions
Push — master ( 38e531...0224ca )
by Remco
15:22 queued 07:16
created

Integration::get_gateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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( __( 'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.', 'pronamic_ideal' ), 'https://download.omnikassa.rabobank.nl/' ),
87
		);
88
89
		// Purchase ID
90
		$fields[] = array(
91
			'section'     => 'advanced',
92
			'filter'      => FILTER_SANITIZE_STRING,
93
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
94
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
95
			'type'        => 'text',
96
			'classes'     => array( 'regular-text', 'code' ),
97
			'tooltip'     => sprintf(
98
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
99
				sprintf( '<code>%s</code>', 'orderId' )
100
			),
101
			'description' => sprintf(
102
				'%s %s<br />%s',
103
				__( 'Available tags:', 'pronamic_ideal' ),
104
				sprintf(
105
					'<code>%s</code> <code>%s</code>',
106
					'{order_id}',
107
					'{payment_id}'
108
				),
109
				sprintf(
110
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
111
					'{payment_id}'
112
				)
113
			),
114
		);
115
116
		return $fields;
117
	}
118
119
	public function get_config( $post_id ) {
120
		$config = new Config();
121
122
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
123
		$config->secret_key  = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_secret_key', true );
124
		$config->key_version = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_key_version', true );
125
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_order_id', true );
126
		$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...
127
128
		return $config;
129
	}
130
131
	/**
132
	 * Get gateway.
133
	 *
134
	 * @param int $post_id Post ID.
135
	 * @return Gateway
136
	 */
137
	public function get_gateway( $post_id ) {
138
		return new Gateway( $this->get_config( $post_id ) );
139
	}
140
}
141