diff --git a/angelleye-includes/angelleye-utility.php b/angelleye-includes/angelleye-utility.php index 505956718..0ba0dba83 100644 --- a/angelleye-includes/angelleye-utility.php +++ b/angelleye-includes/angelleye-utility.php @@ -297,6 +297,14 @@ public function angelleye_woocommerce_order_actions($order_actions = array()) { case 'braintree' : { $this->total_Order = $order->get_total(); $this->total_DoCapture = self::get_total('DoCapture', 'submitted_for_settlement', $order_id); + if( $this->total_DoCapture == 0 ) { + $this->total_DoCapture = self::get_total('DoCapture', 'settling', $order_id); + } + $this->total_Order = self::get_total('Order', 'Pending', $order_id); + $this->total_DoVoid = self::get_total('DoVoid', '', $order_id); + $this->total_Pending_DoAuthorization = self::get_total('DoAuthorization', 'Pending', $order_id); + $this->total_Completed_DoAuthorization = self::get_total('DoAuthorization', 'Completed', $order_id); + $this->total_DoReauthorization = self::get_total('DoReauthorization', '', $order_id); $paypal_payment_action = array(); $paypal_payment_action = array('DoCapture' => 'Capture'); if ($this->total_DoCapture >= ($order->get_total() - $order->get_total_refunded())) { diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php index 1caea97a0..235f247ba 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php @@ -32,6 +32,7 @@ public function __construct($gateway) { $this->email_notify_order_cancellations = $this->gateway->get_option('email_notify_order_cancellations', 'no'); $this->pending_authorization_order_status = $this->gateway->get_option('pending_authorization_order_status', 'On Hold'); $this->enable_in_context_checkout_flow = $this->gateway->get_option('enable_in_context_checkout_flow', 'yes'); + $this->id = 'paypal_express'; if ($this->testmode == false) { $this->testmode = AngellEYE_Utility::angelleye_paypal_for_woocommerce_is_set_sandbox_product(); } diff --git a/assets/css/braintree-checkout.css b/assets/css/braintree-checkout.css new file mode 100644 index 000000000..94cb180ec --- /dev/null +++ b/assets/css/braintree-checkout.css @@ -0,0 +1,40 @@ +.woocommerce-checkout #payment div.payment_box .wc-credit-card-form div.hosted-field-braintree, .woocommerce #payment div.payment_box .wc-credit-card-form div.hosted-field-braintree { + height:2em;padding:7px;border:1px solid #ccc;border-radius:3px;transition:border-color .16s;-webkit-transition:border-color .16s;background-color:#fff; + border-color: #c7c1c6; + border-top-color: rgb(199, 193, 198); + border-top-color: #bbb3b9; +} +.angelleye-braintree-hidden { + display: none; +} + + + +#modal-angelleye-braintree { + + position: fixed; + top: 0; + left: 0; + bottom: 0; + right: 0; + background: rgba(0,0,0,.7); + z-index: 3000; + cursor: pointer; +} +#modal-angelleye-braintree iframe { + overflow: auto; + margin: auto; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + background: #fff; + padding: 1em; + box-sizing: content-box; + border-radius: 5px; +} + +.woocommerce-checkout #payment div.payment_box #wc-braintree-cc-form.wc-credit-card-form div.form-row, .woocommerce #payment div.payment_box #wc-braintree-cc-form.wc-credit-card-form div.form-row{ + padding: 3px; +} \ No newline at end of file diff --git a/assets/css/checkout.css b/assets/css/checkout.css index a0fcf5a6a..91b3f636a 100644 --- a/assets/css/checkout.css +++ b/assets/css/checkout.css @@ -104,6 +104,10 @@ p.woocommerce-SavedPaymentMethods-saveNew { p.woocommerce-SavedPaymentMethods-saveNew label { vertical-align: middle; } + + + + @media only screen and (min-device-width: 320px) and (max-device-width: 480px) { diff --git a/classes/wc-gateway-braintree-angelleye.php b/classes/wc-gateway-braintree-angelleye.php index 1b10dca58..452a26cef 100644 --- a/classes/wc-gateway-braintree-angelleye.php +++ b/classes/wc-gateway-braintree-angelleye.php @@ -73,6 +73,7 @@ function __construct() { // add_action('woocommerce_admin_order_data_after_order_details', array($this, 'woocommerce_admin_order_data_after_order_details'), 10, 1); add_filter('woocommerce_settings_api_sanitized_fields_' . $this->id, array($this, 'angelleye_update_settings'), 10, 1); do_action('angelleye_paypal_for_woocommerce_multi_account_api_' . $this->id, $this, null, null); + $this->storeInVaultOnSuccess = false; } /** @@ -171,7 +172,7 @@ public function is_available() { } public function validate_fields() { - if (!$this->enable_braintree_drop_in) { + try { if (isset($_POST['wc-braintree-payment-token']) && 'new' !== $_POST['wc-braintree-payment-token']) { $token_id = wc_clean($_POST['wc-braintree-payment-token']); @@ -181,28 +182,13 @@ public function validate_fields() { } else { return true; } - } else { - $card = $this->get_posted_card(); - if (empty($card->exp_month) || empty($card->exp_year)) { - throw new Exception(__('Card expiration date is invalid', 'paypal-for-woocommerce')); - } - if (!ctype_digit($card->cvc)) { - throw new Exception(__('Card security code is invalid (only digits are allowed)', 'paypal-for-woocommerce')); - } - if (!ctype_digit($card->exp_month) || !ctype_digit($card->exp_year) || $card->exp_month > 12 || $card->exp_month < 1 || $card->exp_year < date('y')) { - throw new Exception(__('Card expiration date is invalid', 'paypal-for-woocommerce')); - } - if (empty($card->number) || !ctype_digit($card->number)) { - throw new Exception(__('Card number is invalid', 'paypal-for-woocommerce')); - } - return true; - } + } } catch (Exception $e) { wc_add_notice($e->getMessage(), 'error'); return false; } - return true; - } else { + + try { if (isset($_POST['braintree_token']) && !empty($_POST['braintree_token'])) { return true; @@ -214,7 +200,7 @@ public function validate_fields() { return false; } return true; - } + } /** @@ -471,7 +457,7 @@ public function payment_fields() {
- + id : $order->get_id(); $old_wc = version_compare(WC_VERSION, '3.0', '<'); try { - if ($this->enable_braintree_drop_in) { - $payment_method_nonce = self::get_posted_variable('braintree_token'); - if (empty($payment_method_nonce)) { - $this->add_log("Error: The payment_method_nonce was unexpectedly empty"); - wc_add_notice(__('Error: PayPal Powered by Braintree did not supply a payment nonce. Please try again later or use another means of payment.', 'paypal-for-woocommerce'), 'error'); - return false; - } + if (AngellEYE_Utility::angelleye_is_save_payment_token($this, $order_id)) { + $this->storeInVaultOnSuccess = true; } - $request_data = array(); $this->angelleye_braintree_lib(); - $card = $this->get_posted_card(); $billing_company = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_company : $order->get_billing_company(); $billing_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); @@ -748,24 +934,20 @@ public function angelleye_do_payment($order) { 'postalCode' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_postcode : $order->get_shipping_postcode(), 'countryCodeAlpha2' => version_compare(WC_VERSION, '3.0', '<') ? $order->shipping_country : $order->get_shipping_country(), ); - if ($this->enable_braintree_drop_in == false) { - if ((!empty($_POST['wc-braintree-payment-token']) && $_POST['wc-braintree-payment-token'] == 'new') || empty($_POST['wc-braintree-payment-token'])) { - $billing_first_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_first_name : $order->get_billing_first_name(); - $billing_last_name = version_compare(WC_VERSION, '3.0', '<') ? $order->billing_last_name : $order->get_billing_last_name(); - $request_data['creditCard'] = array( - 'number' => $card->number, - 'expirationDate' => $card->exp_month . '/' . $card->exp_year, - 'cvv' => $card->cvc, - 'cardholderName' => $billing_first_name . ' ' . $billing_last_name - ); - } else if (is_user_logged_in() && (!empty($_POST['wc-braintree-payment-token']) && $_POST['wc-braintree-payment-token'] != 'new')) { + + if (is_user_logged_in() && (!empty($_POST['wc-braintree-payment-token']) && $_POST['wc-braintree-payment-token'] != 'new')) { $customer_id = get_current_user_id(); $token_id = wc_clean($_POST['wc-braintree-payment-token']); $token = WC_Payment_Tokens::get($token_id); $braintree_customer_id = get_user_meta($customer_id, 'braintree_customer_id', true); $request_data['paymentMethodToken'] = $token->get_token(); - } } else { + $payment_method_nonce = self::get_posted_variable('braintree_token'); + if (empty($payment_method_nonce)) { + $this->add_log("Error: The payment_method_nonce was unexpectedly empty"); + wc_add_notice(__('Error: PayPal Powered by Braintree did not supply a payment nonce. Please try again later or use another means of payment.', 'paypal-for-woocommerce'), 'error'); + return false; + } $request_data['paymentMethodNonce'] = $payment_method_nonce; } if (is_user_logged_in()) { @@ -978,7 +1160,7 @@ public function angelleye_do_payment($order) { } public function get_braintree_options() { - return array('submitForSettlement' => true, 'storeInVaultOnSuccess' => (is_user_logged_in() && $this->enable_braintree_drop_in) ? true : false); + return array('submitForSettlement' => true, 'storeInVaultOnSuccess' => ($this->storeInVaultOnSuccess) ? true : false); } public static function multibyte_loaded() { @@ -1311,9 +1493,11 @@ public function payment_scripts() { if ($this->enable_braintree_drop_in) { wp_enqueue_script('braintree-gateway', 'https://js.braintreegateway.com/web/dropin/1.10.0/js/dropin.min.js', array('jquery'), null, false); } else { - - wp_enqueue_script('braintree-gateway-client', 'https://js.braintreegateway.com/web/3.32.1/js/client.min.js', array('jquery'), null, true); - wp_enqueue_script('braintree-data-collector', 'https://js.braintreegateway.com/web/3.32.1/js/data-collector.min.js', array('jquery'), null, true); + 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); + wp_enqueue_script('braintree-data-collector', 'https://js.braintreegateway.com/web/3.35.0/js/data-collector.min.js', array('jquery'), null, true); + wp_enqueue_script('braintree-three-d-secure', 'https://js.braintreegateway.com/web/3.35.0/js/three-d-secure.js', array('jquery'), null, true); + wp_enqueue_script('braintree-gateway-hosted-fields', 'https://js.braintreegateway.com/web/3.35.0/js/hosted-fields.min.js', array('jquery'), null, true); } } @@ -1351,18 +1535,18 @@ public function field_name($name) { public function angelleye_braintree_credit_card_form_fields($default_fields, $current_gateway_id) { if ($current_gateway_id == $this->id) { $fields = array( - 'card-number-field' => '

- - field_name('card-number') . ' /> -

', - 'card-expiry-field' => '

- - field_name('card-expiry') . ' /> -

', - '

- - field_name('card-cvc') . ' style="width:100px" /> -

' + 'card-number-field' => '
+ +
+
', + 'card-expiry-field' => '
+ +
+
', + 'card-cvc-field' => '
+ +
+
' ); return $fields; } else { @@ -1404,6 +1588,11 @@ public function add_payment_method($zero_amount_payment = false) { if ($result->success == true) { $return = $this->braintree_save_payment_method($customer_id, $result, $zero_amount_payment); return $return; + } else { + return array( + 'result' => 'failure', + 'redirect' => '' + ); } } else { $braintree_customer_id = $this->braintree_create_customer($customer_id); @@ -1412,13 +1601,17 @@ public function add_payment_method($zero_amount_payment = false) { if ($result->success == true) { $return = $this->braintree_save_payment_method($customer_id, $result, $zero_amount_payment); return $return; + } else { + return array( + 'result' => 'failure', + 'redirect' => '' + ); } } } } public function braintree_create_payment_method($braintree_customer_id, $zero_amount_payment = false) { - if ($this->enable_braintree_drop_in) { $payment_method_nonce = self::get_posted_variable('braintree_token'); if (!empty($payment_method_nonce)) { $payment_method_request = array('customerId' => $braintree_customer_id, 'paymentMethodNonce' => $payment_method_nonce, 'options' => array('failOnDuplicatePaymentMethod' => true)); @@ -1431,20 +1624,11 @@ public function braintree_create_payment_method($braintree_customer_id, $zero_am wc_add_notice(__('Error: PayPal Powered by Braintree did not supply a payment nonce. Please try again later or use another means of payment.', 'paypal-for-woocommerce'), 'error'); return false; } - } else { - $card = $this->get_posted_card(); - $payment_method_request = array('customerId' => $braintree_customer_id, 'cvv' => $card->cvc, 'expirationDate' => $card->exp_month . '/' . $card->exp_year, 'number' => $card->number); - $this->merchant_account_id = $this->angelleye_braintree_get_merchant_account_id(); - if (isset($this->merchant_account_id) && !empty($this->merchant_account_id)) { - $payment_method_request['options']['verificationMerchantAccountId'] = $this->merchant_account_id; - } - } + try { - if ($this->enable_braintree_drop_in) { + $result = Braintree_PaymentMethod::create($payment_method_request); - } else { - $result = Braintree_CreditCard::create($payment_method_request); - } + return $result; } catch (Braintree_Exception_Authentication $e) { $error = $this->get_braintree_exception_message($e); @@ -1522,14 +1706,24 @@ public function braintree_save_payment_method($customer_id, $result) { $wc_existing_token = $this->get_token_by_token($payment_method_token); if ($wc_existing_token == null) { $token = new WC_Payment_Token_CC(); - - $token->set_token($payment_method_token); - $token->set_gateway_id($this->id); - $token->set_card_type($braintree_method->cardType); - $token->set_last4($braintree_method->last4); - $token->set_expiry_month($braintree_method->expirationMonth); - $token->set_expiry_year($braintree_method->expirationYear); - $token->set_user_id($customer_id); + if (!empty($braintree_method->cardType) && !empty($braintree_method->last4)) { + $token->set_token($payment_method_token); + $token->set_gateway_id($this->id); + $token->set_card_type($braintree_method->cardType); + $token->set_last4($braintree_method->last4); + $token->set_expiry_month($braintree_method->expirationMonth); + $token->set_expiry_year($braintree_method->expirationYear); + $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_gateway_id($this->id); + $token->set_card_type('PayPal Billing Agreement'); + $token->set_last4(substr($braintree_method->billingAgreementId, -4)); + $token->set_expiry_month(date('m')); + $token->set_expiry_year(date('Y', strtotime('+20 year'))); + $token->set_user_id($customer_id); + } if ($token->validate()) { $save_result = $token->save(); if ($save_result) { @@ -2058,6 +2252,32 @@ public function generate_merchant_account_id_html($currency_code = null, $value return trim(preg_replace("/[\n\r\t]/", '', ob_get_clean())); } + public function get_braintree_exception_message($e) { + switch ( get_class( $e ) ) { + case 'Braintree\Exception\Authentication': + $message = __( 'Invalid Credentials, please double-check your API credentials (Merchant ID, Public Key, Private Key, and Merchant Account ID) and try again.', 'paypal-for-woocommerce' ); + break; + case 'Braintree\Exception\Authorization': + $message = __( 'Authorization Failed, please verify the user for the API credentials provided can perform transactions and that the request data is correct.', 'paypal-for-woocommerce' ); + break; + case 'Braintree\Exception\DownForMaintenance': + $message = __( 'Braintree is currently down for maintenance, please try again later.', 'paypal-for-woocommerce' ); + break; + case 'Braintree\Exception\NotFound': + $message = __( 'The record cannot be found, please contact support.', 'paypal-for-woocommerce' ); + break; + case 'Braintree\Exception\ServerError': + $message = __( 'Braintree encountered an error when processing your request, please try again later or contact support.', 'paypal-for-woocommerce' ); + break; + case 'Braintree\Exception\SSLCertificate': + $message = __( 'Braintree cannot verify your server\'s SSL certificate. Please contact your hosting provider or try again later.', 'paypal-for-woocommerce' ); + break; + default: + $message = $e->getMessage(); + } + return $message; + } + public function angelleye_save_payment_auth($order) { $success = true; $this->validate_fields(); @@ -2065,10 +2285,12 @@ public function angelleye_save_payment_auth($order) { $customer_id = get_current_user_id(); $braintree_customer_id = get_user_meta($customer_id, 'braintree_customer_id', true); if (!empty($braintree_customer_id)) { - $result = $this->braintree_create_payment_method_auth($braintree_customer_id); + $result = $this->braintree_create_payment_method_auth($braintree_customer_id, $order); if (!empty($result) && $result != false && $result->success == true) { $return = $this->braintree_save_payment_method_auth($customer_id, $result, $order); return $return; + } else if (!empty ($result) && $result == true) { + return true; } else { $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); $this->angelleye_store_card_info($result, $order_id); @@ -2077,7 +2299,7 @@ public function angelleye_save_payment_auth($order) { } else { $braintree_customer_id = $this->braintree_create_customer_auth($customer_id); if (!empty($braintree_customer_id)) { - $result = $this->braintree_create_payment_method_auth($braintree_customer_id); + $result = $this->braintree_create_payment_method_auth($braintree_customer_id, $order); if (!empty($result) && $result != false && $result->success == true) { $return = $this->braintree_save_payment_method_auth($customer_id, $result, $order); return $return; @@ -2115,30 +2337,42 @@ public function braintree_create_customer_auth($customer_id) { } } - public function braintree_create_payment_method_auth($braintree_customer_id) { - if ($this->enable_braintree_drop_in) { + public function braintree_create_payment_method_auth($braintree_customer_id, $order) { + if (is_user_logged_in() && (!empty($_POST['wc-braintree-payment-token']) && $_POST['wc-braintree-payment-token'] != 'new')) { + $customer_id = get_current_user_id(); + $token_id = wc_clean($_POST['wc-braintree-payment-token']); + $token = WC_Payment_Tokens::get($token_id); + $braintree_customer_id = get_user_meta($customer_id, 'braintree_customer_id', true); + $payment_method_nonce = $token->get_token(); + $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); + update_post_meta($order_id, '_first_transaction_id', $payment_method_nonce); + $payment_order_meta = array('_transaction_id' => $payment_method_token, '_payment_action' => $this->payment_action); + AngellEYE_Utility::angelleye_add_order_meta($order_id, $payment_order_meta); + $order->update_status('on-hold', __('Authorization only transaction', 'paypal-for-woocommerce')); + $this->save_payment_token($order, $payment_method_token); + return true; + } else { $payment_method_nonce = self::get_posted_variable('braintree_token'); - if (!empty($payment_method_nonce)) { - $payment_method_request = array('customerId' => $braintree_customer_id, 'paymentMethodNonce' => $payment_method_nonce); - $this->merchant_account_id = $this->angelleye_braintree_get_merchant_account_id(); - $payment_method_request['options']['verifyCard'] = true; - if (isset($this->merchant_account_id) && !empty($this->merchant_account_id)) { - $payment_method_request['options']['verificationMerchantAccountId'] = $this->merchant_account_id; - } - } else { + if (empty($payment_method_nonce)) { $this->add_log("Error: The payment_method_nonce was unexpectedly empty"); wc_add_notice(__('Error: PayPal Powered by Braintree did not supply a payment nonce. Please try again later or use another means of payment.', 'paypal-for-woocommerce'), 'error'); return false; } - } else { - $card = $this->get_posted_card(); - $payment_method_request = array('customerId' => $braintree_customer_id, 'cvv' => $card->cvc, 'expirationDate' => $card->exp_month . '/' . $card->exp_year, 'number' => $card->number); + + } + if (!empty($payment_method_nonce)) { + $payment_method_request = array('customerId' => $braintree_customer_id, 'paymentMethodNonce' => $payment_method_nonce); $this->merchant_account_id = $this->angelleye_braintree_get_merchant_account_id(); $payment_method_request['options']['verifyCard'] = true; if (isset($this->merchant_account_id) && !empty($this->merchant_account_id)) { $payment_method_request['options']['verificationMerchantAccountId'] = $this->merchant_account_id; } + } else { + $this->add_log("Error: The payment_method_nonce was unexpectedly empty"); + wc_add_notice(__('Error: PayPal Powered by Braintree did not supply a payment nonce. Please try again later or use another means of payment.', 'paypal-for-woocommerce'), 'error'); + return false; } + try { if ($this->enable_braintree_drop_in) { $result = Braintree_PaymentMethod::create($payment_method_request); @@ -2184,6 +2418,67 @@ public function braintree_save_payment_method_auth($customer_id, $result, $order } update_user_meta($customer_id, 'braintree_customer_id', $braintree_method->customerId); $payment_method_token = $braintree_method->token; + do_action('before_save_payment_token', $order_id); + if (AngellEYE_Utility::angelleye_is_save_payment_token($this, $order_id)) { + try { + if (0 != $order->get_user_id()) { + $customer_id = $order->get_user_id(); + } else { + $customer_id = get_current_user_id(); + } + $wc_existing_token = $this->get_token_by_token($payment_method_token); + $paymentMethod = Braintree_PaymentMethod::find($payment_method_token); + if ($wc_existing_token == null) { + if (!empty($braintree_method->cardType) && !empty($braintree_method->last4)) { + $token = new WC_Payment_Token_CC(); + $token->set_token($payment_method_token); + $token->set_gateway_id($this->id); + $token->set_card_type($braintree_method->cardType); + $token->set_last4($braintree_method->last4); + $token->set_expiry_month($braintree_method->expirationMonth); + $token->set_expiry_year($braintree_method->expirationYear); + $token->set_user_id($customer_id); + if ($token->validate()) { + $save_result = $token->save(); + if ($save_result) { + $order->add_payment_token($token); + } + } else { + $order->add_order_note('ERROR MESSAGE: ' . __('Invalid or missing payment token fields.', 'paypal-for-woocommerce')); + } + } else { + if (!empty($braintree_method->billingAgreementId)) { + $token = new WC_Payment_Token_CC(); + $customer_id = get_current_user_id(); + $token->set_token($braintree_method->billingAgreementId); + $token->set_gateway_id($this->id); + $token->set_card_type('PayPal Billing Agreement'); + $token->set_last4(substr($braintree_method->billingAgreementId, -4)); + $token->set_expiry_month(date('m')); + $token->set_expiry_year(date('Y', strtotime('+20 year'))); + $token->set_user_id($customer_id); + if ($token->validate()) { + $save_result = $token->save(); + if ($save_result) { + $order->add_payment_token($token); + } + } else { + $order->add_order_note('ERROR MESSAGE: ' . __('Invalid or missing payment token fields.', 'paypal-for-woocommerce')); + } + } + } + } else { + $order->add_payment_token($wc_existing_token); + } + + } catch (Braintree_Exception_NotFound $e) { + $this->add_log("Braintree_Transaction::find Braintree_Exception_NotFound: " . $e->getMessage()); + return new WP_Error(404, $e->getMessage()); + } catch (Exception $ex) { + $this->add_log("Braintree_Transaction::find Exception: " . $ex->getMessage()); + return new WP_Error(404, $ex->getMessage()); + } + } if( !empty($payment_method_token) ) { update_post_meta($order_id, '_first_transaction_id', $payment_method_token); $payment_order_meta = array('_transaction_id' => $payment_method_token, '_payment_action' => $this->payment_action); @@ -2247,31 +2542,4 @@ public function pfw_braintree_do_capture($request_data = array(), $order) { return $this->response; } - - public function get_braintree_exception_message($e) { - switch ( get_class( $e ) ) { - case 'Braintree\Exception\Authentication': - $message = __( 'Failure - Invalid Credentials - The payment gateway is not configured properly.', 'paypal-for-woocommerce' ); - break; - case 'Braintree\Exception\Authorization': - $message = __( 'Authorization Failure - The seller account is not setup to process Authorization transactions.', 'paypal-for-woocommerce' ); - break; - case 'Braintree\Exception\DownForMaintenance': - $message = __( 'Braintree is currently down for maintenance, please try again later.', 'paypal-for-woocommerce' ); - break; - case 'Braintree\Exception\NotFound': - $message = __( 'The record cannot be found, please contact support.', 'paypal-for-woocommerce' ); - break; - case 'Braintree\Exception\ServerError': - $message = __( 'Braintree encountered an error when processing your request, please try again later or contact support.', 'paypal-for-woocommerce' ); - break; - case 'Braintree\Exception\SSLCertificate': - $message = __( 'Braintree cannot verify your server\'s SSL certificate. Please contact your hosting provider or try again later.', 'paypal-for-woocommerce' ); - break; - default: - $message = $e->getMessage(); - } - return $message; - } - }