WooCommerce PayPal Express Checkout Payment Gateway - Version 1.4.3

Version Description

  • Fix - Refunds not working on authorize then captured transactions.
  • Fix - Checkout on single product available before variations are chosen.
  • Fix - Not Returning PayPal Transaction Fee.
  • Fix - 10431 (Item Amount Invalid at Checkout) error with discounts.
  • Fix - Phone not returned and "Require Phone Number" setting not working.
Download this release

Release Info

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

Code changes from version 1.4.2 to 1.4.3

assets/js/wc-gateway-ppec-generate-cart.js CHANGED
@@ -2,6 +2,26 @@
2
  ;(function( $, window, document ) {
3
  'use strict';
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  var get_attributes = function() {
6
  var select = $( '.variations_form' ).find( '.variations select' ),
7
  data = {},
@@ -27,9 +47,28 @@
27
  };
28
  };
29
 
30
- $( '#woo_pp_ec_button' ).click( function( event ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  event.preventDefault();
32
 
 
 
 
 
 
 
33
  var data = {
34
  'nonce': wc_ppec_context.generate_cart_nonce,
35
  'qty': $( '.quantity .qty' ).val(),
2
  ;(function( $, window, document ) {
3
  'use strict';
4
 
5
+ var button_enabled = true;
6
+
7
+ var toggle_button_availability = function( available ) {
8
+ if ( available ) {
9
+ button_enabled = true;
10
+ $( '#woo_pp_ec_button_product' ).css( {
11
+ 'cursor': '',
12
+ '-webkit-filter': '', // Safari 6.0 - 9.0
13
+ 'filter': '',
14
+ } );
15
+ } else {
16
+ button_enabled = false;
17
+ $( '#woo_pp_ec_button_product' ).css( {
18
+ 'cursor': 'not-allowed',
19
+ '-webkit-filter': 'grayscale( 100% )', // Safari 6.0 - 9.0
20
+ 'filter': 'grayscale( 100% )',
21
+ } );
22
+ }
23
+ }
24
+
25
  var get_attributes = function() {
26
  var select = $( '.variations_form' ).find( '.variations select' ),
27
  data = {},
47
  };
48
  };
49
 
50
+ // It's a variations form, button availability should depend on its events
51
+ if ( $( '.variations_form' ).length ) {
52
+ toggle_button_availability( false );
53
+
54
+ $( '.variations_form' )
55
+ .on( 'show_variation', function( event, form, purchasable ) {
56
+ toggle_button_availability( purchasable );
57
+ } )
58
+ .on( 'hide_variation', function() {
59
+ toggle_button_availability( false );
60
+ } );
61
+ }
62
+
63
+ $( '#woo_pp_ec_button_product' ).click( function( event ) {
64
  event.preventDefault();
65
 
66
+ if ( ! button_enabled ) {
67
+ return;
68
+ }
69
+
70
+ toggle_button_availability( false );
71
+
72
  var data = {
73
  'nonce': wc_ppec_context.generate_cart_nonce,
74
  'qty': $( '.quantity .qty' ).val(),
includes/class-wc-gateway-ppec-admin-handler.php CHANGED
@@ -168,6 +168,11 @@ class WC_Gateway_PPEC_Admin_Handler {
168
  $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-express-checkout' ) . ' ' . $result->get_error_message() );
169
  } else {
170
  update_post_meta( $order_id, '_paypal_status', ! empty( $trans_details['PAYMENTSTATUS'] ) ? $trans_details['PAYMENTSTATUS'] : 'completed' );
 
 
 
 
 
171
  $order->add_order_note( sprintf( __( 'PayPal Express Checkout charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-express-checkout' ), $trans_id ) );
172
  }
173
  }
168
  $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-express-checkout' ) . ' ' . $result->get_error_message() );
169
  } else {
170
  update_post_meta( $order_id, '_paypal_status', ! empty( $trans_details['PAYMENTSTATUS'] ) ? $trans_details['PAYMENTSTATUS'] : 'completed' );
171
+
172
+ if ( ! empty( $result['TRANSACTIONID'] ) ) {
173
+ update_post_meta( $order_id, '_transaction_id', $result['TRANSACTIONID'] );
174
+ }
175
+
176
  $order->add_order_note( sprintf( __( 'PayPal Express Checkout charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-express-checkout' ), $trans_id ) );
177
  }
178
  }
includes/class-wc-gateway-ppec-cart-handler.php CHANGED
@@ -132,7 +132,7 @@ class WC_Gateway_PPEC_Cart_Handler {
132
  ?>
133
  <div class="wcppec-checkout-buttons woo_pp_cart_buttons_div">
134
 
135
- <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button" class="wcppec-checkout-buttons__button">
136
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
137
  </a>
138
  </div>
132
  ?>
133
  <div class="wcppec-checkout-buttons woo_pp_cart_buttons_div">
134
 
135
+ <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button_product" class="wcppec-checkout-buttons__button">
136
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
137
  </a>
138
  </div>
includes/class-wc-gateway-ppec-checkout-handler.php CHANGED
@@ -229,7 +229,9 @@ class WC_Gateway_PPEC_Checkout_Handler {
229
  <?php endif; ?>
230
 
231
  <?php if ( ! empty( $checkout_details->payer_details->phone_number ) ) : ?>
232
- <li><strong><?php _e( 'Tel:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->phone_number ); ?></li>
 
 
233
  <?php endif; ?>
234
  </ul>
235
  <?php
@@ -323,6 +325,14 @@ class WC_Gateway_PPEC_Checkout_Handler {
323
  return array();
324
  }
325
 
 
 
 
 
 
 
 
 
326
  return array(
327
  'first_name' => $checkout_details->payer_details->first_name,
328
  'last_name' => $checkout_details->payer_details->last_name,
@@ -333,7 +343,7 @@ class WC_Gateway_PPEC_Checkout_Handler {
333
  'state' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getState() : '',
334
  'postcode' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getZip() : '',
335
  'country' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getCountry() : $checkout_details->payer_details->country,
336
- 'phone' => $checkout_details->payer_details->phone_number,
337
  'email' => $checkout_details->payer_details->email,
338
  );
339
  }
229
  <?php endif; ?>
230
 
231
  <?php if ( ! empty( $checkout_details->payer_details->phone_number ) ) : ?>
232
+ <li><strong><?php _e( 'Phone:', 'woocommerce-gateway-paypal-express-checkout' ) ?></strong> <?php echo esc_html( $checkout_details->payer_details->phone_number ); ?></li>
233
+ <?php elseif ( 'yes' === wc_gateway_ppec()->settings->require_phone_number ) : ?>
234
+ <li><?php $fields = WC()->checkout->get_checkout_fields( 'billing' ); woocommerce_form_field( 'billing_phone', $fields['billing_phone'], WC()->checkout->get_value( 'billing_phone' ) ); ?></li>
235
  <?php endif; ?>
236
  </ul>
237
  <?php
325
  return array();
326
  }
327
 
328
+ $phone = '';
329
+
330
+ if ( ! empty( $checkout_details->payer_details->phone_number ) ) {
331
+ $phone = $checkout_details->payer_details->phone_number;
332
+ } elseif ( 'yes' === wc_gateway_ppec()->settings->require_phone_number && ! empty( $_POST['billing_phone'] ) ) {
333
+ $phone = wc_clean( $_POST['billing_phone'] );
334
+ }
335
+
336
  return array(
337
  'first_name' => $checkout_details->payer_details->first_name,
338
  'last_name' => $checkout_details->payer_details->last_name,
343
  'state' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getState() : '',
344
  'postcode' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getZip() : '',
345
  'country' => $checkout_details->payer_details->billing_address ? $checkout_details->payer_details->billing_address->getCountry() : $checkout_details->payer_details->country,
346
+ 'phone' => $phone,
347
  'email' => $checkout_details->payer_details->email,
348
  );
349
  }
includes/class-wc-gateway-ppec-client.php CHANGED
@@ -547,7 +547,7 @@ class WC_Gateway_PPEC_Client {
547
  // Add line item to make up different between WooCommerce
548
  // calculations and PayPal calculations.
549
  $diff = round( $details['total_item_amount'] - $rounded_total, $decimals );
550
- if ( $diff != 0 ) {
551
  $extra_line_item = $this->_get_extra_offset_line_item( $diff );
552
 
553
  $details['items'][] = $extra_line_item;
@@ -603,7 +603,7 @@ class WC_Gateway_PPEC_Client {
603
  $lisum += $values['quantity'] * $values['amount'];
604
  }
605
 
606
- if ( 0 !== $lisum ) {
607
  $details['items'][] = $this->_get_extra_offset_line_item( $details['total_item_amount'] - $lisum );
608
  }
609
 
547
  // Add line item to make up different between WooCommerce
548
  // calculations and PayPal calculations.
549
  $diff = round( $details['total_item_amount'] - $rounded_total, $decimals );
550
+ if ( abs( $diff ) > 0.000001 ) {
551
  $extra_line_item = $this->_get_extra_offset_line_item( $diff );
552
 
553
  $details['items'][] = $extra_line_item;
603
  $lisum += $values['quantity'] * $values['amount'];
604
  }
605
 
606
+ if ( abs( $lisum ) > 0.000001 ) {
607
  $details['items'][] = $this->_get_extra_offset_line_item( $details['total_item_amount'] - $lisum );
608
  }
609
 
includes/class-wc-gateway-ppec-ipn-handler.php CHANGED
@@ -166,8 +166,7 @@ class WC_Gateway_PPEC_IPN_Handler extends WC_Gateway_PPEC_PayPal_Request_Handler
166
  * @param array $posted_data Posted data
167
  */
168
  protected function payment_status_completed( $order, $posted_data ) {
169
- $old_wc = version_compare( WC_VERSION, '3.0', '<' );
170
- $order_id = $old_wc ? $order->id : $order->get_id();
171
 
172
  if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
173
  wc_gateway_ppec_log( 'Aborting, Order #' . $order_id . ' is already complete.' );
@@ -184,11 +183,7 @@ class WC_Gateway_PPEC_IPN_Handler extends WC_Gateway_PPEC_PayPal_Request_Handler
184
  if ( ! empty( $posted_data['mc_fee'] ) ) {
185
  // Log paypal transaction fee.
186
  $transaction_fee = wc_clean( $posted_data['mc_fee'] );
187
- if ( $old_wc ) {
188
- update_post_meta( $order_id, 'PayPal Transaction Fee', $transaction_fee );
189
- } else {
190
- $order->update_meta_data( 'PayPal Transaction Fee', $transaction_fee );
191
- }
192
  }
193
  } else {
194
  if ( 'authorization' === $posted_data['pending_reason'] ) {
166
  * @param array $posted_data Posted data
167
  */
168
  protected function payment_status_completed( $order, $posted_data ) {
169
+ $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id();
 
170
 
171
  if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
172
  wc_gateway_ppec_log( 'Aborting, Order #' . $order_id . ' is already complete.' );
183
  if ( ! empty( $posted_data['mc_fee'] ) ) {
184
  // Log paypal transaction fee.
185
  $transaction_fee = wc_clean( $posted_data['mc_fee'] );
186
+ update_post_meta( $order_id, 'PayPal Transaction Fee', $transaction_fee );
 
 
 
 
187
  }
188
  } else {
189
  if ( 'authorization' === $posted_data['pending_reason'] ) {
readme.txt CHANGED
@@ -2,8 +2,8 @@
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.7
6
- Stable tag: 1.4.2
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.2 =
89
  * Fix - _paypal_status on Authorize transactions not updating to processing after capture.
90
  * Fix - 10413 (The totals of the cart item amounts do not match order amounts) error with discounts.
@@ -92,7 +99,7 @@ https://gist.github.com/mikejolley/ad2ecc286c9ad6cefbb7065ba6dfef48
92
 
93
  = 1.4.1 =
94
  * Fix - Properly calculate whether Billing phone is required or not.
95
- * Fix - Set NOSHIPPING based on product shipping requiredness (e.g. virtual products do not need shipping, etc)
96
 
97
  = 1.4.0 =
98
  * Tweak - Use shipping discount instead of tax when adjustment negative.
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.8.1
6
+ Stable tag: 1.4.3
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
85
 
86
  == Changelog ==
87
 
88
+ = 1.4.3 =
89
+ * Fix - Refunds not working on authorize then captured transactions.
90
+ * Fix - Checkout on single product available before variations are chosen.
91
+ * Fix - Not Returning PayPal Transaction Fee.
92
+ * Fix - 10431 (Item Amount Invalid at Checkout) error with discounts.
93
+ * Fix - Phone not returned and "Require Phone Number" setting not working.
94
+
95
  = 1.4.2 =
96
  * Fix - _paypal_status on Authorize transactions not updating to processing after capture.
97
  * Fix - 10413 (The totals of the cart item amounts do not match order amounts) error with discounts.
99
 
100
  = 1.4.1 =
101
  * Fix - Properly calculate whether Billing phone is required or not.
102
+ * Fix - Set NOSHIPPING based on product shipping requiredness (e.g. virtual products do not need shipping, etc).
103
 
104
  = 1.4.0 =
105
  * Tweak - Use shipping discount instead of tax when adjustment negative.
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.2
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2017 WooCommerce / PayPal.
@@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
25
  exit; // Exit if accessed directly
26
  }
27
 
28
- define( 'WC_GATEWAY_PPEC_VERSION', '1.4.2' );
29
 
30
  /**
31
  * 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.3
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.4.3' );
29
 
30
  /**
31
  * Return instance of WC_Gateway_PPEC_Plugin.