1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Integration |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2022 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>>> |
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 |
|
if ( '' !== $purchase_id ) { |
185
|
|
|
$config->set_purchase_id( $purchase_id ); |
186
|
|
|
} |
187
|
|
|
|
188
|
1 |
|
return $config; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get gateway. |
193
|
|
|
* |
194
|
|
|
* @param int $post_id Post ID. |
195
|
|
|
* @return Gateway |
196
|
|
|
*/ |
197
|
1 |
|
public function get_gateway( $post_id ) { |
198
|
1 |
|
$config = $this->get_config( $post_id ); |
199
|
|
|
|
200
|
1 |
|
return new Gateway( $config ); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|