WooCommerce PayPal Powered by Braintree Payment Gateway - Version 1.2.3

Version Description

  • Fix - Handle uncaught exceptions thrown by Braintree SDK. API calls from SDK may throws exception, thus it need to be handled properly in try/catch block.
  • Fix - Issue where deactivating WooCommerce might throws an error
Download this release

Release Info

Developer akeda
Plugin Icon 128x128 WooCommerce PayPal Powered by Braintree Payment Gateway
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

classes/class-wc-gateway-paypal-braintree-subscription.php CHANGED
@@ -107,7 +107,13 @@ abstract class WC_Gateway_Paypal_Braintree_Subscription extends WC_Gateway_Paypa
107
  'paymentMethodNonce' => $paypal_braintree_nonce
108
  );
109
 
110
- $result = $gateway->customer()->create( $customer_args );
 
 
 
 
 
 
111
 
112
  if ( ! $result->success ) {
113
  $this->log( __FUNCTION__, "Error: Unable to create customer: {$result->message}" );
@@ -286,14 +292,20 @@ abstract class WC_Gateway_Paypal_Braintree_Subscription extends WC_Gateway_Paypa
286
  'recurring' => true,
287
  'customerId' => $braintree_customer_id,
288
  'channel' => 'WooThemes_BT', // aka BN tracking code
289
- 'orderId' => $order_id,
290
  'options' => array(
291
  'submitForSettlement' => true,
292
  'storeInVaultOnSuccess' => true
293
  )
294
  );
295
 
296
- $result = $gateway->transaction()->sale( $sale_args );
 
 
 
 
 
 
297
  if ( ! $result->success ) {
298
  $this->log( __FUNCTION__, "Error: Unable to process scheduled payment: {$result->message}" );
299
  return false;
107
  'paymentMethodNonce' => $paypal_braintree_nonce
108
  );
109
 
110
+ try {
111
+ $result = $gateway->customer()->create( $customer_args );
112
+ } catch ( Exception $e ) {
113
+ $this->log( __FUNCTION__, 'Error: Unable to create customer. Reason: ' . $e->getMessage() );
114
+ wc_add_notice( __( 'Error: PayPal Powered by Braintree was unable to create a customer record for you. Please try again later or use another means of payment.', 'woocommerce-gateway-paypal-braintree' ), 'error' );
115
+ return false;
116
+ }
117
 
118
  if ( ! $result->success ) {
119
  $this->log( __FUNCTION__, "Error: Unable to create customer: {$result->message}" );
292
  'recurring' => true,
293
  'customerId' => $braintree_customer_id,
294
  'channel' => 'WooThemes_BT', // aka BN tracking code
295
+ 'orderId' => $order->id,
296
  'options' => array(
297
  'submitForSettlement' => true,
298
  'storeInVaultOnSuccess' => true
299
  )
300
  );
301
 
302
+ try {
303
+ $result = $gateway->transaction()->sale( $sale_args );
304
+ } catch ( Exception $e ) {
305
+ $this->log( __FUNCTION__, 'Error: Unable to process scheduled payment. Reason: ' . $e->getMessage() );
306
+ return false;
307
+ }
308
+
309
  if ( ! $result->success ) {
310
  $this->log( __FUNCTION__, "Error: Unable to process scheduled payment: {$result->message}" );
311
  return false;
classes/class-wc-gateway-paypal-braintree.php CHANGED
@@ -829,7 +829,14 @@ abstract class WC_Gateway_Paypal_Braintree extends WC_Payment_Gateway {
829
  'accessToken' => $this->merchant_access_token,
830
  ) );
831
 
832
- $result = $gateway->transaction()->sale( $sale_args );
 
 
 
 
 
 
 
833
 
834
  // Check result
