|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo; |
|
4
|
|
|
|
|
5
|
|
|
use Pronamic\WordPress\Pay\AbstractGatewayIntegration; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Title: Buckaroo integration |
|
9
|
|
|
* Description: |
|
10
|
|
|
* Copyright: 2005-2021 Pronamic |
|
11
|
|
|
* Company: Pronamic |
|
12
|
|
|
* |
|
13
|
|
|
* @author Reüel van der Steege |
|
14
|
|
|
* @version 2.0.4 |
|
15
|
|
|
* @since 1.0.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
class Integration extends AbstractGatewayIntegration { |
|
18
|
|
|
/** |
|
19
|
|
|
* REST route namespace. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
const REST_ROUTE_NAMESPACE = 'pronamic-pay/buckaroo/v1'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Construct Buckaroo integration. |
|
27
|
|
|
* |
|
28
|
|
|
* @param array $args Arguments. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( $args = array() ) { |
|
31
|
|
|
$args = wp_parse_args( |
|
32
|
|
|
$args, |
|
33
|
|
|
array( |
|
34
|
|
|
'id' => 'buckaroo', |
|
35
|
|
|
'name' => 'Buckaroo', |
|
36
|
|
|
'url' => 'https://plaza.buckaroo.nl/', |
|
37
|
|
|
'product_url' => \__( 'http://www.buckaroo-payments.com', 'pronamic_ideal' ), |
|
38
|
|
|
'dashboard_url' => 'https://plaza.buckaroo.nl/', |
|
39
|
|
|
'provider' => 'buckaroo', |
|
40
|
|
|
'supports' => array( |
|
41
|
|
|
'payment_status_request', |
|
42
|
|
|
'refunds', |
|
43
|
|
|
'webhook', |
|
44
|
|
|
'webhook_log', |
|
45
|
|
|
'webhook_no_config', |
|
46
|
|
|
), |
|
47
|
|
|
'manual_url' => \__( 'https://www.pronamic.eu/support/how-to-connect-buckaroo-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ), |
|
48
|
|
|
) |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
parent::__construct( $args ); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* CLI. |
|
55
|
|
|
* |
|
56
|
|
|
* @link https://github.com/woocommerce/woocommerce/blob/3.9.0/includes/class-woocommerce.php#L453-L455 |
|
57
|
|
|
*/ |
|
58
|
|
|
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
|
|
|
|
|
59
|
|
|
new CLI( $this ); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Setup. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setup() { |
|
67
|
|
|
\add_filter( |
|
68
|
|
|
'pronamic_gateway_configuration_display_value_' . $this->get_id(), |
|
69
|
|
|
array( $this, 'gateway_configuration_display_value' ), |
|
70
|
|
|
10, |
|
71
|
|
|
2 |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
// Push controller. |
|
75
|
|
|
$push_controller = new PushController(); |
|
76
|
|
|
|
|
77
|
|
|
$push_controller->setup(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Gateway configuration display value. |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $display_value Display value. |
|
84
|
|
|
* @param int $post_id Gateway configuration post ID. |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public function gateway_configuration_display_value( $display_value, $post_id ) { |
|
88
|
|
|
$config = $this->get_config( $post_id ); |
|
89
|
|
|
|
|
90
|
|
|
$display_value = $config->website_key; |
|
91
|
|
|
|
|
92
|
|
|
return $display_value; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get settings fields. |
|
97
|
|
|
* |
|
98
|
|
|
* @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>> |
|
99
|
|
|
*/ |
|
100
|
|
|
public function get_settings_fields() { |
|
101
|
|
|
$fields = array(); |
|
102
|
|
|
|
|
103
|
|
|
// Website Key. |
|
104
|
|
|
$fields[] = array( |
|
105
|
|
|
'section' => 'general', |
|
106
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
|
107
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_website_key', |
|
108
|
|
|
'title' => __( 'Website Key', 'pronamic_ideal' ), |
|
109
|
|
|
'type' => 'text', |
|
110
|
|
|
'classes' => array( 'code' ), |
|
111
|
|
|
'tooltip' => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ), |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
// Secret Key. |
|
115
|
|
|
$fields[] = array( |
|
116
|
|
|
'section' => 'general', |
|
117
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
|
118
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_secret_key', |
|
119
|
|
|
'title' => __( 'Secret Key', 'pronamic_ideal' ), |
|
120
|
|
|
'type' => 'text', |
|
121
|
|
|
'classes' => array( 'regular-text', 'code' ), |
|
122
|
|
|
'tooltip' => __( 'Secret key as mentioned in the Buckaroo dashboard on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ), |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
// Excluded services. |
|
126
|
|
|
$fields[] = array( |
|
127
|
|
|
'section' => 'advanced', |
|
128
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
|
129
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_excluded_services', |
|
130
|
|
|
'title' => __( 'Excluded services', 'pronamic_ideal' ), |
|
131
|
|
|
'type' => 'text', |
|
132
|
|
|
'classes' => array( 'regular-text', 'code' ), |
|
133
|
|
|
'tooltip' => sprintf( |
|
134
|
|
|
/* translators: %s: <code>brq_parameter</code> */ |
|
135
|
|
|
__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ), |
|
136
|
|
|
sprintf( '<code>%s</code>', 'brq_exludedservices' ) |
|
137
|
|
|
), |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
// Invoice number. |
|
141
|
|
|
$fields[] = array( |
|
142
|
|
|
'section' => 'advanced', |
|
143
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
|
144
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_invoice_number', |
|
145
|
|
|
'title' => __( 'Invoice number', 'pronamic_ideal' ), |
|
146
|
|
|
'type' => 'text', |
|
147
|
|
|
'classes' => array( 'regular-text', 'code' ), |
|
148
|
|
|
'tooltip' => sprintf( |
|
149
|
|
|
/* translators: %s: <code>brq_parameter</code> */ |
|
150
|
|
|
__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ), |
|
151
|
|
|
sprintf( '<code>%s</code>', 'brq_invoicenumber' ) |
|
152
|
|
|
), |
|
153
|
|
|
'description' => sprintf( |
|
154
|
|
|
'%s<br />%s', |
|
155
|
|
|
/* translators: %s: <code>{tag}</code> */ |
|
156
|
|
|
sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ), |
|
157
|
|
|
/* translators: %s: default code */ |
|
158
|
|
|
sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' ) |
|
159
|
|
|
), |
|
160
|
|
|
); |
|
161
|
|
|
|
|
162
|
|
|
// Push URL. |
|
163
|
|
|
$fields[] = array( |
|
164
|
|
|
'section' => 'feedback', |
|
165
|
|
|
'title' => __( 'Push URL', 'pronamic_ideal' ), |
|
166
|
|
|
'type' => 'text', |
|
167
|
|
|
'classes' => array( 'large-text', 'code' ), |
|
168
|
|
|
'value' => \rest_url( self::REST_ROUTE_NAMESPACE . '/push' ), |
|
169
|
|
|
'readonly' => true, |
|
170
|
|
|
'tooltip' => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
|
171
|
|
|
); |
|
172
|
|
|
|
|
173
|
|
|
return $fields; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Get config. |
|
178
|
|
|
* |
|
179
|
|
|
* @param int $post_id Gateway config post ID. |
|
180
|
|
|
* |
|
181
|
|
|
* @return Config |
|
182
|
|
|
*/ |
|
183
|
|
|
public function get_config( $post_id ) { |
|
184
|
|
|
$config = new Config(); |
|
185
|
|
|
|
|
186
|
|
|
$config->website_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true ); |
|
|
|
|
|
|
187
|
|
|
$config->secret_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true ); |
|
|
|
|
|
|
188
|
|
|
$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true ); |
|
|
|
|
|
|
189
|
|
|
$config->invoice_number = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true ); |
|
|
|
|
|
|
190
|
|
|
$config->mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true ); |
|
|
|
|
|
|
191
|
|
|
|
|
192
|
|
|
return $config; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get gateway. |
|
197
|
|
|
* |
|
198
|
|
|
* @param int $post_id Post ID. |
|
199
|
|
|
* @return Gateway |
|
200
|
|
|
*/ |
|
201
|
|
|
public function get_gateway( $post_id ) { |
|
202
|
|
|
return new Gateway( $this->get_config( $post_id ) ); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|