Failed Conditions
Push — develop ( 990170...3692e7 )
by Remco
04:47
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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\EMS\ECommerce;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: EMS e-Commerce 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            = 'ems-ecommerce';
20
		$this->name          = 'EMS e-Commerce';
21
		$this->product_url   = '';
22
		$this->dashboard_url = array(
23
			__( 'test', 'pronamic_ideal' ) => 'https://test.ipg-online.com/vt/login',
24
			__( 'live', 'pronamic_ideal' ) => 'https://www.ipg-online.com/vt/login',
25
		);
26
		$this->provider      = 'ems';
27
		$this->supports      = array(
0 ignored issues
show
Bug Best Practice introduced by
The property supports does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
			'webhook',
29
			'webhook_no_config',
30
		);
31
32
		// Actions
33
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
34
35
		if ( ! has_action( 'wp_loaded', $function ) ) {
36
			add_action( 'wp_loaded', $function );
37
		}
38
	}
39
40
	public function get_settings_fields() {
41
		$fields = array();
42
43
		// Storename.
44
		$fields[] = array(
45
			'section'  => 'general',
46
			'filter'   => FILTER_UNSAFE_RAW,
47
			'meta_key' => '_pronamic_gateway_ems_ecommerce_storename',
48
			'title'    => _x( 'Storename', 'ems', 'pronamic_ideal' ),
49
			'type'     => 'text',
50
			'classes'  => array( 'code' ),
51
		);
52
53
		// Shared secret.
54
		$fields[] = array(
55
			'section'  => 'general',
56
			'filter'   => FILTER_UNSAFE_RAW,
57
			'meta_key' => '_pronamic_gateway_ems_ecommerce_secret',
58
			'title'    => _x( 'Shared Secret', 'ems', 'pronamic_ideal' ),
59
			'type'     => 'text',
60
			'classes'  => array( 'large-text', 'code' ),
61
		);
62
63
		// Purchase ID.
64
		$fields[] = array(
65
			'section'  => 'advanced',
66
			'filter'      => array(
67
				'filter' => FILTER_SANITIZE_STRING,
68
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
69
			),
70
			'meta_key'    => '_pronamic_gateway_ems_ecommerce_order_id',
71
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
72
			'type'        => 'text',
73
			'classes'     => array( 'regular-text', 'code' ),
74
			'tooltip'     => sprintf(
75
				/* translators: %s: <code>{orderId}</code> */
76
				__( 'The EMS e-Commerce %s parameter.', 'pronamic_ideal' ),
77
				sprintf( '<code>%s</code>', 'orderId' )
78
			),
79
			'description' => sprintf(
80
				'%s %s<br />%s',
81
				__( 'Available tags:', 'pronamic_ideal' ),
82
				sprintf(
83
					'<code>%s</code> <code>%s</code>',
84
					'{order_id}',
85
					'{payment_id}'
86
				),
87
				sprintf(
88
					/* translators: %s: {order_id} */
89
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
90
					'{order_id}'
91
				)
92
			),
93
		);
94
95
		// Notification URL.
96
		$fields[] = array(
97
			'section'  => 'feedback',
98
			'title'    => __( 'Notification URL', 'pronamic_ideal' ),
99
			'type'     => 'text',
100
			'classes'  => array( 'large-text', 'code' ),
101
			'value'    => home_url( '/' ),
102
			'readonly' => true,
103
			'tooltip'  => __(
104
				'The Notification URL as sent with each transaction to receive automatic payment status updates on.',
105
				'pronamic_ideal'
106
			),
107
		);
108
109
		return $fields;
110
	}
111
112
	public function get_config( $post_id ) {
113
		$config = new Config();
114
115
		$config->storename = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_storename', true );
116
		$config->secret    = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_secret', true );
117
		$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...
118
		$config->order_id  = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_order_id', true );
119
120
		return $config;
121
	}
122
123
	/**
124
	 * Get gateway.
125
	 *
126
	 * @param int $post_id Post ID.
127
	 * @return Gateway
128
	 */
129
	public function get_gateway( $post_id ) {
130
		return new Gateway( $this->get_config( $post_id ) );
131
	}
132
}
133