835
  if ( ! $result->success ) {
@@ -957,7 +964,7 @@ abstract class WC_Gateway_Paypal_Braintree extends WC_Payment_Gateway {
957
  try {
958
  $transaction = $gateway->transaction()->find( $transaction_id );
959
  } catch ( Exception $e ) {
960
- $this->log( __FUNCTION__, "Error: Unable to find transaction with transaction ID {$transaction_id}" );
961
  return false;
962
  }
963
 
@@ -983,10 +990,15 @@ abstract class WC_Gateway_Paypal_Braintree extends WC_Payment_Gateway {
983
  return false;
984
  }
985
 
986
- if ( "void" === $action_to_take ) {
987
- $result = $gateway->transaction()->void( $transaction_id );
988
- } else {
989
- $result = $gateway->transaction()->refund( $transaction_id, $refund_amount );
 
 
 
 
 
990
  }
991
 
992
  if ( ! $result->success ) {
829
  'accessToken' => $this->merchant_access_token,
830
  ) );
831
 
832
+ try {
833
+ $result = $gateway->transaction()->sale( $sale_args );
834
+ } catch ( Exception $e ) {
835
+ $notice = sprintf( __( 'Error: PayPal Powered by Braintree was unable to complete the transaction. Please try again later or use another means of payment. Reason: %s', 'woocommerce-gateway-paypal-braintree' ), $e->getMessage() );
836
+ wc_add_notice( $notice, 'error' );
837
+ $this->log( __FUNCTION__, 'Error: Unable to complete transaction. Reason: ' . $e->getMessage() );
838
+ return false;
839
+ }
840
 
841
  // Check result
842
  if ( ! $result->success ) {
964
  try {
965
  $transaction = $gateway->transaction()->find( $transaction_id );
966
  } catch ( Exception $e ) {
967
+ $this->log( __FUNCTION__, "Error: Unable to find transaction with transaction ID {$transaction_id}. Reason: " . $e->getMessage() );
968
  return false;
969
  }
970
 
990
  return false;
991
  }
992
 
993
+ try {
994
+ if ( "void" === $action_to_take ) {
995
+ $result = $gateway->transaction()->void( $transaction_id );
996
+ } else {
997
+ $result = $gateway->transaction()->refund( $transaction_id, $refund_amount );
998
+ }
999
+ } catch ( Exception $e ) {
1000
+ $this->log( __FUNCTION__, 'Error: The transaction cannot be voided nor refunded. Reason: ' . $e->getMessage() );
1001
+ return false;
1002
  }
1003
 
1004
  if ( ! $result->success ) {
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WooCommerce PayPal Powered by Braintree Payment Gateway ===
2
- Contributors: automattic, woothemes, akeda, allendav, royho, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal, braintree
4
  Requires at least: 4.4
5
  Tested up to: 4.5.2
6
- Stable tag: 1.2.2
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -77,6 +77,16 @@ For help setting up and configuring, please refer to our [user guide](http://doc
77
 
78
  Make sure PayPal is enabled on your Braintree account by following the [Braintree PayPal Setup Guide](https://articles.braintreepayments.com/guides/paypal/setup-guide).
79
 
 
 
 
 
 
 
 
 
 
 
80
  = Where can I get support or talk to other users? =
81
 
82
  If you get stuck, you can ask for help in the Plugin Forum.
@@ -100,6 +110,10 @@ New feature requests and bugs reports can be made in the plugin forum.
100
 
101
  == Changelog ==
102
 
 
 
 
 
103
  = 1.2.2 =
104
  * Tweak - Updated FAQ that emphasizes this plugin only works in the U.S. currently
105
  * Fix - Updated JS SDK to 2.24.1 which should fixes issue where credit card fields working intermittently
1
  === WooCommerce PayPal Powered by Braintree Payment Gateway ===
2
+ Contributors: automattic, woothemes, akeda, allendav, royho, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, BFTrick
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal, braintree
4
  Requires at least: 4.4
5
  Tested up to: 4.5.2
6
+ Stable tag: 1.2.3
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
77
 
78
  Make sure PayPal is enabled on your Braintree account by following the [Braintree PayPal Setup Guide](https://articles.braintreepayments.com/guides/paypal/setup-guide).
79
 
80
+ = What do I need to do if I'm updating from the retired premium Braintree plugin from WooThemes.com?
81
+
82
+ You'll need to go through the same installation process as everyone else. Luckily it's only a few clicks (no need to copy and paste API keys) so it should only take a minute.
83
+
84
+ Credit card tokens will not migrate. Your customers will have to reenter their CC details once. All transactions made with the new plugin will let the user choose if they want their CC details saved (as tokens of course) so they don't have to reneter them every time.
85
+
86
+ = Can I use this extension just for PayPal and use another gateway for Credit Cards? =
87
+
88
+ You have to connect to PayPal through your Braintree account so it doesn't make a lot of sense to use this just for PayPal. But there's nothing stopping you from adding another gateway to accept credit cards.
89
+
90
  = Where can I get support or talk to other users? =
91
 
92
  If you get stuck, you can ask for help in the Plugin Forum.
110
 
111
  == Changelog ==
112
 
113
+ = 1.2.3 =
114
+ * Fix - Handle uncaught exceptions thrown by Braintree SDK. API calls from SDK may throws exception, thus it need to be handled properly in try/catch block.
115
+ * Fix - Issue where deactivating WooCommerce might throws an error
116
+
117
  = 1.2.2 =
118
  * Tweak - Updated FAQ that emphasizes this plugin only works in the U.S. currently
119
  * Fix - Updated JS SDK to 2.24.1 which should fixes issue where credit card fields working intermittently
woocommerce-gateway-paypal-powered-by-braintree.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Receive payments using Paypal Powered by Braintree. A server with cURL, SSL support, and a valid SSL certificate is required (for security reasons) for this gateway to function. Requires PHP 5.4+
6
  * Author: WooThemes
7
  * Author URI: http://woothemes.com/
8
- * Version: 1.2.2
9
  *
10
  * Copyright (c) 2016 WooThemes
11
  *
@@ -256,7 +256,10 @@ class WC_PayPal_Braintree_Loader {
256
  * @return string Braintree checkout setting link
257
  */
258
  public function get_setting_link() {
259
- $use_id_as_section = version_compare( WC()->version, '2.6', '>=' );
 
 
 
260
 
261
  if ( $this->subscription_support_enabled ) {
262
  $section_slug = $use_id_as_section ? 'paypalbraintree_cards' : strtolower( 'WC_Gateway_Paypal_Braintree_Pay_With_Card_Subscription' );
@@ -377,6 +380,9 @@ class WC_PayPal_Braintree_Loader {
377
  * @since 1.0.0
378
  */
379
  function possibly_enqueue_scripts() {
 
 
 
380
 
381
  if ( ! is_checkout() && ! is_cart() ) {
382
  return;
@@ -421,7 +427,13 @@ class WC_PayPal_Braintree_Loader {
421
  $braintree_gateway = new Braintree_Gateway( array(
422
  'accessToken' => $merchant_access_token,
423
  ) );
424
- $client_token = $braintree_gateway->clientToken()->generate();
 
 
 
 
 
 
425
 
426
  $paypal_braintree_data = array(
427
  'token' => $client_token,
@@ -588,7 +600,7 @@ class WC_PayPal_Braintree_Loader {
588
  */
589
  public function possibly_cancel_checkout_with_paypal() {
590
 
591
- if ( is_cart() && ! empty( $_GET['wc_paypal_braintree_clear_session'] ) ) {
592
  $this->possibly_clear_session_data();
593
  wc_add_notice( __( 'You have cancelled Checkout with PayPal. Please try to process your order again.', 'woocommerce-gateway-paypal-braintree' ), 'notice' );
594
  }
@@ -832,16 +844,25 @@ class WC_PayPal_Braintree_Loader {
832
  'accessToken' => $token,
833
  ) );
834
 
835
- $transaction_details = $trans_id ? $gateway->transaction()->find( $trans_id ) : false;
 
 
 
 
 
 
 
 
 
836
 
837
  if ( $trans_id && 'authorized' === $transaction_details->status ) {
838
- $result = $gateway->transaction()->submitForSettlement( $trans_id, floatval( $order->order_total ) );
 
839
 
840
- if ( is_wp_error( $result ) ) {
841
- $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $result->get_error_message() );
842
- } else {
843
  $order->add_order_note( sprintf( __( 'PayPal Braintree charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-braintree' ), $result->transaction->id ) );
844
  update_post_meta( $order->id, '_pp_braintree_charge_captured', 'yes' );
 
 
845
  }
846
  }
847
  }
@@ -866,17 +887,27 @@ class WC_PayPal_Braintree_Loader {
866
  'accessToken' => $token,
867
  ) );
868
 
869
- $transaction_details = $trans_id ? $gateway->transaction()->find( $trans_id ) : false;
 
 
 
 
 
 
 
 
 
870
 
871
  if ( $trans_id && 'authorized' === $transaction_details->status ) {
872
- $result = $gateway->transaction()->void( $trans_id );
 
873
 
874
- if ( is_wp_error( $result ) ) {
875
- $order->add_order_note( __( 'Unable to void charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $result->get_error_message() );
876
- } else {
877
  $order->add_order_note( sprintf( __( 'PayPal Braintree charge voided (Charge ID: %s)', 'woocommerce-gateway-paypal-braintree' ), $result->transaction->id ) );
878
  delete_post_meta( $order->id, '_pp_braintree_charge_captured' );
879
  delete_post_meta( $order->id, '_transaction_id' );
 
 
 
880
  }
881
  }
882
  }
5
  * Description: Receive payments using Paypal Powered by Braintree. A server with cURL, SSL support, and a valid SSL certificate is required (for security reasons) for this gateway to function. Requires PHP 5.4+
6
  * Author: WooThemes
7
  * Author URI: http://woothemes.com/
8
+ * Version: 1.2.3
9
  *
10
  * Copyright (c) 2016 WooThemes
11
  *
256
  * @return string Braintree checkout setting link
257
  */
258
  public function get_setting_link() {
259
+ $use_id_as_section = true;
260
+ if ( function_exists( 'WC' ) ) {
261
+ $use_id_as_section = version_compare( WC()->version, '2.6', '>=' );
262
+ }
263
 
264
  if ( $this->subscription_support_enabled ) {
265
  $section_slug = $use_id_as_section ? 'paypalbraintree_cards' : strtolower( 'WC_Gateway_Paypal_Braintree_Pay_With_Card_Subscription' );
380
  * @since 1.0.0
381
  */
382
  function possibly_enqueue_scripts() {
383
+ if ( ! function_exists( 'is_checkout' ) || ! function_exists( 'is_cart' ) ) {
384
+ return;
385
+ }
386
 
387
  if ( ! is_checkout() && ! is_cart() ) {
388
  return;
427
  $braintree_gateway = new Braintree_Gateway( array(
428
  'accessToken' => $merchant_access_token,
429
  ) );
430
+
431
+ try {
432
+ $client_token = $braintree_gateway->clientToken()->generate();
433
+ } catch ( Exception $e ) {
434
+ $this->log( __FUNCTION__, 'Error: Unable to generate client token. Reason: ' . $e->getMessage() );
435
+ return;
436
+ }
437
 
438
  $paypal_braintree_data = array(
439
  'token' => $client_token,
600
  */
601
  public function possibly_cancel_checkout_with_paypal() {
602
 
603
+ if ( function_exists( 'is_cart' ) && is_cart() && ! empty( $_GET['wc_paypal_braintree_clear_session'] ) ) {
604
  $this->possibly_clear_session_data();
605
  wc_add_notice( __( 'You have cancelled Checkout with PayPal. Please try to process your order again.', 'woocommerce-gateway-paypal-braintree' ), 'notice' );
606
  }
844
  'accessToken' => $token,
845
  ) );
846
 
847
+ $transaction_details = false;
848
+ if ( $trans_id ) {
849
+ try {
850
+ $transaction_details = $gateway->transaction()->find( $trans_id );
851
+ } catch ( Exception $e ) {
852
+ $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $e->getMessage() );
853
+ $this->log( __FUNCTION__, "Error: Unable to find transaction with transaction ID {$trans_id}. Reason: " . $e->getMessage() );
854
+ return;
855
+ }
856
+ }
857
 
858
  if ( $trans_id && 'authorized' === $transaction_details->status ) {
859
+ try {
860
+ $result = $gateway->transaction()->submitForSettlement( $trans_id, floatval( $order->order_total ) );
861
 
 
 
 
862
  $order->add_order_note( sprintf( __( 'PayPal Braintree charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-braintree' ), $result->transaction->id ) );
863
  update_post_meta( $order->id, '_pp_braintree_charge_captured', 'yes' );
864
+ } catch ( Exception $e ) {
865
+ $order->add_order_note( __( 'Unable to capture charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $result->get_error_message() );
866
  }
867
  }
868
  }
887
  'accessToken' => $token,
888
  ) );
889
 
890
+ $transaction_details = false;
891
+ if ( $trans_id ) {
892
+ try {
893
+ $transaction_details = $gateway->transaction()->find( $trans_id );
894
+ } catch ( Exception $e ) {
895
+ $this->log( __FUNCTION__, "Error: Unable to find transaction with transaction ID {$trans_id}. Reason: " . $e->getMessage() );
896
+ $order->add_order_note( __( 'Unable to void charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $e->getMessage() );
897
+ return;
898
+ }
899
+ }
900
 
901
  if ( $trans_id && 'authorized' === $transaction_details->status ) {
902
+ try {
903
+ $result = $gateway->transaction()->void( $trans_id );
904
 
 
 
 
905
  $order->add_order_note( sprintf( __( 'PayPal Braintree charge voided (Charge ID: %s)', 'woocommerce-gateway-paypal-braintree' ), $result->transaction->id ) );
906
  delete_post_meta( $order->id, '_pp_braintree_charge_captured' );
907
  delete_post_meta( $order->id, '_transaction_id' );
908
+ } catch ( Exception $e ) {
909
+ $this->log( __FUNCTION__, 'Error: Unable to void charge. Reason: ' . $e->getMessage() );
910
+ $order->add_order_note( __( 'Unable to void charge!', 'woocommerce-gateway-paypal-braintree' ) . ' ' . $e->getMessage() );
911
  }
912
  }
913
  }