Failed Conditions
Push — develop ( 819bf1...81fcae )
by Remco
06:20
created

src/Integration.php (1 issue)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: MultiSafepay Connect integration
9
 * Description:
10
 * Copyright: 2005-2020 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.5
15
 * @since   1.2.6
16
 */
17
class Integration extends AbstractIntegration {
18
	/**
19
	 * Integration constructor.
20
	 */
21
	public function __construct() {
22
		parent::__construct();
23
24
		$this->id            = 'multisafepay-connect';
25
		$this->name          = 'MultiSafepay - Connect';
26
		$this->url           = 'http://www.multisafepay.com/';
27
		$this->product_url   = __( 'http://www.multisafepay.com/', 'pronamic_ideal' );
28
		$this->dashboard_url = 'https://merchant.multisafepay.com/';
29
		$this->provider      = 'multisafepay';
30
		$this->supports      = array(
31
			'payment_status_request',
32
			'webhook',
33
			'webhook_no_config',
34
		);
35
36
		$this->set_manual_url( __( 'https://www.pronamic.eu/support/how-to-connect-multisafepay-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) );
37
	}
38
39
	public function get_settings_fields() {
40
		$fields = array();
41
42
		// Account ID
43
		$fields[] = array(
44
			'section'  => 'general',
45
			'filter'   => FILTER_SANITIZE_STRING,
46
			'meta_key' => '_pronamic_gateway_multisafepay_account_id',
47
			'title'    => __( 'Account ID', 'pronamic_ideal' ),
48
			'type'     => 'text',
49
			'classes'  => array( 'code' ),
50
			'tooltip'  => sprintf(
51
				'%s %s.',
52
				__( 'Account ID', 'pronamic_ideal' ),
53
				/* translators: %s: MultiSafepay */
54
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
55
			),
56
		);
57
58
		// Site ID
59
		$fields[] = array(
60
			'section'  => 'general',
61
			'filter'   => FILTER_SANITIZE_STRING,
62
			'meta_key' => '_pronamic_gateway_multisafepay_site_id',
63
			'title'    => __( 'Site ID', 'pronamic_ideal' ),
64
			'type'     => 'text',
65
			'classes'  => array( 'code' ),
66
			'tooltip'  => sprintf(
67
				'%s %s.',
68
				__( 'Site ID', 'pronamic_ideal' ),
69
				/* translators: %s: MultiSafepay */
70
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
71
			),
72
		);
73
74
		// Site Security Code
75
		$fields[] = array(
76
			'section'  => 'general',
77
			'filter'   => FILTER_SANITIZE_STRING,
78
			'meta_key' => '_pronamic_gateway_multisafepay_site_code',
79
			'title'    => __( 'Site Security Code', 'pronamic_ideal' ),
80
			'type'     => 'text',
81
			'classes'  => array( 'code' ),
82
			'tooltip'  => sprintf(
83
				'%s %s.',
84
				__( 'Site Security Code', 'pronamic_ideal' ),
85
				/* translators: %s: MultiSafepay */
86
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
87
			),
88
		);
89
90
		return $fields;
91
	}
92
93
	/**
94
	 * Get config.
95
	 *
96
	 * @param $post_id
97
	 *
98
	 * @return Config
99
	 */
100
	public function get_config( $post_id ) {
101
		$config = new Config();
102
103
		$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...
104
		$config->account_id = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_account_id', true );
105
		$config->site_id    = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_site_id', true );
106
		$config->site_code  = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_site_code', true );
107
108
		if ( Gateway::MODE_TEST === $config->mode ) {
109
			$config->api_url = MultiSafepay::API_TEST_URL;
110
		} else {
111
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
112
		}
113
114
		return $config;
115
	}
116
117
	/**
118
	 * Get gateway.
119
	 *
120
	 * @param int $post_id Post ID.
121
	 * @return Gateway
122
	 */
123
	public function get_gateway( $post_id ) {
124
		return new Gateway( $this->get_config( $post_id ) );
125
	}
126
}
127