Skip to content

Commit

Permalink
Resolved the braintree function not found fatal error on payment meth…
Browse files Browse the repository at this point in the history
…ods page and cartflows checkout, PFW-602
  • Loading branch information
deepakmaurya committed Apr 30, 2020
1 parent 60a3d72 commit f9bbb8e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 32 additions & 9 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -513,7 +527,16 @@ public function payment_fields() {
var is_registration_required = "<?php echo WC()->checkout()->is_registration_required(); ?>";
var is_logged_in = "<?php echo is_user_logged_in(); ?>";
</script>
<?php
<?php
$order_total = $this->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) {
?>
<div id="braintree-cc-form" class="wc-payment-form">
Expand Down Expand Up @@ -581,7 +604,7 @@ function is_angelleye_braintree_selected() {
container: "#braintree-payment-form",
<?php if($this->threed_secure_enabled === true) { ?>
threeDSecure: {
amount: '<?php echo $this->get_order_total(); ?>',
amount: <?php echo $order_total; ?>,
},
<?php } ?>
locale: '<?php echo AngellEYE_Utility::get_button_locale_code(); ?>',
Expand All @@ -595,7 +618,7 @@ function is_angelleye_braintree_selected() {
<?php } ?>
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPrice: '<?php echo $this->get_order_total(); ?>',
totalPrice: '<?php echo $order_total; ?>',
currencyCode: '<?php echo get_woocommerce_currency(); ?>'
},
cardRequirements: {
Expand All @@ -609,7 +632,7 @@ function is_angelleye_braintree_selected() {
paymentRequest: {
total: {
label: '<?php echo __('My Store', 'paypal-for-woocommerce'); ?>',
amount: '<?php echo $this->get_order_total(); ?>'
amount: '<?php echo $order_total; ?>'
}
}
},
Expand Down Expand Up @@ -701,7 +724,7 @@ function is_angelleye_braintree_selected() {
</div>
<?php
if (is_checkout() || is_ajax() || is_checkout_pay_page() || is_add_payment_method_page()) {

?>
<script type="text/javascript">
var angelleye_dropinInstance;
Expand Down Expand Up @@ -933,7 +956,7 @@ class:'input-text wc-credit-card-form-card-number'
}
<?php if($this->threed_secure_enabled === true) { ?>
components.threeDSecure.verifyCard({
amount: '<?php echo $this->get_order_total(); ?>',
amount: <?php echo $order_total ?>,
nonce: payload.nonce,
addFrame: addFrame,
removeFrame: removeFrame
Expand Down
55 changes: 28 additions & 27 deletions paypal-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,20 +1286,21 @@ public static function angelleye_delete_payment_method_action() {
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();
$gateways['braintree']->angelleye_braintree_lib();
$token_value = $token->get_token();
Braintree_PaymentMethod::delete($token_value);
} catch (Braintree_Exception_NotFound $e) {

$gateways['braintree']->braintree_gateway->paymentMethod()->delete($token_value);
} catch (\Braintree\Exception\NotFound $e) {
$gateways['braintree']->add_log("Braintree_PaymentMethod::delete Braintree_Exception_NotFound: " . $e->getMessage());
} catch (Braintree_Exception_Authentication $e) {
} 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) {
} 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) {
} catch (\Braintree\Exception\ServiceUnavailable $e) {
$gateways['braintree']->add_log("Braintree_Exception_ServiceUnavailable: Request times out.");
} catch (\Braintree\Exception\ServerError $e) {
$gateways['braintree']->add_log("Braintree_Exception_ServerError" . $e->getMessage());
} catch (Braintree_Exception_SSLCertificate $e) {
} catch (\Braintree\Exception\SSLCertificate $e) {
$gateways['braintree']->add_log("Braintree_Exception_SSLCertificate" . $e->getMessage());
} catch (Exception $ex) {
$gateways['braintree']->add_log("Exception" . $ex->getMessage());
Expand All @@ -1318,24 +1319,24 @@ public function angelleye_synce_braintree_save_payment_methods($list, $customer_
$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());
}
try {
$gateways['braintree']->braintree_gateway->paymentMethod()->find($token_value);
} catch (\Braintree\Exception\NotFound $e) {
$gateways['braintree']->add_log("Braintree_PaymentMethod::find 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\ServiceUnavailable $e) {
$gateways['braintree']->add_log("Braintree_Exception_ServiceUnavailable: 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());
}
}
}

Expand Down

0 comments on commit f9bbb8e

Please sign in to comment.