WooCommerce PayPal Express Checkout Payment Gateway - Version 1.2.1

Version Description

  • Fix - Avoid plugin links notice when WooCommerce is not active - props rellect
  • Fix - Do not show this gateway when the cart amount is zero
  • Fix - Fix 10413 error that prevents checking out with a coupon
  • Fix - Filter default address fields to ensure they are not required
Download this release

Release Info

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

Code changes from version 1.2.0 to 1.2.1

includes/class-wc-gateway-ppec-checkout-handler.php CHANGED
@@ -37,6 +37,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
37
  add_action( 'init', array( $this, 'init' ) );
38
  add_filter( 'the_title', array( $this, 'endpoint_page_titles' ) );
39
  add_action( 'woocommerce_checkout_init', array( $this, 'checkout_init' ) );
 
40
  add_filter( 'woocommerce_billing_fields', array( $this, 'filter_billing_fields' ) );
41
  add_action( 'woocommerce_checkout_process', array( $this, 'copy_checkout_details_to_post' ) );
42
 
@@ -102,12 +103,40 @@ class WC_Gateway_PPEC_Checkout_Handler {
102
  add_action( 'woocommerce_checkout_shipping', array( $this, 'paypal_shipping_details' ) );
103
  }
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  /**
106
  * Since PayPal doesn't always give us the phone number for the buyer, we need to make
107
- * that field not required. And if the cart doesn't need shipping at all, don't require
108
- * the address fields either (this is unique to PPEC)
 
 
 
109
  *
110
  * @since 1.2.0
 
111
  * @param $billing_fields array
112
  *
113
  * @return array
@@ -117,15 +146,6 @@ class WC_Gateway_PPEC_Checkout_Handler {
117
  $billing_fields['billing_phone']['required'] = false;
118
  };
119
 
120
- if ( ! WC()->cart->needs_shipping() ) {
121
- $not_required_fields = array( 'billing_address_1', 'billing_city', 'billing_state', 'billing_postcode' );
122
- foreach ( $not_required_fields as $not_required_field ) {
123
- if ( array_key_exists( $not_required_field, $billing_fields ) ) {
124
- $billing_fields[ $not_required_field ]['required'] = false;
125
- }
126
- }
127
- }
128
-
129
  return $billing_fields;
130
  }
131
 
@@ -402,9 +422,11 @@ class WC_Gateway_PPEC_Checkout_Handler {
402
  }
403
 
404
  /**
405
- * Maybe disable other gateways.
406
  *
407
  * @since 1.0.0
 
 
408
  * @param array $gateways Available gateways
409
  *
410
  * @return array Available gateways
@@ -423,6 +445,13 @@ class WC_Gateway_PPEC_Checkout_Handler {
423
  unset( $gateways['ppec_paypal'] );
424
  }
425
 
 
 
 
 
 
 
 
426
  return $gateways;
427
  }
428
 
37
  add_action( 'init', array( $this, 'init' ) );
38
  add_filter( 'the_title', array( $this, 'endpoint_page_titles' ) );
39
  add_action( 'woocommerce_checkout_init', array( $this, 'checkout_init' ) );
40
+ add_filter( 'woocommerce_default_address_fields', array( $this, 'filter_default_address_fields' ) );
41
  add_filter( 'woocommerce_billing_fields', array( $this, 'filter_billing_fields' ) );
42
  add_action( 'woocommerce_checkout_process', array( $this, 'copy_checkout_details_to_post' ) );
43
 
103
  add_action( 'woocommerce_checkout_shipping', array( $this, 'paypal_shipping_details' ) );
104
  }
105
 
106
+ /**
107
+ * If the cart doesn't need shipping at all, don't require the address fields
108
+ * (this is unique to PPEC). This is one of two places we need to filter fields.
109
+ * See also filter_billing_fields below.
110
+ *
111
+ * @since 1.2.1
112
+ * @param $fields array
113
+ *
114
+ * @return array
115
+ */
116
+ public function filter_default_address_fields( $fields ) {
117
+ if ( method_exists( WC()->cart, 'needs_shipping' ) && ! WC()->cart->needs_shipping() ) {
118
+ $not_required_fields = array( 'address_1', 'city', 'state', 'postcode', 'country' );
119
+ foreach ( $not_required_fields as $not_required_field ) {
120
+ if ( array_key_exists( $not_required_field, $fields ) ) {
121
+ $fields[ $not_required_field ]['required'] = false;
122
+ }
123
+ }
124
+ }
125
+
126
+ return $fields;
127
+
128
+ }
129
+
130
  /**
131
  * Since PayPal doesn't always give us the phone number for the buyer, we need to make
132
+ * that field not required. Note that core WooCommerce adds the phone field after calling
133
+ * get_default_address_fields, so the woocommerce_default_address_fields cannot
134
+ * be used to make the phone field not required.
135
+ *
136
+ * This is one of two places we need to filter fields. See also filter_default_address_fields above.
137
  *
138
  * @since 1.2.0
139
+ * @version 1.2.1
140
  * @param $billing_fields array
141
  *
142
  * @return array
146
  $billing_fields['billing_phone']['required'] = false;
147
  };
148
 
 
 
 
 
 
 
 
 
 
149
  return $billing_fields;
150
  }
151
 
422
  }
423
 
424
  /**
425
+ * Maybe disable this or other gateways.
426
  *
427
  * @since 1.0.0
428
+ * @version 1.2.1
429
+ *
430
  * @param array $gateways Available gateways
431
  *
432
  * @return array Available gateways
445
  unset( $gateways['ppec_paypal'] );
446
  }
447
 
448
+ // If the cart total is zero (e.g. because of a coupon), don't allow this gateway
449
+ if ( is_cart() || is_checkout() ) {
450
+ if ( isset( $gateways['ppec_paypal'] ) && ( 0 >= WC()->cart->total ) ) {
451
+ unset( $gateways['ppec_paypal'] );
452
+ }
453
+ }
454
+
455
  return $gateways;
456
  }
457
 
includes/class-wc-gateway-ppec-client.php CHANGED
@@ -440,6 +440,7 @@ class WC_Gateway_PPEC_Client {
440
  * This is the details when buyer is checking out from cart page.
441
  *
442
  * @since 1.2.0
 
443
  *
444
  * @return array Order details
445
  */
