WooCommerce PayPal Express Checkout Payment Gateway - Version 1.4.7

Version Description

  • Fix - Issue with missing paypal session information.
  • Fix - Dependency error when using LibreSSL.
  • Fix - Additional compatibility with shipping plugins
  • Fix - Issue where deprecated WC_Cart::get_cart_url is being used.
  • Tweak - Makes admin notification dismissible.
Download this release

Release Info

Developer bor0
Plugin Icon 128x128 WooCommerce PayPal Express Checkout Payment Gateway
Version 1.4.7
Comparing to
See all releases

Code changes from version 1.4.6 to 1.4.7

includes/class-wc-gateway-ppec-checkout-handler.php CHANGED
@@ -49,6 +49,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
49
  add_action( 'woocommerce_review_order_after_submit', array( $this, 'maybe_render_cancel_link' ) );
50
 
51
  add_action( 'woocommerce_cart_shipping_packages', array( $this, 'maybe_add_shipping_information' ) );
 
52
  }
53
 
54
  /**
@@ -401,6 +402,8 @@ class WC_Gateway_PPEC_Checkout_Handler {
401
  // Store values in session.
402
  $session->checkout_completed = true;
403
  $session->payer_id = $payer_id;
 
 
404
  WC()->session->set( 'paypal', $session );
405
 
406
  try {
@@ -933,4 +936,58 @@ class WC_Gateway_PPEC_Checkout_Handler {
933
 
934
  return $needs_billing_agreement;
935
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
936
  }
49
  add_action( 'woocommerce_review_order_after_submit', array( $this, 'maybe_render_cancel_link' ) );
50
 
51
  add_action( 'woocommerce_cart_shipping_packages', array( $this, 'maybe_add_shipping_information' ) );
52
+ add_filter( 'wc_checkout_params', array( $this, 'filter_wc_checkout_params' ), 10, 1 );
53
  }
54
 
55
  /**
402
  // Store values in session.
403
  $session->checkout_completed = true;
404
  $session->payer_id = $payer_id;
405
+ $session->token = $token;
406
+
407
  WC()->session->set( 'paypal', $session );
408
 
409
  try {
936
 
937
  return $needs_billing_agreement;
938
  }
939
+
940
+ /**
941
+ * Filter checkout AJAX endpoint so it carries the query string after buyer is
942
+ * redirected from PayPal.
943
+ *
944
+ * To explain the reason why we need to store this in the session, we
945
+ * first need to take a look at how things flow:
946
+ *
947
+ * For guest checkout with Geolocation enabled:
948
+ *
949
+ * 1. On the checkout screen, WooCommerce gets shipping information and
950
+ * this hook is called. We have `$_GET` context, so we will replace
951
+ * `$packages[0]['destination']` using the PP account (Country 1).
952
+ *
953
+ * 2. Package hash gets stored by `WC_Shipping::calculate_shipping_for_package`
954
+ * for destination "Country 1".
955
+ *
956
+ * 3. The AJAX `update_order_review` will be called from core. At this
957
+ * point, we do not have `$_GET` context, so this method will return
958
+ * the original packages. Note that the original packages will now
959
+ * contain shipping information based on Geolocation (Country 2, may be
960
+ * distinct from Country 1).
961
+ *
962
+ * 4. At this point, the package hash will be different, and thus the
963
+ * call to `get_rates_for_package` within `WC_Shipping::calculate_shipping_for_package`
964
+ * will re-trigger shipping extensions, such as FedEx, USPS, etc.
965
+ *
966
+ * To avoid this behaviour, make sure we store the packages and their
967
+ * correct destination based on PP account info for re-usage in any
968
+ * AJAX calls where we don't have PP token context.
969
+ *
970
+ * Related core commits: 75cc4f9, 2ff1ee1
971
+ *
972
+ * @since 1.4.7
973
+ *
974
+ * @param array $params
975
+ *
976
+ * @return string URL.
977
+ */
978
+ public function filter_wc_checkout_params( $params ) {
979
+ $fields = array( 'woo-paypal-return', 'token', 'PayerID' );
980
+
981
+ $params['wc_ajax_url'] = remove_query_arg( 'wc-ajax', $params['wc_ajax_url'] );
982
+
983
+ foreach ( $fields as $field ) {
984
+ if ( ! empty( $_GET[ $field ] ) ) {
985
+ $params['wc_ajax_url'] = add_query_arg( $field, $_GET[ $field ], $params['wc_ajax_url'] );
986
+ }
987
+ }
988
+
989
+ $params['wc_ajax_url'] = add_query_arg( 'wc-ajax', '%%endpoint%%', $params['wc_ajax_url'] );
990
+
991
+ return $params;
992
+ }
993
  }
