WooCommerce PayPal Express Checkout Payment Gateway - Version 1.6.16

Version Description

  • 2019-07-18 =
  • Fix - Don't require address for renewal of virtual subscriptions
  • Fix - Avoid broken confirmation screen edge case after 10486 redirect
Download this release

Release Info

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

Code changes from version 1.6.15 to 1.6.16

assets/js/wc-gateway-ppec-order-review.js CHANGED
@@ -2,6 +2,11 @@
2
  'use strict';
3
 
4
  $( 'form.checkout' ).on( 'click', 'input[name="payment_method"]', function() {
 
 
 
 
 
5
  var isPPEC = $( this ).is( '#payment_method_ppec_paypal' );
6
  $( '#place_order' ).toggle( ! isPPEC );
7
  $( '#woo_pp_ec_button_checkout' ).toggle( isPPEC );
2
  'use strict';
3
 
4
  $( 'form.checkout' ).on( 'click', 'input[name="payment_method"]', function() {
5
+ // Avoid toggling submit button if on confirmation screen
6
+ if ( $( '#payment' ).find( '.wc-gateway-ppec-cancel' ).length ) {
7
+ return;
8
+ }
9
+
10
  var isPPEC = $( this ).is( '#payment_method_ppec_paypal' );
11
  $( '#place_order' ).toggle( ! isPPEC );
12
  $( '#woo_pp_ec_button_checkout' ).toggle( isPPEC );
changelog.txt CHANGED
@@ -1,5 +1,9 @@
1
  *** Changelog ***
2
 
 
 
 
 
3
  = 1.6.15 - 2019-06-19 =
4
  * Fix - Prevent PHP errors when no billing details are present in PP response
5
  * Fix - Require billing address for virtual products when enabled
1
  *** Changelog ***
2
 
3
+ = 1.6.16 - 2019-07-18 =
4
+ * Fix - Don't require address for renewal of virtual subscriptions
5
+ * Fix - Avoid broken confirmation screen edge case after 10486 redirect
6
+
7
  = 1.6.15 - 2019-06-19 =
8
  * Fix - Prevent PHP errors when no billing details are present in PP response
9
  * Fix - Require billing address for virtual products when enabled
includes/class-wc-gateway-ppec-address.php CHANGED
@@ -700,4 +700,73 @@ class PayPal_Address {
700
 
701
  return $found_any;
702
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
703
  }
700
 
701
  return $found_any;
702
  }
703
+
704
+ /*
705
+ * Checks to see if the PayPal_Address object has all the
706
+ * required parameters when using a shipping address.
707
+ *
708
+ * The required parameters for a DoReferenceTransaction call are listed here:
709
+ * https://developer.paypal.com/docs/classic/api/merchant/DoReferenceTransaction-API-Operation-NVP/#ship-to-address-fields
710
+ *
711
+ * Other API operations have the same shipping parameter requirements.
712
+ * Here's a non-exhaustive list:
713
+ *
714
+ * DoExpressCheckoutPayment
715
+ * https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment-API-Operation-NVP/
716
+ *
717
+ * SetExpressCheckout
718
+ * https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout-API-Operation-NVP/
719
+ *
720
+ * GetExpressCheckoutDetails
721
+ * https://developer.paypal.com/docs/classic/api/merchant/GetExpressCheckoutDetails-API-Operation-NVP/
722
+ */
723
+ public function has_all_required_shipping_params() {
724
+ $has_name = ! empty( $this->getName() );
725
+ $has_street1 = ! empty( $this->getStreet1() );
726
+ $has_city = ! empty( $this->getCity() );
727
+ $has_country = ! empty( $this->getCountry() );
728
+ $has_zip = ! empty( $this->getZip() );
729
+ $has_state = ! empty( $this->getState() );
730
+
731
+ // If the country is the US, a zipcode is required
732
+ $has_zip_if_required = (
733
+ 'US' === $this->getCountry()
734
+ ? $has_zip
735
+ : true
736
+ );
737
+
738
+ // A state is required is the country is one of
739
+ // Argentina, Brazil, Canada, China, Indonesia,
740
+ // India, Japan, Mexico, Thailand or USA
741
+ $has_state_if_required = (
742
+ in_array(
743
+ $this->getCountry(),
744
+ array(
745
+ 'AR', // Argentina
746
+ 'BR', // Brazil
747
+ 'CA', // Canada
748
+ 'CN', // China
749
+ 'ID', // Indonesia
750
+ 'IN', // India
751
+ 'JP', // Japan
752
+ 'MX', // Mexico
753
+ 'TH', // Thailand
754
+ 'US', // USA
755
+ ),
756
+ true
757
+ )
758
+ ? $has_state
759
+ : true
760
+ );
761
+
762
+ return (
763
+ $has_name
764
+ && $has_street1
765
+ && $has_city
766
+ && $has_country
767
+ && $has_zip_if_required
768
+ && $has_state_if_required
769
+ );
770
+
771
+ }
772
  }
includes/class-wc-gateway-ppec-checkout-handler.php CHANGED
@@ -129,7 +129,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
129
  }
130
 
131
  if ( method_exists( WC()->cart, 'needs_shipping' ) && ! WC()->cart->needs_shipping() && 'no' === wc_gateway_ppec()->settings->require_billing ) {
132
- $not_required_fields = array( 'address_1', 'city', 'postcode', 'country' );
133
  foreach ( $not_required_fields as $not_required_field ) {
134
  if ( array_key_exists( $not_required_field, $fields ) ) {
135
  $fields[ $not_required_field ]['required'] = false;
@@ -210,7 +210,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
210
  // Set flag so that WC copies billing to shipping
211
  $_POST['ship_to_different_address'] = 0;
212
 
213
- $copyable_keys = array( 'address_1', 'address_2', 'city', 'state', 'postcode', 'country' );
214
  foreach ( $copyable_keys as $copyable_key ) {
215
  if ( array_key_exists( $copyable_key, $shipping_details ) ) {
216
  $billing_details[ $copyable_key ] = $shipping_details[ $copyable_key ];
@@ -246,36 +246,31 @@ class WC_Gateway_PPEC_Checkout_Handler {
246
  wc_add_notice( $e->getMessage(), 'error' );
247
  return;
248
  }
249
- // check if the payer details have been set on the PP response before rendering them to prevent PHP errors
250
- if ( empty( $checkout_details->payer_details ) ) {
251
- return;
 
 
252
  }
253
  ?>
254
  <h3><?php _e( 'Billing details', 'woocommerce-gateway-paypal-express-checkout' ); ?></h3>
255
  <ul>
256
- <?php if ( $checkout_details->payer_details->billing_address ) : ?>
257
  <li><strong><?php _e( 'Address:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong></br><?php echo WC()->countries->get_formatted_address( $this->get_mapped_billing_address( $checkout_details ) ); ?></li>
258
- <?php else : ?>
259
  <li><strong><?php _e( 'Name:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->first_name . ' ' . $checkout_details->payer_details->last_name ); ?></li>
260
  <?php endif; ?>
261
 
262
  <?php if ( ! empty( $checkout_details->payer_details->email ) ) : ?>
263
  <li><strong><?php _e( 'Email:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->email ); ?></li>
 
 
264
  <?php endif; ?>
265
 
266
  <?php if ( ! empty( $checkout_details->payer_details->phone_number ) ) : ?>
267
  <li><strong><?php _e( 'Phone:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->phone_number ); ?></li>
268
  <?php elseif ( 'yes' === wc_gateway_ppec()->settings->require_phone_number ) : ?>
269
- <li>
270
- <?php
271
- if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
272
- $fields = WC()->checkout->checkout_fields['billing'];
273
- } else {
274
- $fields = WC()->checkout->get_checkout_fields( 'billing' );
275
- }
276
- woocommerce_form_field( 'billing_phone', $fields['billing_phone'], WC()->checkout->get_value( 'billing_phone' ) );
277
- ?>
278
- </li>
279
  <?php endif; ?>
280
  </ul>
281
  <?php
@@ -1021,8 +1016,13 @@ class WC_Gateway_PPEC_Checkout_Handler {
1021
  $needs_billing_agreement = false;
1022
 
1023
  if ( empty( $args['order_id'] ) ) {
1024
- if ( class_exists( 'WC_Subscriptions_Cart' ) ) {
1025
- $needs_billing_agreement = WC_Subscriptions_Cart::cart_contains_subscription();
 
 
 
 
 
1026
  }
1027
  } else {
1028
  if ( function_exists( 'wcs_order_contains_subscription' ) ) {
129
  }
130
 
131
  if ( method_exists( WC()->cart, 'needs_shipping' ) && ! WC()->cart->needs_shipping() && 'no' === wc_gateway_ppec()->settings->require_billing ) {
132
+ $not_required_fields = array( 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'postcode', 'country' );
133
  foreach ( $not_required_fields as $not_required_field ) {
134
  if ( array_key_exists( $not_required_field, $fields ) ) {
135
  $fields[ $not_required_field ]['required'] = false;
210
  // Set flag so that WC copies billing to shipping
211
  $_POST['ship_to_different_address'] = 0;
212
 
213
+ $copyable_keys = array( 'first_name', 'last_name', 'address_1', 'address_2', 'city', 'state', 'postcode', 'country' );
214
  foreach ( $copyable_keys as $copyable_key ) {
215
  if ( array_key_exists( $copyable_key, $shipping_details ) ) {
216
  $billing_details[ $copyable_key ] = $shipping_details[ $copyable_key ];
246
  wc_add_notice( $e->getMessage(), 'error' );
247
  return;
248
  }
249
+
250
+ if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
251
+ $fields = WC()->checkout->checkout_fields['billing'];
252
+ } else {
253
+ $fields = WC()->checkout->get_checkout_fields( 'billing' );
254
  }
255
  ?>
256
  <h3><?php _e( 'Billing details', 'woocommerce-gateway-paypal-express-checkout' ); ?></h3>
257
  <ul>
258
+ <?php if ( ! empty( $checkout_details->payer_details->billing_address ) ) : ?>
259
  <li><strong><?php _e( 'Address:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong></br><?php echo WC()->countries->get_formatted_address( $this->get_mapped_billing_address( $checkout_details ) ); ?></li>
260
+ <?php elseif ( ! empty( $checkout_details->payer_details->first_name ) && ! empty( $checkout_details->payer_details->last_name ) ) : ?>
261
  <li><strong><?php _e( 'Name:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->first_name . ' ' . $checkout_details->payer_details->last_name ); ?></li>
262
  <?php endif; ?>
263
 
264
  <?php if ( ! empty( $checkout_details->payer_details->email ) ) : ?>
265
  <li><strong><?php _e( 'Email:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->email ); ?></li>
266
+ <?php else : ?>
267
+ <li><?php woocommerce_form_field( 'billing_email', $fields['billing_email'], WC()->checkout->get_value( 'billing_email' ) ); ?></li>
268
  <?php endif; ?>
269
 
270
  <?php if ( ! empty( $checkout_details->payer_details->phone_number ) ) : ?>
271
  <li><strong><?php _e( 'Phone:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->phone_number ); ?></li>
272
  <?php elseif ( 'yes' === wc_gateway_ppec()->settings->require_phone_number ) : ?>
273
+ <li><?php woocommerce_form_field( 'billing_phone', $fields['billing_phone'], WC()->checkout->get_value( 'billing_phone' ) ); ?></li>
 
 
 
 
 
 
 
 
 
274
  <?php endif; ?>
275
  </ul>
276
  <?php
1016
  $needs_billing_agreement = false;
1017
 
1018
  if ( empty( $args['order_id'] ) ) {
1019
+ if ( class_exists( 'WC_Subscriptions_Cart' ) && function_exists( 'wcs_cart_contains_renewal' ) ) {
1020
+ // Needs a billing agreement if the cart contains a subscription
1021
+ // or a renewal of a subscription
1022
+ $needs_billing_agreement = (
1023
+ WC_Subscriptions_Cart::cart_contains_subscription()
1024
+ || wcs_cart_contains_renewal()
1025
+ );
1026
  }
1027
  } else {
1028
  if ( function_exists( 'wcs_order_contains_subscription' ) ) {
includes/class-wc-gateway-ppec-client.php CHANGED
@@ -1012,7 +1012,14 @@ class WC_Gateway_PPEC_Client {
1012
  ) ),
1013
  );
1014
 
1015
- if ( ! empty( $details['shipping_address'] ) ) {
 
 
 
 
 
 
 
1016
  $params = array_merge(
1017
  $params,
1018
  $details['shipping_address']->getAddressParams( 'SHIPTO' )
1012
  ) ),
1013
  );
1014
 
1015
+ // We want to add the shipping parameters only if we have all of the required
1016
+ // parameters for a DoReferenceTransaction call. Otherwise, we don't want to
1017
+ // include any of the shipping parameters, even if we have some of them.
1018
+ // The call will fail if not all of the required paramters are present.
1019
+ if (
1020
+ ! empty( $details['shipping_address'] )
1021
+ && $details['shipping_address']->has_all_required_shipping_params()
1022
+ ) {
1023
  $params = array_merge(
1024
  $params,
1025
  $details['shipping_address']->getAddressParams( 'SHIPTO' )
includes/class-wc-gateway-ppec-with-paypal-addons.php CHANGED
@@ -39,73 +39,6 @@ class WC_Gateway_PPEC_With_PayPal_Addons extends WC_Gateway_PPEC_With_PayPal {
39
 
40
  add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
41
  add_action( 'woocommerce_subscription_failing_payment_method_' . $this->id, array( $this, 'update_failing_payment_method' ) );
42
- add_filter( 'woocommerce_payment_gateways_renewal_support_status_html', array( $this, 'subscription_tooltip' ), 10, 2 );
43
- add_filter( 'woocommerce_available_payment_gateways', array( $this, 'get_available_gataways_for_subscriptions' ), 20 );
44
- }
45
-
46
- /**
47
- * Filter for Subscriptions info tooltip html for this gateway
48
- *
49
- * @since 1.6.12
50
- *
51
- * @param string $html HTML of the tooltip
52
- * @param WC_Payment_Gateway $gateway Payment gateway to filter for
53
- *
54
- * @return string Filtered HTML
55
- */
56
- public function subscription_tooltip( $html, $gateway ) {
57
- if ( $gateway->id !== $this->id ) {
58
- return $html;
59
- }
60
- if ( 'no' === $gateway->get_option( 'require_billing', 'no' ) ) {
61
- $tool_tip = esc_attr__( 'You must enable the "Require billing address" option to support this gateway\'s features for virtual subscriptions.', 'woocommerce-gateway-paypal-express-checkout' );
62
- $status = esc_html__( 'Maybe', 'woocommerce-gateway-paypal-express-checkout' );
63
- $html = sprintf( '<span class="payment-method-features-info tips" data-tip="%1$s">%2$s</span>',
64
- $tool_tip,
65
- $status );
66
- }
67
- return $html;
68
- }
69
-
70
- /**
71
- * Filter determining whether to show this gateway during checkout
72
- *
73
- * @since 1.6.12
74
- *
75
- * @param array $gateways Array of payment gateways
76
- *
77
- * @return array Filtered array of payment gateways
78
- */
79
- public function get_available_gataways_for_subscriptions( $gateways ) {
80
- if ( ! $this->should_display_buttons_at_checkout() ) {
81
- unset( $gateways['ppec_paypal'] );
82
- }
83
- return $gateways;
84
- }
85
-
86
- /**
87
- * Checks if smart payment buttons can be displayed during the checkout
88
- *
89
- * @since 1.6.12
90
- *
91
- * @return bool True if buttons can be displayed
92
- */
93
- public function should_display_buttons_at_checkout() {
94
- if ( ! class_exists( 'WC_Subscriptions_Product' )
95
- || ! WC()->cart
96
- || 'yes' === $this->get_option( 'require_billing', 'no' ) ) {
97
- return true;
98
- }
99
- $cart_contents = WC()->cart->cart_contents;
100
- if ( empty( $cart_contents ) ) {
101
- return true;
102
- }
103
- foreach ( WC()->cart->cart_contents as $cart_item ) {
104
- if ( WC_Subscriptions_Product::is_subscription( $cart_item['data'] ) && ! $cart_item['data']->needs_shipping() ) {
105
- return false;
106
- }
107
- }
108
- return true;
109
  }
110
 
111
  /**
39
 
40
  add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 );
41
  add_action( 'woocommerce_subscription_failing_payment_method_' . $this->id, array( $this, 'update_failing_payment_method' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
43
 
44
  /**
includes/class-wc-gateway-ppec-with-spb-addons.php CHANGED
@@ -19,9 +19,6 @@ class WC_Gateway_PPEC_With_SPB_Addons extends WC_Gateway_PPEC_With_PayPal_Addons
19
  * Display PayPal button on the checkout page order review.
20
  */
21
  public function display_paypal_button() {
22
- if ( ! $this->should_display_buttons_at_checkout() ) {
23
- return;
24
- }
25
  wp_enqueue_script( 'wc-gateway-ppec-smart-payment-buttons' );
26
  ?>
27
  <div id="woo_pp_ec_button_checkout"></div>
19
  * Display PayPal button on the checkout page order review.
20
  */
21
  public function display_paypal_button() {
 
 
 
22
  wp_enqueue_script( 'wc-gateway-ppec-smart-payment-buttons' );
23
  ?>
24
  <div id="woo_pp_ec_button_checkout"></div>
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: 5.2.0
6
- Stable tag: 1.6.15
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -101,6 +101,10 @@ Please use this to inform us about bugs, or make contributions via PRs.
101
 
102
  == Changelog ==
103
 
 
 
 
 
104
  = 1.6.15 - 2019-06-19 =
105
  * Fix - Prevent PHP errors when no billing details are present in PP response
106
  * Fix - Require billing address for virtual products when enabled
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: 5.2.0
6
+ Stable tag: 1.6.16
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
101
 
102
  == Changelog ==
103
 
104
+ = 1.6.16 - 2019-07-18 =
105
+ * Fix - Don't require address for renewal of virtual subscriptions
106
+ * Fix - Avoid broken confirmation screen edge case after 10486 redirect
107
+
108
  = 1.6.15 - 2019-06-19 =
109
  * Fix - Prevent PHP errors when no billing details are present in PP response
110
  * Fix - Require billing address for virtual products when enabled
woocommerce-gateway-paypal-express-checkout.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce PayPal Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Checkout (https://www.paypal.com/us/webapps/mpp/paypal-checkout).
6
- * Version: 1.6.15
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2018 WooCommerce / PayPal.
@@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
27
  exit; // Exit if accessed directly
28
  }
29
 
30
- define( 'WC_GATEWAY_PPEC_VERSION', '1.6.15' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.
3
  * Plugin Name: WooCommerce PayPal Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Checkout (https://www.paypal.com/us/webapps/mpp/paypal-checkout).
6
+ * Version: 1.6.16
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2018 WooCommerce / PayPal.
27
  exit; // Exit if accessed directly
28
  }
29
 
30
+ define( 'WC_GATEWAY_PPEC_VERSION', '1.6.16' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.