Mollie Payments for WooCommerce - Version 3.0.4

Version Description

  • 24/05/2018 =

  • Fix - Limit order status update for cancelled and expired payments if another non-Mollie payment gateway also started payment processing (and is active) for that order, prevents expired and cancelled Mollie payments from cancelling the order

  • Fix - Webhook URL's with double slashes, caused by some multilanguage plugins (Polylang etc)

  • Fix - Add extra condition to make sure customers with paid payments are redirected to correct URL after payment

  • Fix - Incorrect return page after payment for some orders, fix was to get payment without cache at least once on return URL (in case Webhook Url is still processing)

Download this release

Release Info

Developer davdebcom
Plugin Icon wp plugin Mollie Payments for WooCommerce
Version 3.0.4
Comparing to
See all releases

Code changes from version 3.0.3 to 3.0.4

includes/mollie/wc/gateway/abstract.php CHANGED
@@ -940,8 +940,22 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
940
  // Overwrite gateway-wide
941
  $new_order_status = apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_order_status_cancelled_' . $this->id, $new_order_status);
942
 
943
- // Reset state
944
- $this->updateOrderStatus($order, $new_order_status);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
945
 
946
  $paymentMethodTitle = $this->getPaymentMethodTitle($payment);
947
 
@@ -1000,8 +1014,22 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
1000
  // Overwrite gateway-wide
1001
  $new_order_status = apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_order_status_expired_' . $this->id, $new_order_status);
1002
 
1003
- // Cancel order
1004
- $this->updateOrderStatus($order, $new_order_status);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1005
 
1006
  $order->add_order_note(sprintf(
1007
  /* translators: Placeholder 1: payment method title, placeholder 2: payment ID */
@@ -1043,34 +1071,31 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
1043
  } else {
1044
  Mollie_WC_Plugin::addNotice( __( 'You have cancelled your payment. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' ) );
1045
 
 
1046
  if ( method_exists( $order, 'get_checkout_payment_url' ) ) {
1047
- /*
1048
- * Return to order payment page
1049
- */
1050
  return $order->get_checkout_payment_url( false );
1051
  }
1052
  }
1053
 
1054
- /*
1055
- * Return to cart
1056
- */
1057
- if ( version_compare( WC_VERSION, '2.5', '<' ) ) {
1058
- return WC()->cart->get_checkout_url();
1059
- } else {
1060
  return $order->get_checkout_payment_url( false );
1061
  }
 
1062
  }
1063
 
1064
  if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1065
- $payment = Mollie_WC_Plugin::getDataHelper()->getActiveMolliePayment($order->id);
1066
  } else {
1067
- $payment = Mollie_WC_Plugin::getDataHelper()->getActiveMolliePayment($order->get_id());
1068
  }
1069
 
1070
- if ( ! $payment->isOpen() && ! $payment->isPending() ) {
1071
  Mollie_WC_Plugin::addNotice( __( 'Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' ) );
1072
-
1073
- return $order->get_checkout_payment_url( false );
 
 
1074
  }
1075
 
1076
  }
@@ -1385,34 +1410,47 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
1385
  }
1386
 
1387
  /**
1388
- * @param WC_Order $order
1389
- * @return bool
1390
- */
1391
- protected function orderNeedsPayment (WC_Order $order)
1392
- {
1393
- // Check whether the order is processed and paid via another gateway
1394
- if ( $this->isOrderPaidByOtherGateway( $order ) ) {
1395
- return false;
1396
- }
1397
 
1398
- // Check whether the order is processed and paid via Mollie
1399
- if ( ! $this->isOrderPaidAndProcessed( $order ) ) {
1400
- return true;
1401
- }
 
1402
 
1403
- if ($order->needs_payment())
1404
- {
1405
- return true;
1406
- }
1407
 
1408
- // Has initial order status 'on-hold'
1409
- if ($this->getInitialOrderStatus() === self::STATUS_ON_HOLD && Mollie_WC_Plugin::getDataHelper()->hasOrderStatus($order, self::STATUS_ON_HOLD))
1410
- {
1411
- return true;
1412
- }
1413
 
1414
- return false;
1415
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1416
 
1417
  /**
1418
  * @return Mollie_API_Object_Method|null
@@ -1503,6 +1541,16 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
1503
  $lang_url = $this->getSiteUrlWithLanguage();
1504
  $webhook_url = str_replace($site_url, $lang_url, $webhook_url);
1505
 
 
 
 
 
 
 
 
 
 
 
1506
  return apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_webhook_url', $webhook_url, $order);
1507
  }
1508
 
@@ -1652,6 +1700,30 @@ abstract class Mollie_WC_Gateway_Abstract extends WC_Payment_Gateway
1652
 
1653
  }
1654
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1655
 
1656
  /**
1657
  * @return mixed
940
  // Overwrite gateway-wide
941
  $new_order_status = apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_order_status_cancelled_' . $this->id, $new_order_status);
942
 
943
+ // Update order status, but only if there is no payment started by another gateway
944
+ if ( ! $this->isOrderPaymentStartedByOtherGateway( $order ) ) {
945
+ $this->updateOrderStatus( $order, $new_order_status );
946
+ } else {
947
+ $order_payment_method_title = get_post_meta( $order_id, '_payment_method_title', $single = true );
948
+
949
+ // Add message to log
950
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order->get_id() . ' webhook called, but payment also started via ' . $order_payment_method_title . ', so order status not updated.', true );
951
+
952
+ // Add order note
953
+ $order->add_order_note( sprintf(
954
+ /* translators: Placeholder 1: payment method title, placeholder 2: payment ID */
955
+ __( 'Mollie webhook called, but payment also started via %s, so the order status is not updated.', 'mollie-payments-for-woocommerce' ),
956
+ $order_payment_method_title
957
+ ) );
958
+ }
959
 
