Failed Conditions
Push — develop ( 1cbcaa...987969 )
by Remco
03:30
created

Integration::field_merchant_profile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 32
ccs 0
cts 21
cp 0
crap 6
rs 9.7333
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
25
		// Actions
26
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
27
28
		if ( ! has_action( 'wp_loaded', $function ) ) {
29
			add_action( 'wp_loaded', $function );
30
		}
31
	}
32
33
	public function get_config_factory_class() {
34
		return __NAMESPACE__ . '\ConfigFactory';
35
	}
36
37
	/**
38
	 * Get settings fields.
39
	 *
40
	 * @return array
41
	 */
42
	public function get_settings_fields() {
43
		$fields = array();
44
45
		// Access token.
46
		$fields[] = array(
47
			'section'  => 'general',
48
			'filter'   => FILTER_SANITIZE_STRING,
49
			'meta_key' => '_pronamic_gateway_nocks_access_token',
50
			'title'    => _x( 'Access Token', 'nocks', 'pronamic_ideal' ),
51
			'type'     => 'textarea',
52
			'classes'  => array( 'code' ),
53
		);
54
55
		// Merchant profile.
56
		$fields[] = array(
57
			'section'  => 'general',
58
			'filter'   => FILTER_SANITIZE_STRING,
59
			'meta_key' => '_pronamic_gateway_nocks_merchant_profile',
60
			'title'    => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ),
61
			'type'     => 'description',
62
			'callback' => array( $this, 'field_merchant_profile' ),
63
		);
64
65
		// Webhook URL.
66
		$fields[] = array(
67
			'section'  => 'feedback',
68
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
69
			'type'     => 'text',
70
			'classes'  => array( 'large-text', 'code' ),
71
			'value'    => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ),
72
			'readonly' => true,
73
			'methods'  => array( 'nocks' ),
74
			'tooltip'  => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
75
		);
76
77
		return $fields;
78
	}
79
80
	/**
81
	 * Field merchant profile select.
82
	 *
83
	 * @param array $field Settings field.
84
	 */
85
	public function field_merchant_profile( $field ) {
86
		$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

86
		$access_token     = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), '_pronamic_gateway_nocks_access_token', true );
Loading history...
87
		$merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true );
88
89
		if ( ! $access_token ) {
90
			esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' );
91
92
			return;
93
		}
94
95
		$client = new Client();
96
97
		$client->set_access_token( $access_token );
98
99
		// Select merchant profile.
100
		printf( '<select name="%s">', esc_attr( $field['meta_key'] ) );
101
102
		$options = array(
103
			__( '— Select Merchant Profile —', 'pronamic_ideal' ),
104
		);
105
106
		$options = array_merge( $options, $client->get_merchant_profiles() );
107
108
		$options = array(
109
			array(
110
				'options' => $options,
111
			),
112
		);
113
114
		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...
115
116
		echo '</select>';
117
	}
118
}
119