From 2c1194da9a73fd5859515cd64b2d665b2705503b Mon Sep 17 00:00:00 2001 From: kcppdevelopers Date: Tue, 20 Feb 2018 18:13:35 +0530 Subject: [PATCH] Express Checkout - JSv4, ref #997 --- ...ateway-paypal-express-helper-angelleye.php | 26 +++++- assets/js/angelleye-in-context-checkout.js | 36 ++++---- .../wc-gateway-paypal-express-angelleye.php | 87 +++++++++++++++++-- 3 files changed, 122 insertions(+), 27 deletions(-) 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 2ec7bd2b1..b111accc9 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 @@ -40,6 +40,15 @@ public function __construct($version) { $this->testmode_value = !empty($this->setting['testmode']) ? $this->setting['testmode'] : 'yes'; $this->testmode = 'yes' === $this->testmode_value; $this->billing_address_value = !empty($this->setting['billing_address']) ? $this->setting['billing_address'] : 'no'; + $this->allowed_funding_methods = !empty($this->setting['allowed_funding_methods']) ? $this->setting['allowed_funding_methods'] : array( + 'credit', 'card', 'elv' + ); + $this->button_size = !empty($this->setting['button_size']) ? $this->setting['button_size'] : 'medium'; + $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'; + $this->button_label = !empty($this->setting['button_label']) ? $this->setting['button_label'] : 'checkout'; + $this->button_tagline = !empty($this->setting['button_tagline']) ? $this->setting['button_tagline'] : 'false'; + $this->button_layout = !empty($this->setting['button_layout']) ? $this->setting['button_layout'] : 'horizontal'; $this->billing_address = 'yes' === $this->billing_address_value; $this->cancel_page = !empty($this->setting['cancel_page']) ? $this->setting['cancel_page'] : ''; $this->use_wp_locale_code = !empty($this->setting['use_wp_locale_code']) ? $this->setting['use_wp_locale_code'] : 'yes'; @@ -447,9 +456,15 @@ public function ec_enqueue_scripts_product_page() { if(is_product() == false && 0 >= WC()->cart->total ) { return false; } + if($this->button_layout == 'vertical') { + $this->button_label = ''; + $this->button_tagline = ''; + if( $this->button_size == 'small' ) { + $this->button_size = 'medium'; + } + } $js_value = array('is_page_name' => '', 'enable_in_context_checkout_flow' => ( $this->enable_in_context_checkout_flow == 'yes' ? 'yes' : 'no')); if ($this->angelleye_is_in_context_enable() == true && ( is_checkout() || is_product() || is_cart())) { - wp_enqueue_script('angelleye-in-context-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true); wp_enqueue_script('angelleye-in-context-checkout-js-frontend', PAYPAL_FOR_WOOCOMMERCE_ASSET_URL . 'assets/js/angelleye-in-context-checkout.js', array('jquery'), $this->version, true); wp_localize_script('angelleye-in-context-checkout-js-frontend', 'angelleye_in_content_param', array( @@ -466,8 +481,15 @@ public function ec_enqueue_scripts_product_page() { 'is_cart' => is_cart() ? "yes" : "no", 'is_checkout' => is_checkout() ? "yes" : "no", 'cart_button_possition' => $this->button_position, + 'button_size' => $this->button_size, + 'button_color' => $this->button_color, + 'button_shape' => $this->button_shape, + 'button_label' => $this->button_label, + 'button_tagline' => $this->button_tagline, + 'button_layout' => $this->button_layout, + 'allowed_funding_methods' => json_encode($this->allowed_funding_methods), 'set_express_checkout' => add_query_arg('pp_action', 'set_express_checkout', add_query_arg('wc-api', 'WC_Gateway_PayPal_Express_AngellEYE', home_url('/'))) - ) + ) ); } diff --git a/assets/js/angelleye-in-context-checkout.js b/assets/js/angelleye-in-context-checkout.js index 735c60413..ac66ef889 100644 --- a/assets/js/angelleye-in-context-checkout.js +++ b/assets/js/angelleye-in-context-checkout.js @@ -14,21 +14,22 @@ } else if(angelleye_in_content_param.is_checkout == 'yes') { angelleye_button_selector.push(".angelleye_smart_button_checkout_top"); } - angelleye_button_selector.forEach(function (selector) { paypal.Button.render({ - env: 'sandbox', + env: angelleye_in_content_param.environment, style: { - size: 'medium', - layout: 'vertical', - shape: 'rect', - tagline: false + 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: angelleye_in_content_param.button_tagline }, funding: { - allowed: [paypal.FUNDING.CREDIT] + allowed: JSON.parse(angelleye_in_content_param.allowed_funding_methods) }, client: { - sandbox: 'testoneusa_api1.gmail.com' + sandbox: angelleye_in_content_param.payer_id }, payment: function () { $(selector).block({ @@ -60,7 +61,6 @@ return actions.redirect(); } }, selector ); - }); }; } else { @@ -73,11 +73,9 @@ select.each(function () { var attribute_name = $(this).data('attribute_name') || $(this).attr('name'); var value = $(this).val() || ''; - if (value.length > 0) { chosen++; } - count++; data[ attribute_name ] = value; }); @@ -88,17 +86,20 @@ }; }; paypal.Button.render({ - env: 'sandbox', + env: angelleye_in_content_param.environment, style: { - size: 'medium', - shape: 'rect', - tagline: false + 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: angelleye_in_content_param.button_tagline }, funding: { - allowed: [paypal.FUNDING.CREDIT] + allowed: JSON.parse(angelleye_in_content_param.allowed_funding_methods) }, client: { - sandbox: 'testoneusa_api1.gmail.com' + sandbox: angelleye_in_content_param.payer_id }, payment: function (data, actions) { console.log(data); @@ -138,6 +139,7 @@ return actions.redirect(); }, onError: function (err) { + alert(err); return actions.redirect(); } }, '.angelleye_button_single'); diff --git a/classes/wc-gateway-paypal-express-angelleye.php b/classes/wc-gateway-paypal-express-angelleye.php index e589df76b..e805634b0 100644 --- a/classes/wc-gateway-paypal-express-angelleye.php +++ b/classes/wc-gateway-paypal-express-angelleye.php @@ -227,14 +227,32 @@ function display_notice_and_disable_marketing_solution() { var in_context_checkout_part_tr = jQuery(".in_context_checkout_part").closest('tr'); var in_context_checkout_part = jQuery(".in_context_checkout_part"); if (jQuery(this).is(':checked') === false) { + jQuery('#woocommerce_paypal_express_show_paypal_credit').closest('tr').show(); in_context_checkout_part_tr.hide(); in_context_checkout_part.hide(); } else { + jQuery('#woocommerce_paypal_express_show_paypal_credit').closest('tr').hide(); in_context_checkout_part_tr.show(); in_context_checkout_part.show(); } }).change(); + jQuery("#woocommerce_paypal_express_button_layout").change(function () { + var angelleye_button_label = jQuery("#woocommerce_paypal_express_button_label").closest('tr'); + var angelleye_button_tagline = jQuery("#woocommerce_paypal_express_button_tagline").closest('tr'); + if ( this.value === 'vertical' ) { + jQuery('#woocommerce_paypal_express_button_size option[value="small"]').remove(); + angelleye_button_label.hide(); + angelleye_button_tagline.hide(); + } else { + if( jQuery("#woocommerce_paypal_express_button_size option[value='small']").length == 0) { + jQuery('#woocommerce_paypal_express_button_size').append(jQuery("").attr("value","small").text("Small")); + } + angelleye_button_label.show(); + angelleye_button_tagline.show(); + } + }).change(); + jQuery('.view-paypal-insight-result').on('click', function (event) { event.preventDefault(); @@ -811,12 +829,37 @@ public function init_form_fields() { 'class' => 'in_context_checkout_part', 'description' => '
Customize your PayPal button with colors, sizes, shapes, layout and funding sources.
', ), + 'allowed_funding_methods' => array( + 'title' => __('Show the specified funding method', 'paypal-for-woocommerce'), + 'type' => 'multiselect', + 'class' => 'wc-enhanced-select in_context_checkout_part', + 'description' => __('Multiple funding sources (CREDIT | CARD | ELV).', 'paypal-for-woocommerce'), + 'default' => 'medium', + 'desc_tip' => true, + 'options' => array( + 'credit' => __('PayPal Credit', 'paypal-for-woocommerce'), + 'card' => __('Credit or Debit card', 'paypal-for-woocommerce'), + 'elv' => __('Elektronisches Lastschriftverfahren', 'paypal-for-woocommerce'), + ), + ), + 'button_layout' => array( + 'title' => __('Button Layout', 'paypal-for-woocommerce'), + 'type' => 'select', + 'class' => 'wc-enhanced-select in_context_checkout_part', + 'description' => __('Type of PayPal Button Layout (pill | rect).', 'paypal-for-woocommerce'), + 'default' => 'horizontal', + 'desc_tip' => true, + 'options' => array( + 'horizontal' => __('Horizontal', 'paypal-for-woocommerce'), + 'vertical' => __('Vertical', 'paypal-for-woocommerce') + ), + ), 'button_size' => array( 'title' => __('Button Size', 'paypal-for-woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select in_context_checkout_part', 'description' => __('Type of PayPal Button Size (small | medium | responsive).', 'paypal-for-woocommerce'), - 'default' => 'small', + 'default' => 'medium', 'desc_tip' => true, 'options' => array( 'small' => __('Small', 'paypal-for-woocommerce'), @@ -824,6 +867,19 @@ public function init_form_fields() { 'responsive' => __('Responsive', 'paypal-for-woocommerce'), ), ), + 'button_color' => array( + 'title' => __('Button Color', 'paypal-for-woocommerce'), + 'type' => 'select', + 'class' => 'wc-enhanced-select in_context_checkout_part', + 'description' => __('Type of PayPal Button Color (gold | blue | silver).', 'paypal-for-woocommerce'), + 'default' => 'gold', + 'desc_tip' => true, + 'options' => array( + 'gold' => __('Gold', 'paypal-for-woocommerce'), + 'blue' => __('Blue', 'paypal-for-woocommerce'), + 'silver' => __('Silver', 'paypal-for-woocommerce') + ), + ), 'button_shape' => array( 'title' => __('Button Shape', 'paypal-for-woocommerce'), 'type' => 'select', @@ -836,17 +892,32 @@ public function init_form_fields() { 'rect' => __('Rect', 'paypal-for-woocommerce') ), ), - 'button_color' => array( - 'title' => __('Button Color', 'paypal-for-woocommerce'), + 'button_label' => array( + 'title' => __('Button Label', 'paypal-for-woocommerce'), 'type' => 'select', 'class' => 'wc-enhanced-select in_context_checkout_part', - 'description' => __('Type of PayPal Button Color (gold | blue | silver).', 'paypal-for-woocommerce'), - 'default' => 'gold', + 'description' => __('Type of PayPal Button Label (checkout | credit | pay | buynow | paypal).', 'paypal-for-woocommerce'), + 'default' => 'checkout', 'desc_tip' => true, 'options' => array( - 'gold' => __('Gold', 'paypal-for-woocommerce'), - 'blue' => __('Blue', 'paypal-for-woocommerce'), - 'silver' => __('Silver', 'paypal-for-woocommerce') + 'checkout' => __('Checkout', 'paypal-for-woocommerce'), + 'credit' => __('Credit', 'paypal-for-woocommerce'), + 'pay' => __('Pay', 'paypal-for-woocommerce'), + 'buynow' => __('Buynow', 'paypal-for-woocommerce'), + 'paypal' => __('Paypal', 'paypal-for-woocommerce') + + ), + ), + 'button_tagline' => array( + 'title' => __('Button Tagline ', 'paypal-for-woocommerce'), + 'type' => 'select', + 'class' => 'wc-enhanced-select in_context_checkout_part', + 'description' => __('To enable/disable the tagline/text beneath the button.', 'paypal-for-woocommerce'), + 'default' => 'false', + 'desc_tip' => true, + 'options' => array( + 'false' => __('Disable', 'paypal-for-woocommerce'), + 'true' => __('Enable', 'paypal-for-woocommerce') ), ), );