Failed Conditions
Push — develop ( 7300c8...de8c77 )
by Remco
09:33 queued 03:31
created

src/Integration.php (1 issue)

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