Test Failed
Push — develop ( 138c44...8262d9 )
by Remco
11:13
created

src/Integration.php (1 issue)

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