@@ -494,7 +495,7 @@ class WC_Gateway_PPEC_Client {
494
  $details['order_total'] -= $discounts;
495
  } else {
496
  if ( $discounts > 0 ) {
497
- $details['items'][] = $this->_get_extra_offset_line_item( $discounts );
498
  }
499
 
500
  $details['ship_discount_amount'] = 0;
440
  * This is the details when buyer is checking out from cart page.
441
  *
442
  * @since 1.2.0
443
+ * @version 1.2.1
444
  *
445
  * @return array Order details
446
  */
495
  $details['order_total'] -= $discounts;
496
  } else {
497
  if ( $discounts > 0 ) {
498
+ $details['items'][] = $this->_get_extra_offset_line_item( - abs( $discounts ) );
499
  }
500
 
501
  $details['ship_discount_amount'] = 0;
includes/class-wc-gateway-ppec-plugin.php CHANGED
@@ -361,12 +361,15 @@ class WC_Gateway_PPEC_Plugin {
361
  * @return array Plugin action links
362
  */
363
  public function plugin_action_links( $links ) {
364
- $setting_url = $this->get_admin_setting_link();
 
 
 
 
 
 
 
365
 
366
- $plugin_links = array(
367
- '<a href="' . esc_url( $setting_url ) . '">' . esc_html__( 'Settings', 'woocommerce-gateway-paypal-express-checkout' ) . '</a>',
368
- '<a href="https://docs.woocommerce.com/document/paypal-express-checkout/">' . esc_html__( 'Docs', 'woocommerce-gateway-paypal-express-checkout' ) . '</a>',
369
- );
370
  return array_merge( $plugin_links, $links );
371
  }
372
  }
361
  * @return array Plugin action links
362
  */
363
  public function plugin_action_links( $links ) {
364
+ $plugin_links = array();
365
+
366
+ if ( $this->_bootstrapped ) {
367
+ $setting_url = $this->get_admin_setting_link();
368
+ $plugin_links[] = '<a href="' . esc_url( $setting_url ) . '">' . esc_html__( 'Settings', 'woocommerce-gateway-paypal-express-checkout' ) . '</a>';
369
+ }
370
+
371
+ $plugin_links[] = '<a href="https://docs.woocommerce.com/document/paypal-express-checkout/">' . esc_html__( 'Docs', 'woocommerce-gateway-paypal-express-checkout' ) . '</a>';
372
 
 
 
 
 
373
  return array_merge( $plugin_links, $links );
374
  }
375
  }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WooCommerce PayPal Express Checkout Payment Gateway ===
2
- Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey, fullysupportedphil, dsmithweb, corsonr, bor0
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.4
6
- Stable tag: 1.2.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -85,6 +85,12 @@ https://gist.github.com/mikejolley/ad2ecc286c9ad6cefbb7065ba6dfef48
85
 
86
  == Changelog ==
87
 
 
 
 
 
 
 
88
  = 1.2.0 =
89
  * Fix - Prevent conflict with other gateways.
90
  * Fix - Compatibility with WooCommerce 3.0, including ensuring the customer address is saved correctly.
1
  === WooCommerce PayPal Express Checkout Payment Gateway ===
2
+ Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey, fullysupportedphil, dsmithweb, corsonr, bor0, zandyring
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.4
6
+ Stable tag: 1.2.1
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
85
 
86
  == Changelog ==
87
 
88
+ = 1.2.1 =
89
+ * Fix - Avoid plugin links notice when WooCommerce is not active - props rellect
90
+ * Fix - Do not show this gateway when the cart amount is zero
91
+ * Fix - Fix 10413 error that prevents checking out with a coupon
92
+ * Fix - Filter default address fields to ensure they are not required
93
+
94
  = 1.2.0 =
95
  * Fix - Prevent conflict with other gateways.
96
  * Fix - Compatibility with WooCommerce 3.0, including ensuring the customer address is saved correctly.
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.2.0
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2017 WooCommerce / PayPal.
@@ -25,6 +25,8 @@ if ( ! defined( 'ABSPATH' ) ) {
25
  exit; // Exit if accessed directly
26
  }
27
 
 
 
28
  /**
29
  * Return instance of WC_Gateway_PPEC_Plugin.
30
  *
@@ -36,7 +38,7 @@ function wc_gateway_ppec() {
36
  if ( ! isset( $plugin ) ) {
37
  require_once( 'includes/class-wc-gateway-ppec-plugin.php' );
38
 
39
- $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, '1.2.0' );
40
  }
41
 
42
  return $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.2.1
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2017 WooCommerce / PayPal.
25
  exit; // Exit if accessed directly
26
  }
27
 
28
+ define( 'WC_GATEWAY_PPEC_VERSION', '1.2.1' );
29
+
30
  /**
31
  * Return instance of WC_Gateway_PPEC_Plugin.
32
  *
38
  if ( ! isset( $plugin ) ) {
39
  require_once( 'includes/class-wc-gateway-ppec-plugin.php' );
40
 
41
+ $plugin = new WC_Gateway_PPEC_Plugin( __FILE__, WC_GATEWAY_PPEC_VERSION );
42
  }
43
 
44
  return $plugin;