Version Description
21-03-2019 =
Fix - Fix caching issues for methods check
Fix - Only run isValidForUse (and resulting API calls) in the WooCommerce settings
Download this release
Release Info
Developer | davdebcom |
Plugin | Mollie Payments for WooCommerce |
Version | 5.1.4 |
Comparing to | |
See all releases |
Code changes from version 5.1.3 to 5.1.4
- includes/mollie/wc/gateway/abstract.php +62 -91
- includes/mollie/wc/helper/data.php +15 -20
- includes/mollie/wc/plugin.php +1 -1
- mollie-payments-for-woocommerce.php +1 -1
- readme.txt +6 -1
includes/mollie/wc/gateway/abstract.php
CHANGED
@@ -201,47 +201,67 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
|
|
201 |
*/
|
202 |
protected function isValidForUse()
|
203 |
{
|
204 |
-
$settings = Mollie_WC_Plugin::getSettingsHelper();
|
205 |
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
'</a>'
|
215 |
-
);
|
216 |
|
217 |
-
|
218 |
-
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
__('%s not enabled in your Mollie profile. You can enabled it by editing your %sMollie profile%s.', 'mollie-payments-for-woocommerce'),
|
225 |
-
$this->getDefaultTitle(),
|
226 |
-
'<a href="https://www.mollie.com/dashboard/settings/profiles" target="_blank">',
|
227 |
-
'</a>'
|
228 |
-
);
|
229 |
|
230 |
-
|
231 |
-
|
232 |
|
233 |
-
|
234 |
-
{
|
235 |
-
$this->errors[] = sprintf(
|
236 |
-
/* translators: Placeholder 1: WooCommerce currency, placeholder 2: Supported Mollie currencies */
|
237 |
-
__('Current shop currency %s not supported by Mollie. Read more about %ssupported currencies and payment methods.%s ', 'mollie-payments-for-woocommerce'),
|
238 |
-
get_woocommerce_currency(),
|
239 |
-
'<a href="https://help.mollie.com/hc/en-us/articles/360003980013-Which-currencies-are-supported-and-what-is-the-settlement-currency-" target="_blank">',
|
240 |
-
'</a>'
|
241 |
-
);
|
242 |
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
return true;
|
247 |
}
|
@@ -1888,71 +1908,22 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
|
|
1888 |
*/
|
1889 |
protected function isAvailableMethodInCheckout( $filters ) {
|
1890 |
|
1891 |
-
$methods = array ();
|
1892 |
-
|
1893 |
$settings_helper = Mollie_WC_Plugin::getSettingsHelper();
|
1894 |
$test_mode = $settings_helper->isTestModeEnabled();
|
1895 |
|
1896 |
-
|
1897 |
-
|
1898 |
-
$filters_key = $filters['amount']['currency'] . '_' . str_replace( '.', '', $filters['amount']['value'] ) . '_' . $filters['billingCountry'] . '_' . $filters['locale'] . '_' . $filters['sequenceType'];
|
1899 |
-
$transient_id = Mollie_WC_Plugin::getDataHelper()->getTransientId( 'api_methods_' . ( $test_mode ? 'test' : 'live' ) . '_' . $filters_key );
|
1900 |
-
|
1901 |
-
$cached = unserialize( get_transient( $transient_id ) );
|
1902 |
|
1903 |
-
|
1904 |
-
|
1905 |
-
}
|
1906 |
-
|
1907 |
-
if ( empty ( $methods ) ) {
|
1908 |
-
|
1909 |
-
// Remove existing expired transients
|
1910 |
-
delete_transient( $transient_id );
|
1911 |
-
|
1912 |
-
// Get payment methods at Mollie
|
1913 |
-
$methods = Mollie_WC_Plugin::getApiHelper()->getApiClient( $test_mode )->methods->all( $filters );
|
1914 |
-
|
1915 |
-
$methods_cleaned = array();
|
1916 |
-
|
1917 |
-
foreach ( $methods as $method ) {
|
1918 |
-
|
1919 |
-
$public_properties = get_object_vars( $method ); // get only the public properties of the object
|
1920 |
-
$methods_cleaned[] = $public_properties;
|
1921 |
-
|
1922 |
-
}
|
1923 |
-
|
1924 |
-
if ( $methods_cleaned === NULL ) {
|
1925 |
-
$methods_cleaned = array(0);
|
1926 |
-
}
|
1927 |
-
|
1928 |
-
$methods = $methods_cleaned;
|
1929 |
|
1930 |
-
|
1931 |
-
|
1932 |
-
set_transient( $transient_id, serialize( $methods ), MINUTE_IN_SECONDS * 5 );
|
1933 |
-
}
|
1934 |
-
catch ( Exception $e ) {
|
1935 |
-
Mollie_WC_Plugin::debug( __FUNCTION__ . ": No caching because serialization failed." );
|
1936 |
-
}
|
1937 |
-
|
1938 |
-
}
|
1939 |
-
|
1940 |
-
// Get the ID of the WooCommerce/Mollie payment method
|
1941 |
-
$woocommerce_method = $this->getMollieMethodId();
|
1942 |
|
1943 |
-
|
1944 |
-
|
1945 |
-
|
1946 |
-
if ( $method['id'] == $woocommerce_method ) {
|
1947 |
-
return true;
|
1948 |
-
}
|
1949 |
}
|
1950 |
}
|
1951 |
-
catch ( \Mollie\Api\Exceptions\ApiException $e ) {
|
1952 |
-
|
1953 |
-
Mollie_WC_Plugin::debug( __FUNCTION__ . ": Could not check availability of Mollie payment methods (" . ( $test_mode ? 'test' : 'live' ) . "): " . $e->getMessage() . ' (' . get_class( $e ) . ')' );
|
1954 |
-
|
1955 |
-
}
|
1956 |
|
1957 |
return false;
|
1958 |
}
|
201 |
*/
|
202 |
protected function isValidForUse()
|
203 |
{
|
|
|
204 |
|
205 |
+
//
|
206 |
+
// Abort if this is not the WooCommerce settings page
|
207 |
+
//
|
208 |
|
209 |
+
// Return if function get_current_screen() is not defined
|
210 |
+
if ( ! function_exists( 'get_current_screen' ) ) {
|
211 |
+
return true;
|
212 |
+
}
|
|
|
|
|
213 |
|
214 |
+
// Try getting get_current_screen()
|
215 |
+
$current_screen = get_current_screen();
|
216 |
|
217 |
+
// Return if get_current_screen() isn't set
|
218 |
+
if ( ! $current_screen ) {
|
219 |
+
return true;
|
220 |
+
}
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
+
// Remove old MisterCash (only) from WooCommerce Payment settings
|
223 |
+
if ( is_admin() && ! empty( $current_screen->base ) && $current_screen->base == 'woocommerce_page_wc-settings' ) {
|
224 |
|
225 |
+
$settings = Mollie_WC_Plugin::getSettingsHelper();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
+
if ( ! $this->isValidApiKeyProvided() ) {
|
228 |
+
$test_mode = $settings->isTestModeEnabled();
|
229 |
+
|
230 |
+
$this->errors[] = ( $test_mode ? __( 'Test mode enabled.', 'mollie-payments-for-woocommerce' ) . ' ' : '' ) . sprintf(
|
231 |
+
/* translators: The surrounding %s's Will be replaced by a link to the global setting page */
|
232 |
+
__( 'No API key provided. Please %sset you Mollie API key%s first.', 'mollie-payments-for-woocommerce' ),
|
233 |
+
'<a href="' . $settings->getGlobalSettingsUrl() . '">',
|
234 |
+
'</a>'
|
235 |
+
);
|
236 |
+
|
237 |
+
return false;
|
238 |
+
}
|
239 |
+
|
240 |
+
// This should be simpler, check for specific payment method in settings, not on all pages
|
241 |
+
if ( null === $this->getMollieMethod() ) {
|
242 |
+
$this->errors[] = sprintf(
|
243 |
+
/* translators: Placeholder 1: payment method title. The surrounding %s's Will be replaced by a link to the Mollie profile */
|
244 |
+
__( '%s not enabled in your Mollie profile. You can enabled it by editing your %sMollie profile%s.', 'mollie-payments-for-woocommerce' ),
|
245 |
+
$this->getDefaultTitle(),
|
246 |
+
'<a href="https://www.mollie.com/dashboard/settings/profiles" target="_blank">',
|
247 |
+
'</a>'
|
248 |
+
);
|
249 |
+
|
250 |
+
return false;
|
251 |
+
}
|
252 |
+
|
253 |
+
if ( ! $this->isCurrencySupported() ) {
|
254 |
+
$this->errors[] = sprintf(
|
255 |
+
/* translators: Placeholder 1: WooCommerce currency, placeholder 2: Supported Mollie currencies */
|
256 |
+
__( 'Current shop currency %s not supported by Mollie. Read more about %ssupported currencies and payment methods.%s ', 'mollie-payments-for-woocommerce' ),
|
257 |
+
get_woocommerce_currency(),
|
258 |
+
'<a href="https://help.mollie.com/hc/en-us/articles/360003980013-Which-currencies-are-supported-and-what-is-the-settlement-currency-" target="_blank">',
|
259 |
+
'</a>'
|
260 |
+
);
|
261 |
+
|
262 |
+
return false;
|
263 |
+
}
|
264 |
+
}
|
265 |
|
266 |
return true;
|
267 |
}
|
1908 |
*/
|
1909 |
protected function isAvailableMethodInCheckout( $filters ) {
|
1910 |
|
|
|
|
|
1911 |
$settings_helper = Mollie_WC_Plugin::getSettingsHelper();
|
1912 |
$test_mode = $settings_helper->isTestModeEnabled();
|
1913 |
|
1914 |
+
$data_helper = Mollie_WC_Plugin::getDataHelper();
|
1915 |
+
$methods = $data_helper->getApiPaymentMethods( $test_mode, $use_cache = true, $filters);
|
|
|
|
|
|
|
|
|
1916 |
|
1917 |
+
// Get the ID of the WooCommerce/Mollie payment method
|
1918 |
+
$woocommerce_method = $this->getMollieMethodId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1919 |
|
1920 |
+
// Set all other payment methods to false, so they can be updated if available
|
1921 |
+
foreach ( $methods as $method ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1922 |
|
1923 |
+
if ( $method['id'] == $woocommerce_method ) {
|
1924 |
+
return true;
|
|
|
|
|
|
|
|
|
1925 |
}
|
1926 |
}
|
|
|
|
|
|
|
|
|
|
|
1927 |
|
1928 |
return false;
|
1929 |
}
|
includes/mollie/wc/helper/data.php
CHANGED
@@ -308,24 +308,25 @@ class Mollie_WC_Helper_Data
|
|
308 |
return self::$recurring_api_methods;
|
309 |
}
|
310 |
|
311 |
-
|
312 |
|
313 |
-
$methods =
|
314 |
|
315 |
-
|
|
|
|
|
316 |
|
317 |
-
|
318 |
-
$transient_id = Mollie_WC_Plugin::getDataHelper()->getTransientId( 'api_methods_' . ( $test_mode ? 'test' : 'live' ) . $filters_key );
|
319 |
|
320 |
-
|
321 |
-
$cached_methods = unserialize( get_transient( $transient_id ) );
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
}
|
327 |
|
328 |
-
|
|
|
329 |
|
330 |
// Remove existing expired transients
|
331 |
delete_transient( $transient_id );
|
@@ -337,16 +338,11 @@ class Mollie_WC_Helper_Data
|
|
337 |
$methods_cleaned = array();
|
338 |
|
339 |
foreach ( $methods as $method ) {
|
340 |
-
|
341 |
$public_properties = get_object_vars( $method ); // get only the public properties of the object
|
342 |
$methods_cleaned[] = $public_properties;
|
343 |
-
|
344 |
-
}
|
345 |
-
|
346 |
-
if ( $methods_cleaned === NULL ) {
|
347 |
-
$methods_cleaned = array(0);
|
348 |
}
|
349 |
|
|
|
350 |
$methods = $methods_cleaned;
|
351 |
|
352 |
// Set new transients (as cache)
|
@@ -356,16 +352,15 @@ class Mollie_WC_Helper_Data
|
|
356 |
catch ( Exception $e ) {
|
357 |
Mollie_WC_Plugin::debug( __FUNCTION__ . ": No caching because serialization failed." );
|
358 |
}
|
359 |
-
|
360 |
}
|
361 |
|
362 |
return $methods;
|
363 |
}
|
364 |
catch ( \Mollie\Api\Exceptions\ApiException $e ) {
|
365 |
Mollie_WC_Plugin::debug( __FUNCTION__ . ": Could not load Mollie methods (" . ( $test_mode ? 'test' : 'live' ) . "): " . $e->getMessage() . ' (' . get_class( $e ) . ')' );
|
366 |
-
}
|
367 |
|
368 |
-
|
|
|
369 |
}
|
370 |
|
371 |
/**
|
308 |
return self::$recurring_api_methods;
|
309 |
}
|
310 |
|
311 |
+
public function getApiPaymentMethods( $test_mode = false, $use_cache = true, $filters = array () ) {
|
312 |
|
313 |
+
$methods = false;
|
314 |
|
315 |
+
$filters_key = $filters;
|
316 |
+
$filters_key['mode'] = ( $test_mode ? 'test' : 'live' );
|
317 |
+
$filters_key['api'] = 'methods';
|
318 |
|
319 |
+
try {
|
|
|
320 |
|
321 |
+
$transient_id = Mollie_WC_Plugin::getDataHelper()->getTransientId( md5(http_build_query($filters_key)) );
|
|
|
322 |
|
323 |
+
if ($use_cache) {
|
324 |
+
// When no cache exists $methods will be `false`
|
325 |
+
$methods = unserialize( get_transient( $transient_id ) );
|
326 |
}
|
327 |
|
328 |
+
// No cache exists, call the API and cache the result
|
329 |
+
if ( $methods === false ) {
|
330 |
|
331 |
// Remove existing expired transients
|
332 |
delete_transient( $transient_id );
|
338 |
$methods_cleaned = array();
|
339 |
|
340 |
foreach ( $methods as $method ) {
|
|
|
341 |
$public_properties = get_object_vars( $method ); // get only the public properties of the object
|
342 |
$methods_cleaned[] = $public_properties;
|
|
|
|
|
|
|
|
|
|
|
343 |
}
|
344 |
|
345 |
+
// $methods_cleaned is empty array when the API doesn't return any methods, cache the empty array
|
346 |
$methods = $methods_cleaned;
|
347 |
|
348 |
// Set new transients (as cache)
|
352 |
catch ( Exception $e ) {
|
353 |
Mollie_WC_Plugin::debug( __FUNCTION__ . ": No caching because serialization failed." );
|
354 |
}
|
|
|
355 |
}
|
356 |
|
357 |
return $methods;
|
358 |
}
|
359 |
catch ( \Mollie\Api\Exceptions\ApiException $e ) {
|
360 |
Mollie_WC_Plugin::debug( __FUNCTION__ . ": Could not load Mollie methods (" . ( $test_mode ? 'test' : 'live' ) . "): " . $e->getMessage() . ' (' . get_class( $e ) . ')' );
|
|
|
361 |
|
362 |
+
return array();
|
363 |
+
}
|
364 |
}
|
365 |
|
366 |
/**
|
includes/mollie/wc/plugin.php
CHANGED
@@ -7,7 +7,7 @@ class Mollie_WC_Plugin
|
|
7 |
{
|
8 |
const PLUGIN_ID = 'mollie-payments-for-woocommerce';
|
9 |
const PLUGIN_TITLE = 'Mollie Payments for WooCommerce';
|
10 |
-
const PLUGIN_VERSION = '5.1.
|
11 |
|
12 |
const DB_VERSION = '1.0';
|
13 |
const DB_VERSION_PARAM_NAME = 'mollie-db-version';
|
7 |
{
|
8 |
const PLUGIN_ID = 'mollie-payments-for-woocommerce';
|
9 |
const PLUGIN_TITLE = 'Mollie Payments for WooCommerce';
|
10 |
+
const PLUGIN_VERSION = '5.1.4';
|
11 |
|
12 |
const DB_VERSION = '1.0';
|
13 |
const DB_VERSION_PARAM_NAME = 'mollie-db-version';
|
mollie-payments-for-woocommerce.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Mollie Payments for WooCommerce
|
4 |
* Plugin URI: https://www.mollie.com
|
5 |
* Description: Accept payments in WooCommerce with the official Mollie plugin
|
6 |
-
* Version: 5.1.
|
7 |
* Author: Mollie
|
8 |
* Author URI: https://www.mollie.com
|
9 |
* Requires at least: 3.8
|
3 |
* Plugin Name: Mollie Payments for WooCommerce
|
4 |
* Plugin URI: https://www.mollie.com
|
5 |
* Description: Accept payments in WooCommerce with the official Mollie plugin
|
6 |
+
* Version: 5.1.4
|
7 |
* Author: Mollie
|
8 |
* Author URI: https://www.mollie.com
|
9 |
* Requires at least: 3.8
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: daanvm, davdebcom, l.vangunst, ndijkstra, robin-mollie
|
|
3 |
Tags: mollie, payments, payment gateway, woocommerce, credit card
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 5.1
|
6 |
-
Stable tag: 5.1.
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -181,6 +181,11 @@ Automatic updates should work like a charm; as always though, ensure you backup
|
|
181 |
|
182 |
== Changelog ==
|
183 |
|
|
|
|
|
|
|
|
|
|
|
184 |
= 5.1.3 - 21-03-2019 =
|
185 |
|
186 |
* Fix - Revert: Check that cached methods are stored as array, otherwise retrieve from API, fixes 'Cannot use object' error
|
3 |
Tags: mollie, payments, payment gateway, woocommerce, credit card
|
4 |
Requires at least: 3.8
|
5 |
Tested up to: 5.1
|
6 |
+
Stable tag: 5.1.4
|
7 |
Requires PHP: 5.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
181 |
|
182 |
== Changelog ==
|
183 |
|
184 |
+
= 5.1.4 - 21-03-2019 =
|
185 |
+
|
186 |
+
* Fix - Fix caching issues for methods check
|
187 |
+
* Fix - Only run isValidForUse (and resulting API calls) in the WooCommerce settings
|
188 |
+
|
189 |
= 5.1.3 - 21-03-2019 =
|
190 |
|
191 |
* Fix - Revert: Check that cached methods are stored as array, otherwise retrieve from API, fixes 'Cannot use object' error
|