Skip to content

Commit

Permalink
Express Checkout - JSv4, ref #997
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Feb 20, 2018
1 parent 3c89799 commit 2c1194d
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand All @@ -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('/')))
)
)
);
}

Expand Down
36 changes: 19 additions & 17 deletions assets/js/angelleye-in-context-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -60,7 +61,6 @@
return actions.redirect();
}
}, selector );

});
};
} else {
Expand All @@ -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;
});
Expand All @@ -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);
Expand Down Expand Up @@ -138,6 +139,7 @@
return actions.redirect();
},
onError: function (err) {
alert(err);
return actions.redirect();
}
}, '.angelleye_button_single');
Expand Down
87 changes: 79 additions & 8 deletions classes/wc-gateway-paypal-express-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("<option></option>").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();
Expand Down Expand Up @@ -811,19 +829,57 @@ public function init_form_fields() {
'class' => 'in_context_checkout_part',
'description' => '<div class="in_context_checkout_part">Customize your PayPal button with colors, sizes, shapes, layout and funding sources.</div>',
),
'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'),
'medium' => __('Medium', 'paypal-for-woocommerce'),
'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',
Expand All @@ -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')
),
),
);
Expand Down

0 comments on commit 2c1194d

Please sign in to comment.