WooCommerce PayPal Express Checkout Payment Gateway - Version 1.6.15

Version Description

  • 2019-06-19 =
  • Fix - Prevent PHP errors when no billing details are present in PP response
  • Fix - Require billing address for virtual products when enabled
  • Add - Hook when a payment error occurs
Download this release

Release Info

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

Code changes from version 1.6.14 to 1.6.15

changelog.txt CHANGED
@@ -1,5 +1,10 @@
1
  *** Changelog ***
2
 
 
 
 
 
 
3
  = 1.6.14 - 2019-05-08 =
4
  * Fix - Failing checkout when no addons are used
5
 
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
6
+ * Add - Hook when a payment error occurs
7
+
8
  = 1.6.14 - 2019-05-08 =
9
  * Fix - Failing checkout when no addons are used
10
 
includes/abstracts/abstract-wc-gateway-ppec.php CHANGED
@@ -173,6 +173,7 @@ abstract class WC_Gateway_PPEC extends WC_Payment_Gateway {
173
  'redirect' => wc_gateway_ppec()->settings->get_paypal_redirect_url( $session->token, true ),
174
  );
175
  } else {
 
176
  wc_add_notice( $e->getMessage(), 'error' );
177
  }
178
  }
173
  'redirect' => wc_gateway_ppec()->settings->get_paypal_redirect_url( $session->token, true ),
174
  );
175
  } else {
176
+ do_action( 'wc_gateway_ppec_process_payment_error', $e, $order );
177
  wc_add_notice( $e->getMessage(), 'error' );
178
  }
179
  }
includes/class-wc-gateway-ppec-admin-handler.php CHANGED
@@ -19,10 +19,10 @@ class WC_Gateway_PPEC_Admin_Handler {
19
  // defer this until for next release.
20
  // add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_checkout_sections' ) );
21
 
22
- add_action( 'woocommerce_order_status_on-hold_to_processing', array( $this, 'capture_payment' ) );
23
- add_action( 'woocommerce_order_status_on-hold_to_completed', array( $this, 'capture_payment' ) );
24
- add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'cancel_payment' ) );
25
- add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'cancel_payment' ) );
26
 
27
  add_filter( 'woocommerce_order_actions', array( $this, 'add_capture_charge_order_action' ) );
28
  add_action( 'woocommerce_order_action_ppec_capture_charge', array( $this, 'maybe_capture_charge' ) );
19
  // defer this until for next release.
20
  // add_filter( 'woocommerce_get_sections_checkout', array( $this, 'filter_checkout_sections' ) );
21
 
22
+ add_action( 'woocommerce_order_status_processing', array( $this, 'capture_payment' ) );
23
+ add_action( 'woocommerce_order_status_completed', array( $this, 'capture_payment' ) );
24
+ add_action( 'woocommerce_order_status_cancelled', array( $this, 'cancel_payment' ) );
25
+ add_action( 'woocommerce_order_status_refunded', array( $this, 'cancel_payment' ) );
26
 
27
  add_filter( 'woocommerce_order_actions', array( $this, 'add_capture_charge_order_action' ) );
28
  add_action( 'woocommerce_order_action_ppec_capture_charge', array( $this, 'maybe_capture_charge' ) );
includes/class-wc-gateway-ppec-checkout-details.php CHANGED
@@ -77,6 +77,7 @@ class PayPal_Checkout_Details {
77
 
78
  $this->payer_details = new PayPal_Checkout_Payer_Details();
79
  if ( ! $this->payer_details->loadFromGetECResponse( $getECResponse ) ) {
 
80
  $this->payer_details = false;
81
  }
82
 
77
 
78
  $this->payer_details = new PayPal_Checkout_Payer_Details();
79
  if ( ! $this->payer_details->loadFromGetECResponse( $getECResponse ) ) {
80
+ wc_gateway_ppec_log( sprintf( 'PayPal response did not include the payer billing details: %s', print_r( $getECResponse, true ) ) );
81
  $this->payer_details = false;
82
  }
83
 
includes/class-wc-gateway-ppec-checkout-handler.php CHANGED
@@ -128,7 +128,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
128
  return $fields;
129
  }
130
 
