Issues (8)

src/Integration.php (4 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\EMS\ECommerce;
4
5
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
6
7
/**
8
 * Title: EMS e-Commerce integration
9
 * Description:
10
 * Copyright: 2005-2022 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.1.1
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractGatewayIntegration {
18
	/**
19
	 * Construct EMS e-Commerce 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'            => 'ems-ecommerce',
28
				'name'          => 'EMS e-Commerce',
29
				'provider'      => 'ems',
30
				'product_url'   => null,
31
				'dashboard_url' => array(
32
					\__( 'test', 'pronamic_ideal' ) => 'https://test.ipg-online.com/vt/login',
33
					\__( 'live', 'pronamic_ideal' ) => 'https://www.ipg-online.com/vt/login',
34
				),
35
				'supports'      => array(
36
					'webhook',
37
					'webhook_log',
38
					'webhook_no_config',
39
				),
40
				'manual_url'    => \__( 'https://www.pronamic.eu/support/how-to-connect-ems-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ),
41
			)
42
		);
43
44
		parent::__construct( $args );
45
46
		// Actions
47
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
48
49
		if ( ! has_action( 'wp_loaded', $function ) ) {
50
			add_action( 'wp_loaded', $function );
51
		}
52
	}
53
54
	/**
55
	 * Get settings fields.
56
	 *
57
	 * @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
58
	 */
59
	public function get_settings_fields() {
60
		$fields = array();
61
62
		// Storename.
63
		$fields[] = array(
64
			'section'  => 'general',
65
			'filter'   => FILTER_UNSAFE_RAW,
66
			'meta_key' => '_pronamic_gateway_ems_ecommerce_storename',
67
			'title'    => _x( 'Storename', 'ems', 'pronamic_ideal' ),
68
			'type'     => 'text',
69
			'classes'  => array( 'code' ),
70
		);
71
72
		// Shared secret.
73
		$fields[] = array(
74
			'section'  => 'general',
75
			'filter'   => FILTER_UNSAFE_RAW,
76
			'meta_key' => '_pronamic_gateway_ems_ecommerce_secret',
77
			'title'    => _x( 'Shared Secret', 'ems', 'pronamic_ideal' ),
78
			'type'     => 'text',
79
			'classes'  => array( 'large-text', 'code' ),
80
		);
81
82
		// Purchase ID.
83
		$fields[] = array(
84
			'section'     => 'advanced',
85
			'filter'      => array(
86
				'filter' => FILTER_SANITIZE_STRING,
87
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
88
			),
89
			'meta_key'    => '_pronamic_gateway_ems_ecommerce_order_id',
90
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
91
			'type'        => 'text',
92
			'classes'     => array( 'regular-text', 'code' ),
93
			'tooltip'     => sprintf(
94
				/* translators: %s: <code>{orderId}</code> */
95
				__( 'The EMS e-Commerce %s parameter.', 'pronamic_ideal' ),
96
				sprintf( '<code>%s</code>', 'orderId' )
97
			),
98
			'description' => sprintf(
99
				'%s %s<br />%s',
100
				__( 'Available tags:', 'pronamic_ideal' ),
101
				sprintf(
102
					'<code>%s</code> <code>%s</code>',
103
					'{order_id}',
104
					'{payment_id}'
105
				),
106
				sprintf(
107
					/* translators: %s: default code */
108
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
109
					'{payment_id}'
110
				)
111
			),
112
		);
113
114
		// Notification URL.
115
		$fields[] = array(
116
			'section'  => 'feedback',
117
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
118
			'title'    => _x( 'Notification URL', 'EMS e-Commerce', 'pronamic_ideal' ),
119
			'type'     => 'text',
120
			'classes'  => array( 'large-text', 'code' ),
121
			'value'    => home_url( '/' ),
122
			'readonly' => true,
123
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
124
			'tooltip'  => _x(
125
				'The Notification URL as sent with each transaction to receive automatic payment status updates on.',
126
				'EMS e-Commerce',
127
				'pronamic_ideal'
128
			),
129
		);
130
131
		return $fields;
132
	}
133
134
	/**
135
	 * Get configuration by post ID.
136
	 *
137
	 * @param int $post_id Post ID.
138
	 * @return Config
139
	 */
140
	public function get_config( $post_id ) {
141
		$config = new Config();
142
143
		$config->storename = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_storename', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...merce_storename', true) can also be of type false. However, the property $storename is declared as type null|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...
144
		$config->secret    = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_secret', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...commerce_secret', true) can also be of type false. However, the property $secret is declared as type null|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...
145
		$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...
146
		$config->order_id  = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_order_id', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...mmerce_order_id', true) can also be of type false. However, the property $order_id is declared as type null|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...
147
148
		return $config;
149
	}
150
151
	/**
152
	 * Get gateway.
153
	 *
154
	 * @param int $post_id Post ID.
155
	 * @return Gateway
156
	 */
157
	public function get_gateway( $post_id ) {
158
		return new Gateway( $this->get_config( $post_id ) );
159
	}
160
}
161