960
  $paymentMethodTitle = $this->getPaymentMethodTitle($payment);
961
 
1014
  // Overwrite gateway-wide
1015
  $new_order_status = apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_order_status_expired_' . $this->id, $new_order_status);
1016
 
1017
+ // Update order status, but only if there is no payment started by another gateway
1018
+ if ( ! $this->isOrderPaymentStartedByOtherGateway( $order ) ) {
1019
+ $this->updateOrderStatus( $order, $new_order_status );
1020
+ } else {
1021
+ $order_payment_method_title = get_post_meta( $order_id, '_payment_method_title', $single = true );
1022
+
1023
+ // Add message to log
1024
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order->get_id() . ' webhook called, but payment also started via ' . $order_payment_method_title . ', so order status not updated.', true );
1025
+
1026
+ // Add order note
1027
+ $order->add_order_note( sprintf(
1028
+ /* translators: Placeholder 1: payment method title, placeholder 2: payment ID */
1029
+ __( 'Mollie webhook called, but payment also started via %s, so the order status is not updated.', 'mollie-payments-for-woocommerce' ),
1030
+ $order_payment_method_title
1031
+ ) );
1032
+ }
1033
 
1034
  $order->add_order_note(sprintf(
1035
  /* translators: Placeholder 1: payment method title, placeholder 2: payment ID */
1071
  } else {
1072
  Mollie_WC_Plugin::addNotice( __( 'You have cancelled your payment. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' ) );
1073
 
1074
+ // Return to order payment page
1075
  if ( method_exists( $order, 'get_checkout_payment_url' ) ) {
 
 
 
1076
  return $order->get_checkout_payment_url( false );
1077
  }
1078
  }
1079
 
1080
+ // Return to order payment page
1081
+ if ( method_exists( $order, 'get_checkout_payment_url' ) ) {
 
 
 
 
1082
  return $order->get_checkout_payment_url( false );
1083
  }
1084
+
1085
  }
1086
 
1087
  if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1088
+ $payment = Mollie_WC_Plugin::getDataHelper()->getActiveMolliePayment($order->id, false );
1089
  } else {
1090
+ $payment = Mollie_WC_Plugin::getDataHelper()->getActiveMolliePayment($order->get_id(), false );
1091
  }
1092
 
1093
+ if ( ! $payment->isOpen() && ! $payment->isPending() && ! $payment->isPaid() ) {
1094
  Mollie_WC_Plugin::addNotice( __( 'Your payment was not successful. Please complete your order with a different payment method.', 'mollie-payments-for-woocommerce' ) );
1095
+ // Return to order payment page
1096
+ if ( method_exists( $order, 'get_checkout_payment_url' ) ) {
1097
+ return $order->get_checkout_payment_url( false );
1098
+ }
1099
  }
1100
 
1101
  }
1410
  }
1411
 
1412
  /**
1413
+ * @param WC_Order $order
1414
+ *
1415
+ * @return bool
1416
+ */
1417
+ protected function orderNeedsPayment( WC_Order $order ) {
 
 
 
 
1418
 
1419
+ if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1420
+ $order_id = $order->id;
1421
+ } else {
1422
+ $order_id = $order->get_id();
1423
+ }
1424
 
1425
+ // Check whether the order is processed and paid via another gateway
1426
+ if ( $this->isOrderPaidByOtherGateway( $order ) ) {
1427
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order_id . ' orderNeedsPayment, no, processed by other (non-Mollie) gateway.', true );
 
1428
 
1429
+ return false;
1430
+ }
 
 
 
1431
 
