Skip to content

Commit

Permalink
delete card automatically when card remove in braintree account, PFW-507
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Oct 24, 2019
1 parent 686a7d1 commit 88e638d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions classes/wc-gateway-braintree-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
39 changes: 39 additions & 0 deletions paypal-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

0 comments on commit 88e638d

Please sign in to comment.