From 44da087e9061d18641431bfe4e00a59e558e6fc6 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Wed, 23 Oct 2019 12:31:40 +0530 Subject: [PATCH 1/5] Braintree place order not working, PFW-506 --- classes/wc-gateway-braintree-angelleye.php | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/classes/wc-gateway-braintree-angelleye.php b/classes/wc-gateway-braintree-angelleye.php index 162c82bea..dca90cfba 100644 --- a/classes/wc-gateway-braintree-angelleye.php +++ b/classes/wc-gateway-braintree-angelleye.php @@ -509,6 +509,8 @@ public function payment_fields() { ?> enable_braintree_drop_in) { @@ -521,7 +523,15 @@ public function payment_fields() { @@ -1648,7 +1661,7 @@ public function payment_scripts() { return; } if ($this->enable_braintree_drop_in) { - wp_enqueue_script('braintree-gateway', 'https://js.braintreegateway.com/web/dropin/1.16.0/js/dropin.min.js', array('jquery'), null, false); + wp_enqueue_script('braintree-gateway', 'https://js.braintreegateway.com/web/dropin/1.20.4/js/dropin.min.js', array('jquery'), null, false); } else { wp_enqueue_style('braintree_checkout', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . 'assets/css/braintree-checkout.css', array(), VERSION_PFW); wp_enqueue_script('braintree-gateway-client', 'https://js.braintreegateway.com/web/3.35.0/js/client.min.js', array('jquery'), null, true); From f926e5800db397145f738d4fdd3f5729f262a7a4 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Thu, 24 Oct 2019 10:33:53 +0530 Subject: [PATCH 2/5] Saved Cards Not Displaying on Payment Methods Page - Braintree, PFW-507 --- paypal-for-woocommerce.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index abab87e13..104b6b8a5 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -152,6 +152,7 @@ public function __construct() add_action( 'wp_head', array( $this, 'paypal_for_woo_head_mark' ), 1 ); add_action( 'admin_footer', array($this, 'angelleye_add_deactivation_form')); add_action( 'wp_ajax_angelleye_send_deactivation', array($this, 'angelleye_handle_plugin_deactivation_request')); + add_action( 'wp', array( __CLASS__, 'angelleye_delete_payment_method_action' ), 10 ); $this->customer_id; } @@ -1287,6 +1288,40 @@ public function load_cartflow_pro_plugin() { include_once plugin_dir_path(__FILE__) . 'angelleye-includes/cartflows-pro/class-angelleye-cartflow-pro-helper.php'; } } + + /** + * Process the delete payment method form. + */ + public static function angelleye_delete_payment_method_action() { + global $wp, $woocommerce; + if ( isset( $wp->query_vars['delete-payment-method'] ) ) { + wc_nocache_headers(); + $token_id = absint( $wp->query_vars['delete-payment-method'] ); + $token = WC_Payment_Tokens::get( $token_id ); + if ( !is_null( $token ) && $token->get_gateway_id() === 'braintree' && get_current_user_id() == $token->get_user_id() && isset( $_REQUEST['_wpnonce'] ) || true === wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'delete-payment-method-' . $token_id ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + try { + $gateways = $woocommerce->payment_gateways->payment_gateways(); + $gateways['braintree']->angelleye_braintree_lib(); + $token_value = $token->get_token(); + Braintree_PaymentMethod::delete($token_value); + } catch (Braintree_Exception_NotFound $e) { + $this->add_log("Braintree_PaymentMethod::delete Braintree_Exception_NotFound: " . $e->getMessage()); + } catch (Braintree_Exception_Authentication $e) { + $this->add_log("Braintree_ClientToken::generate Exception: API keys are incorrect, Please double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa."); + } catch (Braintree_Exception_Authorization $e) { + $this->add_log("Braintree_ClientToken::generate Exception: The API key that you're using is not authorized to perform the attempted action according to the role assigned to the user who owns the API key."); + } catch (Braintree_Exception_DownForMaintenance $e) { + $this->add_log("Braintree_Exception_DownForMaintenance: Request times out."); + } catch (Braintree_Exception_ServerError $e) { + $this->add_log("Braintree_Exception_ServerError" . $e->getMessage()); + } catch (Braintree_Exception_SSLCertificate $e) { + $this->add_log("Braintree_Exception_SSLCertificate" . $e->getMessage()); + } catch (Exception $ex) { + $this->add_log("Exception" . $ex->getMessage()); + } + } + } + } } } new AngellEYE_Gateway_Paypal(); \ No newline at end of file From 686a7d19658134a54e2a2f4f0f81a97847f16d85 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Thu, 24 Oct 2019 11:52:27 +0530 Subject: [PATCH 3/5] Saved Cards Not Displaying on Payment Methods Page - Braintree, PFW-507 --- paypal-for-woocommerce.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index 104b6b8a5..727d03214 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -1305,19 +1305,19 @@ public static function angelleye_delete_payment_method_action() { $token_value = $token->get_token(); Braintree_PaymentMethod::delete($token_value); } catch (Braintree_Exception_NotFound $e) { - $this->add_log("Braintree_PaymentMethod::delete Braintree_Exception_NotFound: " . $e->getMessage()); + $gateways['braintree']->add_log("Braintree_PaymentMethod::delete Braintree_Exception_NotFound: " . $e->getMessage()); } catch (Braintree_Exception_Authentication $e) { - $this->add_log("Braintree_ClientToken::generate Exception: API keys are incorrect, Please double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa."); + $gateways['braintree']->add_log("Braintree_ClientToken::generate Exception: API keys are incorrect, Please double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa."); } catch (Braintree_Exception_Authorization $e) { - $this->add_log("Braintree_ClientToken::generate Exception: The API key that you're using is not authorized to perform the attempted action according to the role assigned to the user who owns the API key."); + $gateways['braintree']->add_log("Braintree_ClientToken::generate Exception: The API key that you're using is not authorized to perform the attempted action according to the role assigned to the user who owns the API key."); } catch (Braintree_Exception_DownForMaintenance $e) { - $this->add_log("Braintree_Exception_DownForMaintenance: Request times out."); + $gateways['braintree']->add_log("Braintree_Exception_DownForMaintenance: Request times out."); } catch (Braintree_Exception_ServerError $e) { - $this->add_log("Braintree_Exception_ServerError" . $e->getMessage()); + $gateways['braintree']->add_log("Braintree_Exception_ServerError" . $e->getMessage()); } catch (Braintree_Exception_SSLCertificate $e) { - $this->add_log("Braintree_Exception_SSLCertificate" . $e->getMessage()); + $gateways['braintree']->add_log("Braintree_Exception_SSLCertificate" . $e->getMessage()); } catch (Exception $ex) { - $this->add_log("Exception" . $ex->getMessage()); + $gateways['braintree']->add_log("Exception" . $ex->getMessage()); } } } From 7f3db867349755c2f1f8cfce6b4a58235aba0f34 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Thu, 24 Oct 2019 12:19:00 +0530 Subject: [PATCH 4/5] Saved Cards Not Displaying on Payment Methods Page - Braintree, PFW-507 --- classes/wc-gateway-braintree-angelleye.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/wc-gateway-braintree-angelleye.php b/classes/wc-gateway-braintree-angelleye.php index dca90cfba..f5d65230f 100644 --- a/classes/wc-gateway-braintree-angelleye.php +++ b/classes/wc-gateway-braintree-angelleye.php @@ -1266,7 +1266,7 @@ public function angelleye_do_payment($order) { } else { $customer_id = get_current_user_id(); } - $token->set_token($paymentMethod->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($paymentMethod->billingAgreementId, -4)); @@ -1890,7 +1890,7 @@ public function braintree_save_payment_method($customer_id, $result, $zero_amoun $token->set_user_id($customer_id); } elseif (!empty($braintree_method->billingAgreementId)) { $customer_id = get_current_user_id(); - $token->set_token($braintree_method->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($braintree_method->billingAgreementId, -4)); @@ -2670,7 +2670,7 @@ public function braintree_save_payment_method_auth($customer_id, $result, $order } else { $customer_id = get_current_user_id(); } - $token->set_token($braintree_method->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($braintree_method->billingAgreementId, -4)); From 88e638d119c31c32444bea6eaee4d71a420651c2 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Thu, 24 Oct 2019 12:19:00 +0530 Subject: [PATCH 5/5] delete card automatically when card remove in braintree account, PFW-507 --- classes/wc-gateway-braintree-angelleye.php | 6 ++-- paypal-for-woocommerce.php | 39 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/classes/wc-gateway-braintree-angelleye.php b/classes/wc-gateway-braintree-angelleye.php index dca90cfba..f5d65230f 100644 --- a/classes/wc-gateway-braintree-angelleye.php +++ b/classes/wc-gateway-braintree-angelleye.php @@ -1266,7 +1266,7 @@ public function angelleye_do_payment($order) { } else { $customer_id = get_current_user_id(); } - $token->set_token($paymentMethod->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($paymentMethod->billingAgreementId, -4)); @@ -1890,7 +1890,7 @@ public function braintree_save_payment_method($customer_id, $result, $zero_amoun $token->set_user_id($customer_id); } elseif (!empty($braintree_method->billingAgreementId)) { $customer_id = get_current_user_id(); - $token->set_token($braintree_method->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($braintree_method->billingAgreementId, -4)); @@ -2670,7 +2670,7 @@ public function braintree_save_payment_method_auth($customer_id, $result, $order } else { $customer_id = get_current_user_id(); } - $token->set_token($braintree_method->billingAgreementId); + $token->set_token($payment_method_token); $token->set_gateway_id($this->id); $token->set_card_type('PayPal Billing Agreement'); $token->set_last4(substr($braintree_method->billingAgreementId, -4)); diff --git a/paypal-for-woocommerce.php b/paypal-for-woocommerce.php index 727d03214..73586732d 100644 --- a/paypal-for-woocommerce.php +++ b/paypal-for-woocommerce.php @@ -153,6 +153,7 @@ public function __construct() add_action( 'admin_footer', array($this, 'angelleye_add_deactivation_form')); add_action( 'wp_ajax_angelleye_send_deactivation', array($this, 'angelleye_handle_plugin_deactivation_request')); add_action( 'wp', array( __CLASS__, 'angelleye_delete_payment_method_action' ), 10 ); + add_filter( 'woocommerce_saved_payment_methods_list', array($this, 'angelleye_synce_braintree_save_payment_methods'), 5, 2 ); $this->customer_id; } @@ -1322,6 +1323,44 @@ public static function angelleye_delete_payment_method_action() { } } } + + public function angelleye_synce_braintree_save_payment_methods($list, $customer_id) { + global $wp, $woocommerce; + try { + $gateways = $woocommerce->payment_gateways->payment_gateways(); + $gateways['braintree']->angelleye_braintree_lib(); + if( !empty($gateways['braintree'])) { + if ($gateways['braintree']->enable_tokenized_payments == 'yes') { + $payment_tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id, 'braintree' ); + foreach ( $payment_tokens as $payment_token ) { + $token_value = $payment_token->get_token(); + try { + Braintree_PaymentMethod::find($token_value); + } catch (Braintree_Exception_NotFound $e) { + $gateways['braintree']->add_log("Braintree_PaymentMethod::delete Braintree_Exception_NotFound: " . $e->getMessage()); + WC_Payment_Tokens::delete( $payment_token->get_id() ); + } catch (Braintree_Exception_Authentication $e) { + $gateways['braintree']->add_log("Braintree_ClientToken::generate Exception: API keys are incorrect, Please double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa."); + } catch (Braintree_Exception_Authorization $e) { + $gateways['braintree']->add_log("Braintree_ClientToken::generate Exception: The API key that you're using is not authorized to perform the attempted action according to the role assigned to the user who owns the API key."); + } catch (Braintree_Exception_DownForMaintenance $e) { + $gateways['braintree']->add_log("Braintree_Exception_DownForMaintenance: Request times out."); + } catch (Braintree_Exception_ServerError $e) { + $gateways['braintree']->add_log("Braintree_Exception_ServerError" . $e->getMessage()); + } catch (Braintree_Exception_SSLCertificate $e) { + $gateways['braintree']->add_log("Braintree_Exception_SSLCertificate" . $e->getMessage()); + } catch (Exception $ex) { + $gateways['braintree']->add_log("Exception" . $ex->getMessage()); + } + } + } + + } + } catch (Exception $ex) { + + } + return $list; + } } } new AngellEYE_Gateway_Paypal(); \ No newline at end of file