1432
+ // Check whether the order is processed and paid via Mollie
1433
+ if ( ! $this->isOrderPaidAndProcessed( $order ) ) {
1434
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order_id . ' orderNeedsPayment check, yes, not processed by Mollie gateway.', true );
1435
+
1436
+ return true;
1437
+ }
1438
+
1439
+ if ( $order->needs_payment() ) {
1440
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, WooCommerce thinks order needs payment.', true );
1441
+
1442
+ return true;
1443
+ }
1444
+
1445
+ // Has initial order status 'on-hold'
1446
+ if ( $this->getInitialOrderStatus() === self::STATUS_ON_HOLD && Mollie_WC_Plugin::getDataHelper()->hasOrderStatus( $order, self::STATUS_ON_HOLD ) ) {
1447
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, has status On-Hold. ', true );
1448
+
1449
+ return true;
1450
+ }
1451
+
1452
+ return false;
1453
+ }
1454
 
1455
  /**
1456
  * @return Mollie_API_Object_Method|null
1541
  $lang_url = $this->getSiteUrlWithLanguage();
1542
  $webhook_url = str_replace($site_url, $lang_url, $webhook_url);
1543
 
1544
+ // Some (multilanguage) plugins will add a extra slash to the url (/nl//) causing the URL to redirect and lose it's data.
1545
+ // Status updates via webhook will therefor not be processed. The below regex will find and remove those double slashes.
1546
+ $webhook_url = preg_replace('/([^:])(\/{2,})/', '$1/', $webhook_url);
1547
+
1548
+ if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1549
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order->id . ' webhookUrl: ' . $webhook_url, true );
1550
+ } else {
1551
+ Mollie_WC_Plugin::debug( $this->id . ': Order ' . $order->get_id() . ' webhookUrl: ' . $webhook_url, true );
1552
+ }
1553
+
1554
  return apply_filters(Mollie_WC_Plugin::PLUGIN_ID . '_webhook_url', $webhook_url, $order);
1555
  }
1556
 
1700
 
1701
  }
1702
 
1703
+ /**
1704
+ * @return bool
1705
+ */
1706
+ protected function isOrderPaymentStartedByOtherGateway( WC_Order $order ) {
1707
+
1708
+ if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
1709
+ $order_id = $order->id;
1710
+ } else {
1711
+ $order_id = $order->get_id();
1712
+ }
1713
+
1714
+ // Get the current payment method id for the order
1715
+ $payment_method_id = get_post_meta( $order_id, '_payment_method', $single = true );
1716
+
1717
+ // If the current payment method id for the order is not Mollie, return true
1718
+ if ( ( strpos( $payment_method_id, 'mollie' ) === false ) ) {
1719
+
1720
+ return true;
1721
+ }
1722
+
1723
+ return false;
1724
+
1725
+ }
1726
+
1727
 
1728
  /**
1729
  * @return mixed
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 = '3.0.3';
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 = '3.0.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: 3.0.3
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: 3.0.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, woocommerce, payment gateway, e-commerce, credit card, ideal, sofort, bancontact, bitcoin, direct debit, subscriptions
4
  Requires at least: 3.8
5
  Tested up to: 4.9
6
- Stable tag: 3.0.3
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -163,6 +163,13 @@ Automatic updates should work like a charm; as always though, ensure you backup
163
 
164
  == Changelog ==
165
 
 
 
 
 
 
 
 
166
  = 3.0.3 - 14/05/2018 =
167
 
168
  * Note - If you use Polylang or another multilanguage plugin, read this [FAQ item](https://github.com/mollie/WooCommerce/wiki/Common-issues#issues-with-polylang-or-other-multilanguage-plugins)!
3
  Tags: mollie, payments, woocommerce, payment gateway, e-commerce, credit card, ideal, sofort, bancontact, bitcoin, direct debit, subscriptions
4
  Requires at least: 3.8
5
  Tested up to: 4.9
6
+ Stable tag: 3.0.4
7
  Requires PHP: 5.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
163
 
164
  == Changelog ==
165
 
166
+ = 3.0.4 - 24/05/2018 =
167
+
168
+ * Fix - Limit order status update for cancelled and expired payments if another non-Mollie payment gateway also started payment processing (and is active) for that order, prevents expired and cancelled Mollie payments from cancelling the order
169
+ * Fix - Webhook URL's with double slashes, caused by some multilanguage plugins (Polylang etc)
170
+ * Fix - Add extra condition to make sure customers with paid payments are redirected to correct URL after payment
171
+ * Fix - Incorrect return page after payment for some orders, fix was to get payment without cache at least once on return URL (in case Webhook Url is still processing)
172
+
173
  = 3.0.3 - 14/05/2018 =
174
 
175
  * Note - If you use Polylang or another multilanguage plugin, read this [FAQ item](https://github.com/mollie/WooCommerce/wiki/Common-issues#issues-with-polylang-or-other-multilanguage-plugins)!