From f9bbb8e824227765d79e57fe936e7e88a4a6a550 Mon Sep 17 00:00:00 2001 From: Deepak Maurya Date: Fri, 1 May 2020 01:08:08 +0530 Subject: [PATCH] Resolved the braintree function not found fatal error on payment methods page and cartflows checkout, PFW-602 --- ...tflows-pro-gateway-braintree-angelleye.php | 12 ++-- classes/wc-gateway-braintree-angelleye.php | 41 +++++++++++--- paypal-for-woocommerce.php | 55 ++++++++++--------- 3 files changed, 66 insertions(+), 42 deletions(-) diff --git a/angelleye-includes/cartflows-pro/class-cartflows-pro-gateway-braintree-angelleye.php b/angelleye-includes/cartflows-pro/class-cartflows-pro-gateway-braintree-angelleye.php index cb244bbca..a2e87b632 100644 --- a/angelleye-includes/cartflows-pro/class-cartflows-pro-gateway-braintree-angelleye.php +++ b/angelleye-includes/cartflows-pro/class-cartflows-pro-gateway-braintree-angelleye.php @@ -198,21 +198,21 @@ public function process_offer_payment($order, $product) { } try { - $gateway->response = Braintree_Transaction::sale($request_data); + $gateway->response = $gateway->braintree_gateway->transaction()->sale($request_data); do_action('angelleye_paypal_response_data', $gateway->response, $request_data, '1', $gateway->sandbox, false, 'braintree'); - } catch (Braintree_Exception_Authentication $e) { + } catch (\Braintree\Exception\Authentication $e) { $gateway->add_log("Braintree_Transaction::sale Braintree_Exception_Authentication: API keys are incorrect, Please double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa."); return $success = false; - } catch (Braintree_Exception_Authorization $e) { + } catch (\Braintree\Exception\Authorization $e) { $gateway->add_log("Braintree_Transaction::sale Braintree_Exception_Authorization: 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."); return $success = false; - } catch (Braintree_Exception_DownForMaintenance $e) { + } catch (\Braintree\Exception\ServiceUnavailable $e) { $gateway->add_log("Braintree_Transaction::sale Braintree_Exception_DownForMaintenance: Request times out."); return $success = false; - } catch (Braintree_Exception_ServerError $e) { + } catch (\Braintree\Exception\ServerError $e) { $gateway->add_log("Braintree_Transaction::sale Braintree_Exception_ServerError " . $e->getMessage()); return $success = false; - } catch (Braintree_Exception_SSLCertificate $e) { + } catch (\Braintree\Exception\SSLCertificate $e) { $gateway->add_log("Braintree_Transaction::sale Braintree_Exception_SSLCertificate " . $e->getMessage()); return $success = false; } catch (Exception $e) { diff --git a/classes/wc-gateway-braintree-angelleye.php b/classes/wc-gateway-braintree-angelleye.php index bdd7a49b6..9754b882a 100644 --- a/classes/wc-gateway-braintree-angelleye.php +++ b/classes/wc-gateway-braintree-angelleye.php @@ -473,7 +473,22 @@ public function payment_fields() { $this->add_log("Generate a client token Braintree\Exception\SSLCertificate" . $e->getMessage()); wp_redirect(wc_get_cart_url()); exit; - } catch (Braintree\Exception\NotFound $e) { + }catch (InvalidArgumentException $e){ + if ($e->getMessage() == 'Customer specified by customer_id does not exist') { + if (is_user_logged_in()) { + $customer_id = get_current_user_id(); + delete_user_meta($customer_id, 'braintree_customer_id'); + $clientToken = $this->braintree_gateway->clientToken()->generate(); + } + } else { + $error = $this->get_braintree_exception_message($e); + wc_add_notice($error, 'error'); + $this->add_log("Generate a client token Braintree\Exception\NotFound" . $e->getMessage()); + wp_redirect(wc_get_cart_url()); + exit; + } + } + catch (Braintree\Exception\NotFound $e) { if ($e->getMessage() == 'Customer specified by customer_id does not exist') { if (is_user_logged_in()) { $customer_id = get_current_user_id(); @@ -488,8 +503,7 @@ public function payment_fields() { exit; } } catch (Exception $ex) { - - $error = $this->get_braintree_exception_message($e); + $error = $this->get_braintree_exception_message($ex); wc_add_notice($error, 'error'); wp_redirect(wc_get_cart_url()); exit; @@ -513,7 +527,16 @@ public function payment_fields() { var is_registration_required = "checkout()->is_registration_required(); ?>"; var is_logged_in = ""; - get_order_total(); + + /** + * //Adding it since Braintree doesn't support 0, it throws error + * 94505 - Amount can be any number of digits optionally followed by a decimal point . and up to two decimal places following the decimal point. Commas , are not allowed. + * The amount you specified must be a number greater than 0. + */ + if($order_total==0) $order_total = 0.01; + if ($this->enable_braintree_drop_in) { ?>
@@ -581,7 +604,7 @@ function is_angelleye_braintree_selected() { container: "#braintree-payment-form", threed_secure_enabled === true) { ?> threeDSecure: { - amount: 'get_order_total(); ?>', + amount: , }, locale: '', @@ -595,7 +618,7 @@ function is_angelleye_braintree_selected() { transactionInfo: { totalPriceStatus: 'FINAL', - totalPrice: 'get_order_total(); ?>', + totalPrice: '', currencyCode: '' }, cardRequirements: { @@ -609,7 +632,7 @@ function is_angelleye_braintree_selected() { paymentRequest: { total: { label: '', - amount: 'get_order_total(); ?>' + amount: '' } } }, @@ -701,7 +724,7 @@ function is_angelleye_braintree_selected() {