Test Failed
Push — main ( 28b955...362ef3 )
by Reüel
14:17 queued 10s
created

Integration::get_config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 1
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Integration
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
use Pronamic\WordPress\Pay\AbstractGatewayIntegration;
14
15
/**
16
 * Integration
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.1.0
20
 * @since   1.0.0
21
 */
22
class Integration extends AbstractGatewayIntegration {
23
	/**
24
	 * REST route namespace.
25
	 *
26
	 * @var string
27
	 */
28
	const REST_ROUTE_NAMESPACE = 'pronamic-pay/payvision/v1';
29
30
	/**
31
	 * Construct Payvision integration.
32
	 *
33
	 * @param array<string, array<string>> $args Arguments.
34
	 */
35 2
	public function __construct( $args = array() ) {
36 2
		$args = \wp_parse_args(
37 2
			$args,
38
			array(
39 2
				'id'            => 'payvision',
40 2
				'name'          => 'Payvision',
41 2
				'provider'      => 'payvision',
42 2
				'url'           => \__( 'https://www.payvision.com/', 'pronamic_ideal' ),
43 2
				'product_url'   => \__( 'https://www.payvision.com/', 'pronamic_ideal' ),
44 2
				'dashboard_url' => 'https://tools.payvisionservices.com/acecontrol/dashboard',
45 2
				'manual_url'    => \__(
46 2
					'https://www.pronamic.eu/manuals/using-payvision-pronamic-pay/',
47 2
					'pronamic_ideal'
48
				),
49
				'supports'      => array(),
50
			)
51
		);
52
53 2
		parent::__construct( $args );
54 2
	}
55
56
	/**
57
	 * Setup.
58
	 */
59
	public function setup() {
60
		\add_filter(
61
			'pronamic_gateway_configuration_display_value_' . $this->get_id(),
62
			array( $this, 'gateway_configuration_display_value' ),
63
			10,
64
			2
65
		);
66
	}
67
68
	/**
69
	 * Gateway configuration display value.
70
	 *
71
	 * @param string $display_value Display value.
72
	 * @param int    $post_id       Gateway configuration post ID.
73
	 * @return string
74
	 */
75
	public function gateway_configuration_display_value( $display_value, $post_id ) {
76
		$config = $this->get_config( $post_id );
77
78
		return $config->get_business_id();
79
	}
80
81
	/**
82
	 * Get settings fields.
83
	 *
84
	 * @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>>
0 ignored issues
show
Documentation introduced by
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
85
	 */
86 1
	public function get_settings_fields() {
87 1
		$fields = array();
88
89
		// Business Id.
90 1
		$fields[] = array(
91 1
			'section'  => 'general',
92
			'filter'   => \FILTER_SANITIZE_STRING,
93 1
			'meta_key' => '_pronamic_gateway_payvision_business_id',
94 1
			'title'    => \_x( 'Business Id', 'payvision', 'pronamic_ideal' ),
95 1
			'type'     => 'text',
96
			'classes'  => array( 'regular-text', 'code' ),
97 1
			'tooltip'  => \__(
98 1
				'A Merchant connecting to the platform is identified by its Business ID (“businessId”).',
99 1
				'pronamic_ideal'
100
			),
101
		);
102
103
		// User.
104 1
		$fields[] = array(
105 1
			'section'  => 'general',
106
			'filter'   => \FILTER_SANITIZE_STRING,
107 1
			'meta_key' => '_pronamic_gateway_payvision_username',
108 1
			'title'    => \_x( 'User', 'payvision', 'pronamic_ideal' ),
109 1
			'type'     => 'text',
110
			'classes'  => array( 'regular-text', 'code' ),
111
		);
112
113
		// Password.
114 1
		$fields[] = array(
115 1
			'section'  => 'general',
116
			'filter'   => \FILTER_SANITIZE_STRING,
117 1
			'meta_key' => '_pronamic_gateway_payvision_password',
118 1
			'title'    => \_x( 'Password', 'payvision', 'pronamic_ideal' ),
119 1
			'type'     => 'text',
120
			'classes'  => array( 'regular-text', 'code' ),
121
		);
122
123
		// Store Id.
124 1
		$fields[] = array(
125 1
			'section'  => 'general',
126
			'filter'   => \FILTER_SANITIZE_STRING,
127 1
			'meta_key' => '_pronamic_gateway_payvision_store_id',
128 1
			'title'    => \_x( 'Store ID', 'payvision', 'pronamic_ideal' ),
129 1
			'type'     => 'text',
130
			'classes'  => array( 'regular-text', 'code' ),
131
		);
132
133
		// Purchase ID.
134 1
		$code_field = \sprintf( '<code>%s</code>', 'purchaseId' );
135
136 1
		$fields[] = array(
137 1
			'section'     => 'advanced',
138
			'filter'      => \FILTER_SANITIZE_STRING,
139 1
			'meta_key'    => '_pronamic_gateway_payvision_purchase_id',
140 1
			'title'       => \__( 'Order ID', 'pronamic_ideal' ),
141 1
			'type'        => 'text',
142
			'classes'     => array( 'regular-text', 'code' ),
143 1
			'tooltip'     => \sprintf(
144
				/* translators: %s: <code>purchaseId</code> */
145 1
				\__( 'The Payvision parameter %s', 'pronamic_ideal' ),
146 1
				$code_field
147
			),
148 1
			'description' => \sprintf(
149 1
				'%s %s<br />%s',
150 1
				\__( 'Available tags:', 'pronamic_ideal' ),
151 1
				\sprintf(
152 1
					'<code>%s</code> <code>%s</code>',
153 1
					'{order_id}',
154 1
					'{payment_id}'
155
				),
156 1
				\sprintf(
157
					/* translators: %s: default code */
158 1
					\__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
159 1
					'{payment_id}'
160
				)
161
			),
162
		);
163
164
		// Return fields.
165 1
		return $fields;
166
	}
167
168
	/**
169
	 * Get configuration by post ID.
170
	 *
171
	 * @param int $post_id Post ID.
172
	 * @return Config
173
	 */
174 1
	public function get_config( $post_id ) {
175 1
		$mode        = $this->get_meta( $post_id, 'mode' );
176 1
		$business_id = $this->get_meta( $post_id, 'payvision_business_id' );
177 1
		$username    = $this->get_meta( $post_id, 'payvision_username' );
178 1
		$password    = $this->get_meta( $post_id, 'payvision_password' );
179 1
		$store_id    = $this->get_meta( $post_id, 'payvision_store_id' );
180 1
		$purchase_id = $this->get_meta( $post_id, 'payvision_purchase_id' );
181
182 1
		$config = new Config( $mode, $business_id, $username, $password, $store_id );
183
184 1
		$config->set_purchase_id( $purchase_id );
185
186 1
		return $config;
187
	}
188
189
	/**
190
	 * Get gateway.
191
	 *
192
	 * @param int $post_id Post ID.
193
	 * @return Gateway
194
	 */
195
	public function get_gateway( $post_id ) {
196
		$config = $this->get_config( $post_id );
197
198
		return new Gateway( $config );
199
	}
200
}
201