Failed Conditions
Push — feature/webhook-status ( 7f5a3e )
by Reüel
05:57
created

src/Settings.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Nocks;
4
5
use Pronamic\WordPress\Pay\Core\GatewaySettings;
6
use Pronamic\WordPress\Pay\Util as Pay_Util;
7
8
/**
9
 * Title: Nocks settings
10
 * Description:
11
 * Copyright: 2005-2019 Pronamic
12
 * Company: Pronamic
13
 *
14
 * @author  Reüel van der Steege
15
 * @version 2.0.0
16
 * @since   1.0.0
17
 */
18
class Settings extends GatewaySettings {
19
	/**
20
	 * Settings constructor.
21
	 */
22
	public function __construct() {
23
		add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) );
24
		add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) );
25
	}
26
27
	/**
28
	 * Settings sections.
29
	 *
30
	 * @param array $sections Sections.
31
	 *
32
	 * @return array
33
	 */
34
	public function sections( array $sections ) {
35
		$sections['nocks'] = array(
36
			'title'   => __( 'Nocks', 'pronamic_ideal' ),
37
			'methods' => array( 'nocks' ),
38
		);
39
40
		// Transaction feedback.
41
		$sections['nocks_feedback'] = array(
42
			'title'       => __( 'Transaction feedback', 'pronamic_ideal' ),
43
			'methods'     => array( 'nocks' ),
44
			'description' => __( 'Payment status updates will be processed without any additional configuration. The <em>Webhook URL</em> is being used to receive the status updates.', 'pronamic_ideal' ),
45
		);
46
47
		return $sections;
48
	}
49
50
	/**
51
	 * Settings fields.
52
	 *
53
	 * @param array $fields Settings fields.
54
	 *
55
	 * @return array
56
	 */
57
	public function fields( array $fields ) {
58
		// Access token.
59
		$fields[] = array(
60
			'filter'   => FILTER_SANITIZE_STRING,
61
			'section'  => 'nocks',
62
			'meta_key' => '_pronamic_gateway_nocks_access_token',
63
			'title'    => _x( 'Access Token', 'nocks', 'pronamic_ideal' ),
64
			'type'     => 'textarea',
65
			'classes'  => array( 'code' ),
66
		);
67
68
		// Merchant profile.
69
		$fields[] = array(
70
			'filter'   => FILTER_SANITIZE_STRING,
71
			'section'  => 'nocks',
72
			'meta_key' => '_pronamic_gateway_nocks_merchant_profile',
73
			'title'    => _x( 'Merchant Profile', 'nocks', 'pronamic_ideal' ),
74
			'type'     => 'description',
75
			'callback' => array( $this, 'field_merchant_profile' ),
76
		);
77
78
		// Transaction feedback.
79
		$fields[] = array(
80
			'section' => 'nocks',
81
			'methods' => array( 'nocks' ),
82
			'title'   => __( 'Transaction feedback', 'pronamic_ideal' ),
83
			'type'    => 'description',
84
			'html'    => __( 'Payment status updates will be processed without any additional configuration.', 'pronamic_ideal' ),
85
		);
86
87
		// Webhook URL.
88
		$fields[] = array(
89
			'section'  => 'nocks_feedback',
90
			'title'    => __( 'Webhook URL', 'pronamic_ideal' ),
91
			'type'     => 'text',
92
			'classes'  => array( 'large-text', 'code' ),
93
			'value'    => add_query_arg( 'nocks_webhook', '', home_url( '/' ) ),
94
			'readonly' => true,
95
			'methods'  => array( 'nocks' ),
96
			'tooltip'  => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
97
		);
98
99
		// Webhook status.
100
		$fields[] = array(
101
			'section'  => 'nocks_feedback',
102
			'methods'  => array( 'nocks' ),
103
			'title'    => __( 'Status', 'pronamic_ideal' ),
104
			'type'     => 'description',
105
			'callback' => array( 'Pronamic\WordPress\Pay\WebhookManager', 'settings_status' ),
106
		);
107
108
		return $fields;
109
	}
110
111
	/**
112
	 * Field merchant profile select.
113
	 *
114
	 * @param array $field Settings field.
115
	 */
116
	public function field_merchant_profile( $field ) {
117
		$access_token     = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_access_token', true );
0 ignored issues
show
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

117
		$access_token     = get_post_meta( /** @scrutinizer ignore-type */ get_the_ID(), '_pronamic_gateway_nocks_access_token', true );
Loading history...
118
		$merchant_profile = get_post_meta( get_the_ID(), '_pronamic_gateway_nocks_merchant_profile', true );
119
120
		if ( ! $access_token ) {
121
			esc_html_e( 'First enter an API Key and save the configuration, to be able to choose from your Nocks merchant profiles.', 'pronamic_ideal' );
122
123
			return;
124
		}
125
126
		$client = new Client();
127
128
		$client->set_access_token( $access_token );
129
130
		// Select merchant profile.
131
		printf( '<select name="%s">', esc_attr( $field['meta_key'] ) );
132
133
		$options = array(
134
			__( '— Select Merchant Profile —', 'pronamic_ideal' ),
135
		);
136
137
		$options = array_merge( $options, $client->get_merchant_profiles() );
138
139
		$options = array(
140
			array(
141
				'options' => $options,
142
			),
143
		);
144
145
		echo Pay_Util::select_options_grouped( $options, $merchant_profile ); // WPCS: xss ok.
0 ignored issues
show
It seems like $merchant_profile can also be of type false; however, parameter $selected_value of Pronamic\WordPress\Pay\U...elect_options_grouped() does only seem to accept string, 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

145
		echo Pay_Util::select_options_grouped( $options, /** @scrutinizer ignore-type */ $merchant_profile ); // WPCS: xss ok.
Loading history...
146
147
		echo '</select>';
148
	}
149
}
150