Failed Conditions
Push — develop ( a934e6...00f5ab )
by Remco
07:38 queued 13s
created

Integration::get_settings_fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 87
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 52
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 60
nc 1
nop 0
dl 0
loc 87
ccs 52
cts 52
cp 1
crap 1
rs 8.8727
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Icepay;
4
5
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
6
7
/**
8
 * Title: ICEPAY integration
9
 * Description:
10
 * Copyright: 2005-2020 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.6
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractGatewayIntegration {
18
	/**
19
	 * Construct ICEPAY integration.
20
	 *
21
	 * @param array $args Arguments.
22
	 */
23 3
	public function __construct( $args = array() ) {
24 3
		$args = wp_parse_args(
25 3
			$args,
26
			array(
27 3
				'id'            => 'icepay-ideal',
28 3
				'name'          => 'ICEPAY',
29 3
				'url'           => 'https://icepay.com/',
30 3
				'product_url'   => \__( 'https://icepay.com/nl/en/pricing-and-accounts/', 'pronamic_ideal' ),
31 3
				'manual_url'    => \__( 'https://www.pronamic.eu/support/how-to-connect-icepay-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ),
32 3
				'dashboard_url' => 'https://portal.icepay.com/',
33 3
				'provider'      => 'icepay',
34
				'supports'      => array(
35
					'webhook',
36
					'webhook_log',
37
				),
38
			)
39
		);
40
41 3
		parent::__construct( $args );
42
43
		// Actions
44 3
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
45
46 3
		if ( ! has_action( 'wp_loaded', $function ) ) {
47 1
			add_action( 'wp_loaded', $function );
48
		}
49 3
	}
50
51 1
	public function get_settings_fields() {
52 1
		$fields = array();
53
54
		// Merchant ID
55 1
		$fields[] = array(
56 1
			'section'  => 'general',
57 1
			'filter'   => FILTER_SANITIZE_STRING,
58 1
			'meta_key' => '_pronamic_gateway_icepay_merchant_id',
59 1
			'title'    => _x( 'Merchant ID', 'icepay', 'pronamic_ideal' ),
60 1
			'type'     => 'text',
61 1
			'tooltip'  => __( 'Merchant ID as mentioned in the ICEPAY dashboard at the "My websites" page.', 'pronamic_ideal' ),
62
		);
63
64
		// Secret Code
65 1
		$fields[] = array(
66 1
			'section'  => 'general',
67 1
			'filter'   => FILTER_SANITIZE_STRING,
68 1
			'meta_key' => '_pronamic_gateway_icepay_secret_code',
69 1
			'title'    => _x( 'Secret Code', 'icepay', 'pronamic_ideal' ),
70 1
			'type'     => 'text',
71
			'classes'  => array( 'regular-text', 'code' ),
72 1
			'tooltip'  => __( 'Secret Code as mentioned in the ICEPAY dashboard at the "My websites" page.', 'pronamic_ideal' ),
73
		);
74
75
		// Purchase ID
76 1
		$fields[] = array(
77 1
			'section'     => 'advanced',
78
			'filter'      => array(
79 1
				'filter' => FILTER_SANITIZE_STRING,
80 1
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
81
			),
82 1
			'meta_key'    => '_pronamic_gateway_icepay_order_id',
83 1
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
84 1
			'type'        => 'text',
85
			'classes'     => array( 'regular-text', 'code' ),
86 1
			'tooltip'     => sprintf(
87
				/* translators: %s: <code>OrderID</code> */
88 1
				__( 'The Icepay %s parameter.', 'pronamic_ideal' ),
89 1
				sprintf( '<code>%s</code>', 'OrderID' )
90
			),
91 1
			'description' => sprintf(
92 1
				'%s %s<br />%s',
93 1
				__( 'Available tags:', 'pronamic_ideal' ),
94 1
				sprintf(
95 1
					'<code>%s</code> <code>%s</code>',
96 1
					'{order_id}',
97 1
					'{payment_id}'
98
				),
99 1
				sprintf(
100
					/* translators: %s: <code>{payment_id}</code> */
101 1
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
102 1
					'{payment_id}'
103
				)
104
			),
105
		);
106
107
		// Thank you page URL
108 1
		$fields[] = array(
109 1
			'section'  => 'feedback',
110 1
			'title'    => __( 'Thank you page URL', 'pronamic_ideal' ),
111 1
			'type'     => 'text',
112
			'classes'  => array( 'regular-text', 'code' ),
113 1
			'value'    => home_url( '/' ),
114
			'readonly' => true,
115
		);
116
117
		// Error page URL
118 1
		$fields[] = array(
119 1
			'section'  => 'feedback',
120 1
			'title'    => __( 'Error page URL', 'pronamic_ideal' ),
121 1
			'type'     => 'text',
122
			'classes'  => array( 'regular-text', 'code' ),
123 1
			'value'    => home_url( '/' ),
124
			'readonly' => true,
125
		);
126
127
		// Postback URL
128 1
		$fields[] = array(
129 1
			'section'  => 'feedback',
130 1
			'title'    => __( 'Postback URL', 'pronamic_ideal' ),
131 1
			'type'     => 'text',
132
			'classes'  => array( 'regular-text', 'code' ),
133 1
			'value'    => home_url( '/' ),
134
			'readonly' => true,
135
		);
136
137 1
		return $fields;
138
	}
139
140 2
	public function get_config( $post_id ) {
141 2
		$config = new Config();
142
143 2
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_icepay_merchant_id', true );
144 2
		$config->secret_code = get_post_meta( $post_id, '_pronamic_gateway_icepay_secret_code', true );
145 2
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_icepay_order_id', true );
146
147 2
		return $config;
148
	}
149
150
	/**
151
	 * Get gateway.
152
	 *
153
	 * @param int $post_id Post ID.
154
	 * @return Gateway
155
	 */
156 1
	public function get_gateway( $post_id ) {
157 1
		return new Gateway( $this->get_config( $post_id ) );
158
	}
159
}
160