From f1b64d8195fca87c2894fb19f513daa408574d02 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Fri, 6 Jul 2018 15:40:25 +0530 Subject: [PATCH 1/4] Ability to hide individual credit card logo icons in Smart Buttons, PFW-179 --- ...ateway-paypal-express-helper-angelleye.php | 4 ++++ assets/js/angelleye-admin.js | 9 ++++++++ .../wc-gateway-paypal-express-angelleye.php | 23 ++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php index 883332888..b2fbc9ee2 100644 --- a/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php +++ b/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-helper-angelleye.php @@ -41,6 +41,10 @@ public function __construct($version) { $this->testmode = 'yes' === $this->testmode_value; $this->billing_address_value = !empty($this->setting['billing_address']) ? $this->setting['billing_address'] : 'no'; $this->disallowed_funding_methods = !empty($this->setting['disallowed_funding_methods']) ? $this->setting['disallowed_funding_methods'] : array(); + if(!in_array('card', $this->disallowed_funding_methods)) { + $this->disallowed_card_types = !empty($this->setting['disallowed_card_types']) ? $this->setting['disallowed_card_types'] : array(); + $this->disallowed_funding_methods = array_merge($this->disallowed_card_types, $this->disallowed_funding_methods); + } $this->button_size = !empty($this->setting['button_size']) ? $this->setting['button_size'] : 'small'; $this->button_color = !empty($this->setting['button_color']) ? $this->setting['button_color'] : 'gold'; $this->button_shape = !empty($this->setting['button_shape']) ? $this->setting['button_shape'] : 'pill'; diff --git a/assets/js/angelleye-admin.js b/assets/js/angelleye-admin.js index b5d92a1a9..46f472456 100644 --- a/assets/js/angelleye-admin.js +++ b/assets/js/angelleye-admin.js @@ -373,6 +373,15 @@ jQuery(document).ready(function ($) { if (angelleye_admin.shop_based_us == "no") { angelleye_woocommerce_paypal_express_disallowed_funding_methods.push("credit"); } + if(jQuery.inArray('card', angelleye_woocommerce_paypal_express_allowed_funding_methods) > -1 === true) { + var woocommerce_paypal_express_disallowed_card_types = jQuery('#woocommerce_paypal_express_disallowed_card_types').val(); + if (woocommerce_paypal_express_disallowed_card_types === null) { + woocommerce_paypal_express_disallowed_card_types = []; + } + jQuery.grep(woocommerce_paypal_express_disallowed_card_types, function (value) { + angelleye_woocommerce_paypal_express_disallowed_funding_methods.push(value); + }); + } window.paypalCheckoutReady = function () { paypal.Button.render({ env: 'sandbox', diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index 9e184a10d..6d5ed1d37 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -66,6 +66,14 @@ public function __construct() { 'paypal' => __('PayPal', 'paypal-for-woocommerce') ); } + $this->disallowed_card_types = array( + 'visa' => esc_html_x( 'Visa', 'credit card type', 'paypal-for-woocommerce' ), + 'mastercard' => esc_html_x( 'MasterCard', 'credit card type', 'paypal-for-woocommerce' ), + 'amex' => esc_html_x( 'American Express', 'credit card type', 'paypal-for-woocommerce' ), + 'discover' => esc_html_x( 'Discover', 'credit card type', 'paypal-for-woocommerce' ), + 'maestro' => esc_html_x( 'Maestro', 'credit card type', 'paypal-for-woocommerce' ), + 'jcb' => esc_html_x( 'JCB', 'credit card type', 'paypal-for-woocommerce' ), + ); $this->init_form_fields(); $this->init_settings(); $this->enable_tokenized_payments = $this->get_option('enable_tokenized_payments', 'no'); @@ -399,7 +407,11 @@ function is_funding_icon_should_show_php() { } else { jQuery('#woocommerce_paypal_express_button_label option[value="credit"]').remove(); } - + if( jQuery.inArray('card', jQuery('#woocommerce_paypal_express_disallowed_funding_methods').val()) ) { + jQuery("#woocommerce_paypal_express_disallowed_card_types").closest('tr').show(); + } else { + jQuery("#woocommerce_paypal_express_disallowed_card_types").closest('tr').hide(); + } if( is_funding_icon_should_show_php() === false) { jQuery("#woocommerce_paypal_express_button_fundingicons").closest('tr').hide(); jQuery("#woocommerce_paypal_express_button_fundingicons").val("false"); @@ -1023,6 +1035,15 @@ public function init_form_fields() { 'desc_tip' => true, 'options' => $this->disallowed_funding_methods_array, ), + 'disallowed_card_types' => array( + 'title' => __('Hide Card Type(s)', 'paypal-for-woocommerce'), + 'type' => 'multiselect', + 'class' => 'wc-enhanced-select in_context_checkout_part', + 'description' => __('Card Type(s) selected here will be hidden from buyers during checkout.', 'paypal-for-woocommerce'), + 'default' => 'medium', + 'desc_tip' => true, + 'options' => $this->disallowed_card_types, + ), 'button_layout' => array( 'title' => __('Button Layout', 'paypal-for-woocommerce'), 'type' => 'select', From 54a2309c85304a48b237d85fd0c7bdbc8ffbcf27 Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Fri, 6 Jul 2018 15:46:17 +0530 Subject: [PATCH 2/4] update min js file, PFW-179 --- assets/js/angelleye-in-context-checkout.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 assets/js/angelleye-in-context-checkout.min.js diff --git a/assets/js/angelleye-in-context-checkout.min.js b/assets/js/angelleye-in-context-checkout.min.js new file mode 100644 index 000000000..a5a65af25 --- /dev/null +++ b/assets/js/angelleye-in-context-checkout.min.js @@ -0,0 +1 @@ +jQuery(function(e){if("undefined"==typeof angelleye_in_content_param)return!1;function n(){var n=angelleye_in_content_param.disallowed_funding_methods;return null===n&&(n=[]),!(e.inArray("card",n)>-1)}function t(){window.paypalCheckoutReady=function(){var t,a=[],o=[];"yes"==angelleye_in_content_param.is_cart&&("both"==angelleye_in_content_param.cart_button_possition?a.push(".angelleye_smart_button_top",".angelleye_smart_button_bottom"):"bottom"==angelleye_in_content_param.cart_button_possition?a.push(".angelleye_smart_button_bottom"):"top"==angelleye_in_content_param.cart_button_possition&&a.push(".angelleye_smart_button_top")),"yes"==angelleye_in_content_param.is_checkout&&"yes"==angelleye_in_content_param.is_display_on_checkout&&a.push(".angelleye_smart_button_checkout_top"),a.push(".angelleye_smart_button_mini"),o=e.parseJSON(angelleye_in_content_param.disallowed_funding_methods),t=e.parseJSON(angelleye_in_content_param.allowed_funding_methods),"no"==angelleye_in_content_param.is_paypal_credit_enable&&o.push("credit"),angelleye_cart_style_object={size:angelleye_in_content_param.button_size,color:angelleye_in_content_param.button_color,shape:angelleye_in_content_param.button_shape,label:angelleye_in_content_param.button_label,layout:angelleye_in_content_param.button_layout,tagline:"true"===angelleye_in_content_param.button_tagline},a.forEach(function(a){e(a).html(""),o=e.grep(o,function(e){return"venmo"!==e}),a.length>0&&e(a).length>0&&(".angelleye_smart_button_mini"==a&&(angelleye_cart_style_object.size="responsive"),"horizontal"===angelleye_in_content_param.button_layout&&!0===n()&&"credit"!==angelleye_in_content_param.button_label&&"true"===angelleye_in_content_param.button_fundingicons&&(angelleye_cart_style_object.fundingicons="true"===angelleye_in_content_param.button_fundingicons),paypal.Button.render({env:angelleye_in_content_param.environment,style:angelleye_cart_style_object,locale:angelleye_in_content_param.locale,funding:{allowed:t,disallowed:o},payment:function(){e(".woocommerce").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});return paypal.request.post(angelleye_in_content_param.set_express_checkout,{request_from:"JSv4"}).then(function(e){return e.token})},onAuthorize:function(e,n){var t={paymentToken:e.paymentToken,payerID:e.payerID,token:e.paymentToken,request_from:"JSv4"};paypal.request.post(e.returnUrl,t).then(function(t){e.returnUrl=t.url,n.redirect()})},onCancel:function(n,t){return e(".woocommerce").unblock(),t.redirect()},onClick:function(){"yes"===angelleye_in_content_param.enable_google_analytics_click&&"undefined"!=typeof ga&&e.isFunction(ga)&&ga("send",{hitType:"event",eventCategory:"Checkout",eventAction:"paypal_button_click"})},onError:function(n,t){e(".woocommerce").unblock(),window.location.href=angelleye_in_content_param.cancel_page}},a))})}}t(),e(".angelleye_button_single").length>0&&(window.paypalCheckoutReady=function(){allowed_funding_methods_single_array=e.parseJSON(angelleye_in_content_param.allowed_funding_methods),disallowed_funding_methods_single_array=e.parseJSON(angelleye_in_content_param.disallowed_funding_methods),"no"==angelleye_in_content_param.is_paypal_credit_enable&&disallowed_funding_methods_single_array.push("credit"),angelleye_cart_style_object={size:angelleye_in_content_param.button_size,color:angelleye_in_content_param.button_color,shape:angelleye_in_content_param.button_shape,label:angelleye_in_content_param.button_label,layout:angelleye_in_content_param.button_layout,tagline:"true"===angelleye_in_content_param.button_tagline},"horizontal"===angelleye_in_content_param.button_layout&&!0===n()&&"credit"!==angelleye_in_content_param.button_label&&"true"===angelleye_in_content_param.button_fundingicons&&(angelleye_cart_style_object.fundingicons="true"===angelleye_in_content_param.button_fundingicons),paypal.Button.render({env:angelleye_in_content_param.environment,style:angelleye_cart_style_object,locale:angelleye_in_content_param.locale,funding:{allowed:allowed_funding_methods_single_array,disallowed:disallowed_funding_methods_single_array},payment:function(n,t){e(".cart").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var a,o,_,l={nonce:angelleye_in_content_param.generate_cart_nonce,qty:e(".quantity .qty").val(),attributes:e(".variations_form").length?JSON.stringify((a={},o=0,_=0,e(".variations_form").find(".variations select").each(function(){var n=e(this).data("attribute_name")||e(this).attr("name"),t=e(this).val()||"";t.length>0&&_++,o++,a[n]=t}),{count:o,chosenCount:_,data:a}).data):[],"wc-paypal_express-new-payment-method":e("#wc-paypal_express-new-payment-method").is(":checked"),is_cc:"",product_id:e("input[name=add-to-cart]").val(),variation_id:e("input[name=variation_id]").val(),request_from:"JSv4",express_checkout:"true"};return paypal.request.post(angelleye_in_content_param.add_to_cart_ajaxurl,l).then(function(e){return paypal.request.post(e.url,{request_from:"JSv4"}).then(function(e){return e.token})})},onAuthorize:function(e,n){var t={paymentToken:e.paymentToken,payerID:e.payerID,token:e.paymentToken,request_from:"JSv4"};paypal.request.post(e.returnUrl,t).then(function(t){e.returnUrl=t.url,n.redirect()})},onCancel:function(n,t){return e(".cart").unblock(),t.redirect()},onClick:function(){"yes"===angelleye_in_content_param.enable_google_analytics_click&&"undefined"!=typeof ga&&e.isFunction(ga)&&ga("send",{hitType:"event",eventCategory:"Checkout",eventAction:"button_click"})},onError:function(n,t){e(".cart").unblock(),e(".angelleye_button_single").length&&(window.location.href=angelleye_in_content_param.cancel_page)}},".angelleye_button_single")}),e(document.body).on("updated_shipping_method wc_fragments_refreshed wc_fragments_loaded",function(e){t()})}); \ No newline at end of file From 53544009c32bd5214039635e30bfe0823ab57970 Mon Sep 17 00:00:00 2001 From: angelleye Date: Fri, 6 Jul 2018 16:46:44 -0500 Subject: [PATCH 3/4] Updates changelog, ref PFW-179 --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 8c1460120..c25a18338 100644 --- a/readme.txt +++ b/readme.txt @@ -128,6 +128,7 @@ Automatic updates should work great for you. As always, though, we recommend ba == Changelog == = 1.4.12 - xx.xx.2018 = +* Feature - Adds ability to hide individual credit card types from Express Checkout Smart Payment Buttons. ([PFW-179](https://github.com/angelleye/paypal-woocommerce/pull/1159)) * Fix - Resolves an issue where Smart Buttons would not display on Checkout page when Page Setup options were changed from default. ([PFW-147](https://github.com/angelleye/paypal-woocommerce/pull/1151)) * Fix - Resolves some PHP notices. ([PFW-135](https://github.com/angelleye/paypal-woocommerce/pull/1152)) * Fix - Adjusts the check for SSL to coincide with changes made in recent updates to WooCommerce. ([PFW-168](https://github.com/angelleye/paypal-woocommerce/pull/1155)) From 6a4340be526a79234aa0927e5adc0469242a530f Mon Sep 17 00:00:00 2001 From: angelleye Date: Fri, 6 Jul 2018 16:48:18 -0500 Subject: [PATCH 4/4] Updates verbiage, ref PFW-179 --- classes/wc-gateway-paypal-express-angelleye.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index 6d5ed1d37..bbd21ff47 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -1039,7 +1039,7 @@ public function init_form_fields() { 'title' => __('Hide Card Type(s)', 'paypal-for-woocommerce'), 'type' => 'multiselect', 'class' => 'wc-enhanced-select in_context_checkout_part', - 'description' => __('Card Type(s) selected here will be hidden from buyers during checkout.', 'paypal-for-woocommerce'), + 'description' => __('Individual credit card type(s) selected here will be hidden from buyers during checkout.', 'paypal-for-woocommerce'), 'default' => 'medium', 'desc_tip' => true, 'options' => $this->disallowed_card_types,