Failed Conditions
Push — develop ( 4503bb...9b582e )
by Reüel
12:02
created

src/Integration.php (2 issues)

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.3
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->manual_url    = __( 'https://www.pronamic.eu/support/how-to-connect-ems-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' );
0 ignored issues
show
Bug Best Practice introduced by
The property manual_url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
		$this->dashboard_url = array(
24
			__( 'test', 'pronamic_ideal' ) => 'https://test.ipg-online.com/vt/login',
25
			__( 'live', 'pronamic_ideal' ) => 'https://www.ipg-online.com/vt/login',
26
		);
27
		$this->provider      = 'ems';
28
		$this->supports      = array(
29
			'webhook',
30
			'webhook_log',
31
			'webhook_no_config',
32
		);
33
34
		// Actions
35
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
36
37
		if ( ! has_action( 'wp_loaded', $function ) ) {
38
			add_action( 'wp_loaded', $function );
39
		}
40
	}
41
42
	public function get_settings_fields() {
43
		$fields = array();
44
45
		// Storename.
46
		$fields[] = array(
47
			'section'  => 'general',
48
			'filter'   => FILTER_UNSAFE_RAW,
49
			'meta_key' => '_pronamic_gateway_ems_ecommerce_storename',
50
			'title'    => _x( 'Storename', 'ems', 'pronamic_ideal' ),
51
			'type'     => 'text',
52
			'classes'  => array( 'code' ),
53
		);
54
55
		// Shared secret.
56
		$fields[] = array(
57
			'section'  => 'general',
58
			'filter'   => FILTER_UNSAFE_RAW,
59
			'meta_key' => '_pronamic_gateway_ems_ecommerce_secret',
60
			'title'    => _x( 'Shared Secret', 'ems', 'pronamic_ideal' ),
61
			'type'     => 'text',
62
			'classes'  => array( 'large-text', 'code' ),
63
		);
64
65
		// Purchase ID.
66
		$fields[] = array(
67
			'section'     => 'advanced',
68
			'filter'      => array(
69
				'filter' => FILTER_SANITIZE_STRING,
70
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
71
			),
72
			'meta_key'    => '_pronamic_gateway_ems_ecommerce_order_id',
73
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
74
			'type'        => 'text',
75
			'classes'     => array( 'regular-text', 'code' ),
76
			'tooltip'     => sprintf(
77
				/* translators: %s: <code>{orderId}</code> */
78
				__( 'The EMS e-Commerce %s parameter.', 'pronamic_ideal' ),
79
				sprintf( '<code>%s</code>', 'orderId' )
80
			),
81
			'description' => sprintf(
82
				'%s %s<br />%s',
83
				__( 'Available tags:', 'pronamic_ideal' ),
84
				sprintf(
85
					'<code>%s</code> <code>%s</code>',
86
					'{order_id}',
87
					'{payment_id}'
88
				),
89
				sprintf(
90
					/* translators: %s: {order_id} */
91
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
92
					'{order_id}'
93
				)
94
			),
95
		);
96
97
		// Notification URL.
98
		$fields[] = array(
99
			'section'  => 'feedback',
100
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
101
			'title'    => _x( 'Notification URL', 'EMS e-Commerce', 'pronamic_ideal' ),
102
			'type'     => 'text',
103
			'classes'  => array( 'large-text', 'code' ),
104
			'value'    => home_url( '/' ),
105
			'readonly' => true,
106
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
107
			'tooltip'  => _x(
108
				'The Notification URL as sent with each transaction to receive automatic payment status updates on.',
109
				'EMS e-Commerce',
110
				'pronamic_ideal'
111
			),
112
		);
113
114
		return $fields;
115
	}
116
117
	public function get_config( $post_id ) {
118
		$config = new Config();
119
120
		$config->storename = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_storename', true );
121
		$config->secret    = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_secret', true );
122
		$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...
123
		$config->order_id  = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_order_id', true );
124
125
		return $config;
126
	}
127
128
	/**
129
	 * Get gateway.
130
	 *
131
	 * @param int $post_id Post ID.
132
	 * @return Gateway
133
	 */
134
	public function get_gateway( $post_id ) {
135
		return new Gateway( $this->get_config( $post_id ) );
136
	}
137
}
138