1 | <?php |
||
2 | /** |
||
3 | * Mollie integration. |
||
4 | * |
||
5 | * @author Pronamic <[email protected]> |
||
6 | * @copyright 2005-2019 Pronamic |
||
7 | * @license GPL-3.0-or-later |
||
8 | * @package Pronamic\WordPress\Pay |
||
9 | */ |
||
10 | |||
11 | namespace Pronamic\WordPress\Pay\Gateways\Mollie; |
||
12 | |||
13 | use Pronamic\WordPress\Pay\Core\PaymentMethods; |
||
14 | use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration; |
||
15 | use Pronamic\WordPress\Pay\Payments\Payment; |
||
16 | use WP_User; |
||
17 | |||
18 | /** |
||
19 | * Title: Mollie integration |
||
20 | * Description: |
||
21 | * Copyright: 2005-2019 Pronamic |
||
22 | * Company: Pronamic |
||
23 | * |
||
24 | * @author Remco Tolsma |
||
25 | * @version 2.0.8 |
||
26 | * @since 1.0.0 |
||
27 | */ |
||
28 | class Integration extends AbstractIntegration { |
||
29 | /** |
||
30 | * Register URL. |
||
31 | * |
||
32 | 7 | * @var string |
|
33 | 7 | */ |
|
34 | 7 | public $register_url; |
|
35 | 7 | ||
36 | 7 | /** |
|
37 | 7 | * Construct and intialize Mollie integration. |
|
38 | 7 | */ |
|
39 | 7 | public function __construct() { |
|
40 | 7 | $this->id = 'mollie'; |
|
41 | $this->name = 'Mollie'; |
||
42 | $this->url = 'http://www.mollie.com/en/'; |
||
43 | $this->product_url = __( 'https://www.mollie.com/en/pricing', 'pronamic_ideal' ); |
||
44 | $this->dashboard_url = 'https://www.mollie.com/dashboard/'; |
||
45 | $this->register_url = 'https://www.mollie.com/nl/signup/665327'; |
||
46 | $this->provider = 'mollie'; |
||
47 | $this->supports = array( |
||
48 | 7 | 'payment_status_request', |
|
49 | 'recurring_direct_debit', |
||
50 | 7 | 'recurring_credit_card', |
|
51 | 7 | 'recurring', |
|
52 | 'webhook', |
||
53 | 'webhook_log', |
||
54 | 7 | 'webhook_no_config', |
|
55 | ); |
||
56 | |||
57 | $this->set_manual_url( __( 'https://www.pronamic.eu/support/how-to-connect-mollie-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) ); |
||
0 ignored issues
–
show
|
|||
58 | |||
59 | // Actions. |
||
60 | $function = array( __NAMESPACE__ . '\Listener', 'listen' ); |
||
61 | |||
62 | if ( ! has_action( 'wp_loaded', $function ) ) { |
||
63 | add_action( 'wp_loaded', $function ); |
||
64 | } |
||
65 | |||
66 | if ( is_admin() ) { |
||
67 | 7 | $function = array( __CLASS__, 'user_profile' ); |
|
68 | |||
69 | 7 | if ( ! has_action( 'show_user_profile', $function ) ) { |
|
70 | 7 | add_action( 'show_user_profile', $function ); |
|
71 | } |
||
72 | |||
73 | 7 | if ( ! has_action( 'edit_user_profile', $function ) ) { |
|
74 | 7 | add_action( 'edit_user_profile', $function ); |
|
75 | } |
||
76 | } |
||
77 | |||
78 | // Filters. |
||
79 | $function = array( $this, 'next_payment_delivery_date' ); |
||
80 | |||
81 | 1 | if ( ! \has_filter( 'pronamic_pay_subscription_next_payment_delivery_date', $function ) ) { |
|
82 | 1 | \add_filter( 'pronamic_pay_subscription_next_payment_delivery_date', $function, 10, 2 ); |
|
83 | } |
||
84 | |||
85 | 1 | add_filter( 'pronamic_payment_provider_url_mollie', array( $this, 'payment_provider_url' ), 10, 2 ); |
|
86 | 1 | } |
|
87 | 1 | ||
88 | 1 | /** |
|
89 | 1 | * Get settings fields. |
|
90 | 1 | * |
|
91 | * @return array |
||
92 | 1 | */ |
|
93 | public function get_settings_fields() { |
||
94 | $fields = array(); |
||
95 | |||
96 | 1 | // API Key. |
|
97 | 1 | $fields[] = array( |
|
98 | 'section' => 'general', |
||
99 | 1 | 'filter' => FILTER_SANITIZE_STRING, |
|
100 | 1 | 'meta_key' => '_pronamic_gateway_mollie_api_key', |
|
101 | 1 | 'title' => _x( 'API Key', 'mollie', 'pronamic_ideal' ), |
|
102 | 1 | 'type' => 'text', |
|
103 | 1 | 'classes' => array( 'regular-text', 'code' ), |
|
104 | 'tooltip' => __( 'API key as mentioned in the payment provider dashboard', 'pronamic_ideal' ), |
||
105 | 1 | ); |
|
106 | 1 | ||
107 | // Due date days. |
||
108 | 1 | $fields[] = array( |
|
109 | 1 | 'section' => 'advanced', |
|
110 | 1 | 'filter' => \FILTER_SANITIZE_NUMBER_INT, |
|
111 | 1 | 'meta_key' => '_pronamic_gateway_mollie_due_date_days', |
|
112 | 'title' => _x( 'Due date days', 'mollie', 'pronamic_ideal' ), |
||
113 | 'type' => 'number', |
||
114 | 'min' => 1, |
||
115 | 'max' => 100, |
||
116 | 1 | 'classes' => array( 'regular-text' ), |
|
117 | 1 | 'tooltip' => __( 'Number of days after which a bank transfer payment expires.', 'pronamic_ideal' ), |
|
118 | 1 | 'description' => sprintf( |
|
119 | 1 | /* translators: 1: <code>1</code>, 2: <code>100</code>, 3: <code>12</code> */ |
|
120 | __( 'Minimum %1$s and maximum %2$s days. Default: %3$s days.', 'pronamic_ideal' ), |
||
121 | 1 | sprintf( '<code>%s</code>', '1' ), |
|
122 | sprintf( '<code>%s</code>', '100' ), |
||
123 | 1 | sprintf( '<code>%s</code>', '12' ) |
|
124 | ), |
||
125 | ); |
||
126 | 1 | ||
127 | // Webhook. |
||
128 | $fields[] = array( |
||
129 | 'section' => 'feedback', |
||
130 | 'title' => __( 'Webhook URL', 'pronamic_ideal' ), |
||
131 | 'type' => 'text', |
||
132 | 'classes' => array( 'large-text', 'code' ), |
||
133 | 'value' => add_query_arg( 'mollie_webhook', '', home_url( '/' ) ), |
||
134 | 'readonly' => true, |
||
135 | 'tooltip' => __( 'The Webhook URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ), |
||
136 | ); |
||
137 | |||
138 | return $fields; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Save post. |
||
143 | * |
||
144 | * @link https://developer.wordpress.org/reference/functions/get_post_meta/ |
||
145 | * |
||
146 | * @param int $post_id Post ID. |
||
147 | */ |
||
148 | public function save_post( $post_id ) { |
||
149 | $api_key = get_post_meta( $post_id, '_pronamic_gateway_mollie_api_key', true ); |
||
150 | |||
151 | if ( ! is_string( $api_key ) ) { |
||
152 | return; |
||
153 | } |
||
154 | |||
155 | $api_key_prefix = substr( $api_key, 0, 4 ); |
||
156 | |||
157 | switch ( $api_key_prefix ) { |
||
158 | case 'live': |
||
159 | update_post_meta( $post_id, '_pronamic_gateway_mode', Gateway::MODE_LIVE ); |
||
160 | |||
161 | return; |
||
162 | case 'test': |
||
163 | update_post_meta( $post_id, '_pronamic_gateway_mode', Gateway::MODE_TEST ); |
||
164 | |||
165 | return; |
||
166 | } |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * User profile. |
||
171 | * |
||
172 | * @param WP_User $user WordPress user. |
||
173 | * |
||
174 | * @since 1.1.6 |
||
175 | * @link https://github.com/WordPress/WordPress/blob/4.5.2/wp-admin/user-edit.php#L578-L600 |
||
176 | */ |
||
177 | 1 | public static function user_profile( $user ) { |
|
178 | 1 | include __DIR__ . '/../views/html-admin-user-profile.php'; |
|
179 | 1 | } |
|
180 | 1 | ||
181 | /** |
||
182 | * Payment provider URL. |
||
183 | * |
||
184 | * @param string $url Payment provider URL. |
||
185 | * @param Payment $payment Payment. |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function payment_provider_url( $url, Payment $payment ) { |
||
190 | 2 | return sprintf( |
|
191 | 2 | 'https://www.mollie.com/dashboard/payments/%s', |
|
192 | $payment->get_transaction_id() |
||
193 | 2 | ); |
|
194 | 2 | } |
|
195 | 2 | /** |
|
196 | 2 | * Get configuration by post ID. |
|
197 | * |
||
198 | 2 | * @param int $post_id Post ID. |
|
199 | * |
||
200 | * @return Config |
||
201 | */ |
||
202 | public function get_config( $post_id ) { |
||
203 | $config = new Config(); |
||
204 | |||
205 | $config->id = intval( $post_id ); |
||
206 | $config->api_key = $this->get_meta( $post_id, 'mollie_api_key' ); |
||
207 | 1 | $config->mode = $this->get_meta( $post_id, 'mode' ); |
|
208 | 1 | $config->due_date_days = $this->get_meta( $post_id, 'mollie_due_date_days' ); |
|
209 | |||
210 | return $config; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Get gateway. |
||
215 | * |
||
216 | * @param int $post_id Post ID. |
||
217 | * @return Gateway |
||
218 | */ |
||
219 | public function get_gateway( $post_id ) { |
||
220 | return new Gateway( $this->get_config( $post_id ) ); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Next payment delivery date. |
||
225 | * |
||
226 | * @param \DateTime $next_payment_delivery_date Next payment delivery date. |
||
227 | * @param Payment $payment Payment. |
||
228 | * |
||
229 | * @return \DateTime |
||
230 | */ |
||
231 | public function next_payment_delivery_date( \DateTime $next_payment_delivery_date, Payment $payment ) { |
||
232 | $config_id = $payment->get_config_id(); |
||
233 | |||
234 | if ( null === $config_id ) { |
||
235 | return $next_payment_delivery_date; |
||
236 | } |
||
237 | |||
238 | // Check gateway. |
||
239 | $gateway_id = \get_post_meta( $config_id, '_pronamic_gateway_id', true ); |
||
240 | |||
241 | if ( 'mollie' !== $gateway_id ) { |
||
242 | return $next_payment_delivery_date; |
||
243 | } |
||
244 | |||
245 | // Check direct debit payment method. |
||
246 | $method = $payment->get_method(); |
||
247 | |||
248 | if ( null === $method ) { |
||
249 | return $next_payment_delivery_date; |
||
250 | } |
||
251 | |||
252 | if ( ! PaymentMethods::is_direct_debit_method( $method ) ) { |
||
253 | return $next_payment_delivery_date; |
||
254 | } |
||
255 | |||
256 | // Check subscription. |
||
257 | $subscription = $payment->get_subscription(); |
||
258 | |||
259 | if ( null === $subscription ) { |
||
260 | return $next_payment_delivery_date; |
||
261 | } |
||
262 | |||
263 | // Base delivery date on next payment date. |
||
264 | $next_payment_date = $subscription->get_next_payment_date(); |
||
265 | |||
266 | if ( null === $next_payment_date ) { |
||
267 | return $next_payment_delivery_date; |
||
268 | } |
||
269 | |||
270 | $next_payment_delivery_date = clone $next_payment_date; |
||
271 | |||
272 | // Textual representation of the day of the week, Sunday through Saturday. |
||
273 | $day_of_week = $next_payment_delivery_date->format( 'l' ); |
||
274 | |||
275 | /* |
||
276 | * Subtract days from next payment date for earlier delivery. |
||
277 | * |
||
278 | * @link https://help.mollie.com/hc/en-us/articles/115000785649-When-are-direct-debit-payments-processed-and-paid-out- |
||
279 | * @link https://help.mollie.com/hc/en-us/articles/115002540294-What-are-the-payment-methods-processing-times- |
||
280 | */ |
||
281 | switch ( $day_of_week ) { |
||
282 | case 'Monday': |
||
283 | $next_payment_delivery_date->modify( '-3 days' ); |
||
284 | |||
285 | break; |
||
286 | case 'Saturday': |
||
287 | $next_payment_delivery_date->modify( '-2 days' ); |
||
288 | |||
289 | break; |
||
290 | case 'Sunday': |
||
291 | $next_payment_delivery_date->modify( '-3 days' ); |
||
292 | |||
293 | break; |
||
294 | default: |
||
295 | $next_payment_delivery_date->modify( '-1 day' ); |
||
296 | |||
297 | break; |
||
298 | } |
||
299 | |||
300 | $next_payment_delivery_date->setTime( 0, 0, 0 ); |
||
301 | |||
302 | return $next_payment_delivery_date; |
||
303 | } |
||
304 | } |
||
305 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.