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
|
|
|
/** |
55
|
|
|
* Setup. |
56
|
|
|
*/ |
57
|
|
|
public function setup() { |
58
|
|
|
\add_filter( |
59
|
|
|
'pronamic_gateway_configuration_display_value_' . $this->get_id(), |
60
|
|
|
array( $this, 'gateway_configuration_display_value' ), |
61
|
|
|
10, |
62
|
|
|
2 |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
// Push controller. |
66
|
|
|
$push_controller = new PushController(); |
67
|
|
|
|
68
|
|
|
$push_controller->setup(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Gateway configuration display value. |
73
|
|
|
* |
74
|
|
|
* @param string $display_value Display value. |
75
|
|
|
* @param int $post_id Gateway configuration post ID. |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function gateway_configuration_display_value( $display_value, $post_id ) { |
79
|
|
|
$config = $this->get_config( $post_id ); |
80
|
|
|
|
81
|
|
|
$display_value = $config->website_key; |
82
|
|
|
|
83
|
|
|
return $display_value; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get settings fields. |
88
|
|
|
* |
89
|
|
|
* @return array<int, array<string, callable|int|string|bool|array<int|string,int|string>>> |
90
|
|
|
*/ |
91
|
|
|
public function get_settings_fields() { |
92
|
|
|
$fields = array(); |
93
|
|
|
|
94
|
|
|
// Website Key. |
95
|
|
|
$fields[] = array( |
96
|
|
|
'section' => 'general', |
97
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
98
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_website_key', |
99
|
|
|
'title' => __( 'Website Key', 'pronamic_ideal' ), |
100
|
|
|
'type' => 'text', |
101
|
|
|
'classes' => array( 'code' ), |
102
|
|
|
'tooltip' => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ), |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
// Secret Key. |
106
|
|
|
$fields[] = array( |
107
|
|
|
'section' => 'general', |
108
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
109
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_secret_key', |
110
|
|
|
'title' => __( 'Secret Key', 'pronamic_ideal' ), |
111
|
|
|
'type' => 'text', |
112
|
|
|
'classes' => array( 'regular-text', 'code' ), |
113
|
|
|
'tooltip' => __( 'Secret key as mentioned in the Buckaroo dashboard on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ), |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
// Excluded services. |
117
|
|
|
$fields[] = array( |
118
|
|
|
'section' => 'advanced', |
119
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
120
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_excluded_services', |
121
|
|
|
'title' => __( 'Excluded services', 'pronamic_ideal' ), |
122
|
|
|
'type' => 'text', |
123
|
|
|
'classes' => array( 'regular-text', 'code' ), |
124
|
|
|
'tooltip' => sprintf( |
125
|
|
|
/* translators: %s: <code>brq_parameter</code> */ |
126
|
|
|
__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ), |
127
|
|
|
sprintf( '<code>%s</code>', 'brq_exludedservices' ) |
128
|
|
|
), |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
// Invoice number. |
132
|
|
|
$fields[] = array( |
133
|
|
|
'section' => 'advanced', |
134
|
|
|
'filter' => FILTER_SANITIZE_STRING, |
135
|
|
|
'meta_key' => '_pronamic_gateway_buckaroo_invoice_number', |
136
|
|
|
'title' => __( 'Invoice number', 'pronamic_ideal' ), |
137
|
|
|
'type' => 'text', |
138
|
|
|
'classes' => array( 'regular-text', 'code' ), |
139
|
|
|
'tooltip' => sprintf( |
140
|
|
|
/* translators: %s: <code>brq_parameter</code> */ |
141
|
|
|
__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ), |
142
|
|
|
sprintf( '<code>%s</code>', 'brq_invoicenumber' ) |
143
|
|
|
), |
144
|
|
|
'description' => sprintf( |
145
|
|
|
'%s<br />%s', |
146
|
|
|
/* translators: %s: <code>{tag}</code> */ |
147
|
|
|
sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ), |
148
|
|
|
/* translators: %s: default code */ |
149
|
|
|
sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' ) |
150
|
|
|
), |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
// Push URL. |
154
|
|
|
$fields[] = array( |
155
|
|
|
'section' => 'feedback', |
156
|
|
|
'title' => __( 'Push URL', 'pronamic_ideal' ), |
157
|
|
|
'type' => 'text', |
158
|
|
|
'classes' => array( 'large-text', 'code' ), |
159
|
|
|
'value' => \rest_url( self::REST_ROUTE_NAMESPACE . '/push' ), |
160
|
|
|
'readonly' => true, |
161
|
|
|
'tooltip' => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
return $fields; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Get config. |
169
|
|
|
* |
170
|
|
|
* @param int $post_id Gateway config post ID. |
171
|
|
|
* |
172
|
|
|
* @return Config |
173
|
|
|
*/ |
174
|
|
|
public function get_config( $post_id ) { |
175
|
|
|
$config = new Config(); |
176
|
|
|
|
177
|
|
|
$config->website_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true ); |
|
|
|
|
178
|
|
|
$config->secret_key = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true ); |
|
|
|
|
179
|
|
|
$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true ); |
|
|
|
|
180
|
|
|
$config->invoice_number = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true ); |
|
|
|
|
181
|
|
|
$config->mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true ); |
|
|
|
|
182
|
|
|
|
183
|
|
|
return $config; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get gateway. |
188
|
|
|
* |
189
|
|
|
* @param int $post_id Post ID. |
190
|
|
|
* @return Gateway |
191
|
|
|
*/ |
192
|
|
|
public function get_gateway( $post_id ) { |
193
|
|
|
return new Gateway( $this->get_config( $post_id ) ); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.