includes/class-wc-gateway-ppec-plugin.php CHANGED
@@ -147,6 +147,7 @@ class WC_Gateway_PPEC_Plugin {
147
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
148
 
149
  add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'plugin_action_links' ) );
 
150
  }
151
 
152
  public function bootstrap() {
@@ -164,7 +165,6 @@ class WC_Gateway_PPEC_Plugin {
164
  delete_option( 'wc_gateway_ppce_prompt_to_connect' );
165
  } catch ( Exception $e ) {
166
  if ( in_array( $e->getCode(), array( self::ALREADY_BOOTSTRAPED, self::DEPENDENCIES_UNSATISFIED ) ) ) {
167
-
168
  update_option( 'wc_gateway_ppce_bootstrap_warning_message', $e->getMessage() );
169
  }
170
 
@@ -178,28 +178,73 @@ class WC_Gateway_PPEC_Plugin {
178
 
179
  public function show_bootstrap_warning() {
180
  $dependencies_message = get_option( 'wc_gateway_ppce_bootstrap_warning_message', '' );
181
- if ( ! empty( $dependencies_message ) ) {
182
  ?>
183
- <div class="error fade">
184
  <p>
185
  <strong><?php echo esc_html( $dependencies_message ); ?></strong>
186
  </p>
187
  </div>
 
 
 
 
 
 
 
 
 
 
 
188
  <?php
189
  }
190
 
191
  $prompt_connect = get_option( 'wc_gateway_ppce_prompt_to_connect', '' );
192
- if ( ! empty( $prompt_connect ) ) {
193
  ?>
194
- <div class="notice notice-warning">
195
  <p>
196
  <strong><?php echo wp_kses( $prompt_connect, array( 'a' => array( 'href' => array() ) ) ); ?></strong>
197
  </p>
198
  </div>
 
 
 
 
 
 
 
 
 
 
 
199
  <?php
200
  }
201
  }
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  /**
204
  * Check dependencies.
205
  *
@@ -223,7 +268,7 @@ class WC_Gateway_PPEC_Plugin {
223
  throw new Exception( $openssl_warning, self::DEPENDENCIES_UNSATISFIED );
224
  }
225
 
226
- preg_match( '/^OpenSSL ([\d.]+)/', OPENSSL_VERSION_TEXT, $matches );
227
  if ( empty( $matches[1] ) ) {
228
  throw new Exception( $openssl_warning, self::DEPENDENCIES_UNSATISFIED );
229
  }
147
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
148
 
149
  add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'plugin_action_links' ) );
150
+ add_action( 'wp_ajax_ppec_dismiss_notice_message', array( $this, 'ajax_dismiss_notice' ) );
151
  }
152
 
153
  public function bootstrap() {
165
  delete_option( 'wc_gateway_ppce_prompt_to_connect' );
166
  } catch ( Exception $e ) {
167
  if ( in_array( $e->getCode(), array( self::ALREADY_BOOTSTRAPED, self::DEPENDENCIES_UNSATISFIED ) ) ) {
 
168
  update_option( 'wc_gateway_ppce_bootstrap_warning_message', $e->getMessage() );
169
  }
170
 
178
 
179
  public function show_bootstrap_warning() {
180
  $dependencies_message = get_option( 'wc_gateway_ppce_bootstrap_warning_message', '' );
181
+ if ( ! empty( $dependencies_message ) && 'yes' !== get_option( 'wc_gateway_ppec_bootstrap_warning_message_dismissed', 'no' ) ) {
182
  ?>
183
+ <div class="notice notice-warning is-dismissible ppec-dismiss-bootstrap-warning-message">
184
  <p>
185
  <strong><?php echo esc_html( $dependencies_message ); ?></strong>
186
  </p>
187
  </div>
188
+ <script>
189
+ ( function( $ ) {
190
+ $( '.ppec-dismiss-bootstrap-warning-message' ).on( 'click', '.notice-dismiss', function() {
191
+ jQuery.post( "<?php echo admin_url( 'admin-ajax.php' ); ?>", {
192
+ action: "ppec_dismiss_notice_message",
193
+ dismiss_action: "ppec_dismiss_bootstrap_warning_message",
194
+ nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
195
+ } );
196
+ } );
197
+ } )( jQuery );
198
+ </script>
199
  <?php
200
  }
201
 
202
  $prompt_connect = get_option( 'wc_gateway_ppce_prompt_to_connect', '' );
203
+ if ( ! empty( $prompt_connect ) && 'yes' !== get_option( 'wc_gateway_ppec_prompt_to_connect_message_dismissed', 'no' ) ) {
204
  ?>
205
+ <div class="notice notice-warning is-dismissible ppec-dismiss-prompt-to-connect-message">
206
  <p>
207
  <strong><?php echo wp_kses( $prompt_connect, array( 'a' => array( 'href' => array() ) ) ); ?></strong>
208
  </p>
209
  </div>
210
+ <script>
211
+ ( function( $ ) {
212
+ $( '.ppec-dismiss-prompt-to-connect-message' ).on( 'click', '.notice-dismiss', function() {
213
+ jQuery.post( "<?php echo admin_url( 'admin-ajax.php' ); ?>", {
214
+ action: "ppec_dismiss_notice_message",
215
+ dismiss_action: "ppec_dismiss_prompt_to_connect",
216
+ nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
217
+ } );
218
+ } );
219
+ } )( jQuery );
220
+ </script>
221
  <?php
222
  }
223
  }
224
 
225
+ /**
226
+ * AJAX handler for dismiss notice action.
227
+ *
228
+ * @since 1.4.7
229
+ * @version 1.4.7
230
+ */
231
+ public function ajax_dismiss_notice() {
232
+ if ( empty( $_POST['dismiss_action'] ) ) {
233
+ return;
234
+ }
235
+
236
+ check_ajax_referer( 'ppec_dismiss_notice', 'nonce' );
237
+ switch ( $_POST['dismiss_action'] ) {
238
+ case 'ppec_dismiss_bootstrap_warning_message':
239
+ update_option( 'wc_gateway_ppec_bootstrap_warning_message_dismissed', 'yes' );
240
+ break;
241
+ case 'ppec_dismiss_prompt_to_connect':
242
+ update_option( 'wc_gateway_ppec_prompt_to_connect_message_dismissed', 'yes' );
243
+ break;
244
+ }
245
+ wp_die();
246
+ }
247
+
248
  /**
249
  * Check dependencies.
250
  *
268
  throw new Exception( $openssl_warning, self::DEPENDENCIES_UNSATISFIED );
269
  }
270
 
271
+ preg_match( '/^(?:Libre|Open)SSL ([\d.]+)/', OPENSSL_VERSION_TEXT, $matches );
272
  if ( empty( $matches[1] ) ) {
273
  throw new Exception( $openssl_warning, self::DEPENDENCIES_UNSATISFIED );
274
  }
includes/functions.php CHANGED
@@ -10,7 +10,7 @@ function woo_pp_start_checkout() {
10
  } catch( PayPal_API_Exception $e ) {
11
  wc_add_notice( $e->getMessage(), 'error' );
12
 
13
- $redirect_url = WC()->cart->get_cart_url();
14
  $settings = wc_gateway_ppec()->settings;
15
  $client = wc_gateway_ppec()->client;
16
 
10
  } catch( PayPal_API_Exception $e ) {
11
  wc_add_notice( $e->getMessage(), 'error' );
12
 
13
+ $redirect_url = wc_get_cart_url();
14
  $settings = wc_gateway_ppec()->settings;
15
  $client = wc_gateway_ppec()->client;
16
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy,
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
4
  Requires at least: 4.4
5
  Tested up to: 4.9.0
6
- Stable tag: 1.4.6
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -85,6 +85,13 @@ https://gist.github.com/mikejolley/ad2ecc286c9ad6cefbb7065ba6dfef48
85
 
86
  == Changelog ==
87
 
 
 
 
 
 
 
 
88
  = 1.4.6 =
89
  * Fix - Coupon related PayPal error 10413.
90
 
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
4
  Requires at least: 4.4
5
  Tested up to: 4.9.0
6
+ Stable tag: 1.4.7
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
85
 
86
  == Changelog ==
87
 
88
+ = 1.4.7 =
89
+ * Fix - Issue with missing paypal session information.
90
+ * Fix - Dependency error when using LibreSSL.
91
+ * Fix - Additional compatibility with shipping plugins
92
+ * Fix - Issue where deprecated `WC_Cart::get_cart_url` is being used.
93
+ * Tweak - Makes admin notification dismissible.
94
+
95
  = 1.4.6 =
96
  * Fix - Coupon related PayPal error 10413.
97
 
woocommerce-gateway-paypal-express-checkout.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce PayPal Express Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Express Checkout (https://www.paypal.com/us/webapps/mpp/express-checkout).
6
- * Version: 1.4.6
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2017 WooCommerce / PayPal.
@@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
27
  exit; // Exit if accessed directly
28
  }
29
 
30
- define( 'WC_GATEWAY_PPEC_VERSION', '1.4.6' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.
3
  * Plugin Name: WooCommerce PayPal Express Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Express Checkout (https://www.paypal.com/us/webapps/mpp/express-checkout).
6
+ * Version: 1.4.7
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2017 WooCommerce / PayPal.
27
  exit; // Exit if accessed directly
28
  }
29
 
30
+ define( 'WC_GATEWAY_PPEC_VERSION', '1.4.7' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.