Failed Conditions
Push — develop ( 987969...9e6419 )
by Remco
03:33
created

Integration::get_config_factory_class()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Nocks;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: Nocks 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            = 'nocks';
20
		$this->name          = 'Nocks - Checkout';
21
		$this->product_url   = 'https://www.nocks.com/';
22
		$this->dashboard_url = 'https://www.nocks.com/';
23
		$this->provider      = 'nocks';
24
		$this->supports      = array(
0 ignored issues
show
Bug Best Practice introduced by
The property supports does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
			'payment_status_request',
26
			'webhook',
27
			'webhook_no_config',
28
		);
29
30
		// Actions
31
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
32
33
		if ( ! has_action( 'wp_loaded', $function ) ) {
34
			add_action( 'wp_loaded', $function );
35
		}
36
	}
37
38
	public function get_config_factory_class() {
39
		return __NAMESPACE__ . '\ConfigFactory';
40
	}
41
42
	/**
43
	 * Get settings fields.
44
	 *
45
	 * @return array
46
	 */
47
	public function get_settings_fields() {
48
		$fields = array();
49
50
		// Access token.
51
		$fields[] = array(
52
			'section'  => 'general',
53
			'filter'   => FILTER_SANITIZE_STRING,
54
			'meta_key' => '_pronamic_gateway_nocks_access_token',
55
			'title'    => _x( 'Access Token', 'nocks', 'pronamic_ideal' ),
56
			'type'     => 'textarea',
57
			'classes'  => array( 'code' ),
58
		);
59
60
		// Merchant profile.
61
		$fields[] = array(
62
			'section'  => 'general',
63
			'filter'   => FILTER_SANITIZE_STRING,
64
			'meta_key' => '_pronamic_gateway_nocks_merchant_profile',
65
			'title'    => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ),
66
			'type'     => 'description',
67
			'callback' => array( $this, 'field_merchant_profile' ),
68
		);
69
70
		// Webhook URL.
71
		$fields[] = array(
72
			'section'  => 'feedback',
73
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
74
			'type'     => 'text',
75
			'classes'  => array( 'large-text', 'code' ),
76
			'value'    => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ),
77
			'readonly' => true,
78
			'tooltip'  => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
79
		);
80
81
		return $fields;
82
	}
83
84
	/**
85
	 * Field merchant profile select.
86
	 *
87
	 * @param array $field Settings field.
88
	 */
89
	public function field_merchant_profile( $field ) {
90
		$access_token     = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_access_token', true );
0 ignored issues
show
Bug introduced by
It seems like get_the_ID() can also be of type false; however, parameter $post_id of get_post_meta() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
		$access_token     = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), '_pronamic_gateway_nocks_access_token', true );
Loading history...
91
		$merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true );
92
93
		if ( ! $access_token ) {
94
			esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' );
95
96
			return;
97
		}
98
99
		$client = new Client();
100
101
		$client->set_access_token( $access_token );
102
103
		// Select merchant profile.
104
		printf( '<select name="%s">', esc_attr( $field['meta_key'] ) );
105
106
		$options = array(
107
			__( '— Select Merchant Profile —', 'pronamic_ideal' ),
108
		);
109
110
		$options = array_merge( $options, $client->get_merchant_profiles() );
111
112
		$options = array(
113
			array(
114
				'options' => $options,
115
			),
116
		);
117
118
		echo Pay_Util::select_options_grouped( $options, $merchant_profile ); // WPCS: xss ok.
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\Gateways\Nocks\Pay_Util was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
119
120
		echo '</select>';
121
	}
122
}
123