131
- if ( method_exists( WC()->cart, 'needs_shipping' ) && ! WC()->cart->needs_shipping() ) {
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 ) ) {
@@ -246,6 +246,10 @@ class WC_Gateway_PPEC_Checkout_Handler {
246
  wc_add_notice( $e->getMessage(), 'error' );
247
  return;
248
  }
 
 
 
 
249
  ?>
250
  <h3><?php _e( 'Billing details', 'woocommerce-gateway-paypal-express-checkout' ); ?></h3>
251
  <ul>
@@ -402,10 +406,9 @@ class WC_Gateway_PPEC_Checkout_Handler {
402
  $name = explode( ' ', $checkout_details->payments[0]->shipping_address->getName() );
403
  $first_name = array_shift( $name );
404
  $last_name = implode( ' ', $name );
405
- return array(
406
  'first_name' => $first_name,
407
  'last_name' => $last_name,
408
- 'company' => $checkout_details->payer_details->business_name,
409
  'address_1' => $checkout_details->payments[0]->shipping_address->getStreet1(),
410
  'address_2' => $checkout_details->payments[0]->shipping_address->getStreet2(),
411
  'city' => $checkout_details->payments[0]->shipping_address->getCity(),
@@ -413,6 +416,10 @@ class WC_Gateway_PPEC_Checkout_Handler {
413
  'postcode' => $checkout_details->payments[0]->shipping_address->getZip(),
414
  'country' => $checkout_details->payments[0]->shipping_address->getCountry(),
415
  );
 
 
 
 
416
  }
417
 
418
  /**
@@ -506,12 +513,14 @@ class WC_Gateway_PPEC_Checkout_Handler {
506
  $customer = WC()->customer;
507
 
508
  // Update billing/shipping addresses.
509
- $customer->set_billing_address( $billing_details['address_1'] );
510
- $customer->set_billing_address_2( $billing_details['address_2'] );
511
- $customer->set_billing_city( $billing_details['city'] );
512
- $customer->set_billing_postcode( $billing_details['postcode'] );
513
- $customer->set_billing_state( $billing_details['state'] );
514
- $customer->set_billing_country( $billing_details['country'] );
 
 
515
 
516
  if ( ! empty( $shipping_details ) ) {
517
  $customer->set_shipping_address( $shipping_details['address_1'] );
128
  return $fields;
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 ) ) {
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>
406
  $name = explode( ' ', $checkout_details->payments[0]->shipping_address->getName() );
407
  $first_name = array_shift( $name );
408
  $last_name = implode( ' ', $name );
409
+ $result = array(
410
  'first_name' => $first_name,
411
  'last_name' => $last_name,
 
412
  'address_1' => $checkout_details->payments[0]->shipping_address->getStreet1(),
413
  'address_2' => $checkout_details->payments[0]->shipping_address->getStreet2(),
414
  'city' => $checkout_details->payments[0]->shipping_address->getCity(),
416
  'postcode' => $checkout_details->payments[0]->shipping_address->getZip(),
417
  'country' => $checkout_details->payments[0]->shipping_address->getCountry(),
418
  );
419
+ if ( ! empty( $checkout_details->payer_details ) && property_exists( $checkout_details->payer_details, 'business_name' ) ) {
420
+ $result['company'] = $checkout_details->payer_details->business_name;
421
+ }
422
+ return $result;
423
  }
424
 
425
  /**
513
  $customer = WC()->customer;
514
 
515
  // Update billing/shipping addresses.
516
+ if ( ! empty( $billing_details ) ) {
517
+ $customer->set_billing_address( $billing_details['address_1'] );
518
+ $customer->set_billing_address_2( $billing_details['address_2'] );
519
+ $customer->set_billing_city( $billing_details['city'] );
520
+ $customer->set_billing_postcode( $billing_details['postcode'] );
521
+ $customer->set_billing_state( $billing_details['state'] );
522
+ $customer->set_billing_country( $billing_details['country'] );
523
+ }
524
 
525
  if ( ! empty( $shipping_details ) ) {
526
  $customer->set_shipping_address( $shipping_details['address_1'] );
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.14
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -101,6 +101,11 @@ Please use this to inform us about bugs, or make contributions via PRs.
101
 
102
  == Changelog ==
103
 
 
 
 
 
 
104
  = 1.6.14 - 2019-05-08 =
105
  * Fix - Failing checkout when no addons are used
106
 
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
 
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
107
+ * Add - Hook when a payment error occurs
108
+
109
  = 1.6.14 - 2019-05-08 =
110
  * Fix - Failing checkout when no addons are used
111
 
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.14
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.14' );
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.15
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.15' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.