WooCommerce PayPal Express Checkout Payment Gateway - Version 1.6.0

Version Description

  • 2018-06-27 =
  • Add - Smart Payment Buttons mode as alternative to directly embedded image links for all instances of PayPal button.
  • Fix - Help tip alignment for image settings.
  • Update - Enable PayPal Credit by default, and restrict its support by currency.
  • Update - Omit 'Express Checkout' portion of default payment method title.
  • Update - Enable Express Checkout on regular checkout page by default.
  • Update - Enable Express Checkout on single product page by default.
Download this release

Release Info

Developer bor0
Plugin Icon 128x128 WooCommerce PayPal Express Checkout Payment Gateway
Version 1.6.0
Comparing to
See all releases

Code changes from version 1.5.6 to 1.6.0

assets/css/wc-gateway-ppec-frontend-cart.css CHANGED
@@ -3,6 +3,9 @@
3
  margin: 1em 0;
4
  overflow: hidden;
5
  }
 
 
 
6
  .wcppec-checkout-buttons__separator {
7
  display: block;
8
  opacity: .5;
@@ -28,3 +31,6 @@
28
  text-decoration: none !important;
29
  border: 0 !important;
30
  }
 
 
 
3
  margin: 1em 0;
4
  overflow: hidden;
5
  }
6
+ .wcppec-checkout-buttons .woocommerce-error {
7
+ text-align: left;
8
+ }
9
  .wcppec-checkout-buttons__separator {
10
  display: block;
11
  opacity: .5;
31
  text-decoration: none !important;
32
  border: 0 !important;
33
  }
34
+ .site-header .widget_shopping_cart p.buttons.wcppec-cart-widget-spb {
35
+ padding: 0 1em 1em;
36
+ }
assets/js/wc-gateway-ppec-generate-cart.js CHANGED
@@ -1,25 +1,46 @@
1
- /* global wc_ppec_context */
2
  ;(function( $, window, document ) {
3
  'use strict';
4
 
 
5
  var button_enabled = true;
6
-
7
- var toggle_button_availability = function( available ) {
8
- if ( available ) {
9
  button_enabled = true;
 
 
 
 
 
 
 
10
  $( '#woo_pp_ec_button_product' ).css( {
11
  'cursor': '',
12
  '-webkit-filter': '', // Safari 6.0 - 9.0
13
  'filter': '',
14
  } );
15
- } else {
16
- button_enabled = false;
 
17
  $( '#woo_pp_ec_button_product' ).css( {
18
  'cursor': 'not-allowed',
19
  '-webkit-filter': 'grayscale( 100% )', // Safari 6.0 - 9.0
20
  'filter': 'grayscale( 100% )',
21
  } );
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  var get_attributes = function() {
@@ -47,44 +68,38 @@
47
  };
48
  };
49
 
50
- // It's a variations form, button availability should depend on its events
51
- if ( $( '.variations_form' ).length ) {
52
- toggle_button_availability( false );
 
 
 
 
53
 
54
- $( '.variations_form' )
55
- .on( 'show_variation', function( event, form, purchasable ) {
56
- toggle_button_availability( purchasable );
57
- } )
58
- .on( 'hide_variation', function() {
59
- toggle_button_availability( false );
60
  } );
61
- }
62
 
63
- $( '#woo_pp_ec_button_product' ).click( function( event ) {
 
 
 
64
  event.preventDefault();
65
 
66
  if ( ! button_enabled ) {
67
  return;
68
  }
69
 
70
- toggle_button_availability( false );
71
-
72
- var data = {
73
- 'nonce': wc_ppec_context.generate_cart_nonce,
74
- 'qty': $( '.quantity .qty' ).val(),
75
- 'attributes': $( '.variations_form' ).length ? get_attributes().data : [],
76
- 'add-to-cart': $( '[name=add-to-cart]' ).val(),
77
- };
78
 
79
  var href = $(this).attr( 'href' );
80
 
81
- $.ajax( {
82
- type: 'POST',
83
- data: data,
84
- url: wc_ppec_context.ajaxurl,
85
- success: function( response ) {
86
- window.location.href = href;
87
- }
88
  } );
89
  } );
90
 
1
+ /* global wc_ppec_generate_cart_context */
2
  ;(function( $, window, document ) {
3
  'use strict';
4
 
5
+ // This button state is only applicable to non-SPB click handler below.
6
  var button_enabled = true;
7
+ $( '#woo_pp_ec_button_product' )
8
+ .on( 'enable.legacy', function() {
 
9
  button_enabled = true;
10
+ } )
11
+ .on( 'disable.legacy', function() {
12
+ button_enabled = false;
13
+ } );
14
+
15
+ $( '#woo_pp_ec_button_product' )
16
+ .on( 'enable', function() {
17
  $( '#woo_pp_ec_button_product' ).css( {
18
  'cursor': '',
19
  '-webkit-filter': '', // Safari 6.0 - 9.0
20
  'filter': '',
21
  } );
22
+ $( '#woo_pp_ec_button_product > *' ).css( 'pointer-events', '' );
23
+ } )
24
+ .on( 'disable', function() {
25
  $( '#woo_pp_ec_button_product' ).css( {
26
  'cursor': 'not-allowed',
27
  '-webkit-filter': 'grayscale( 100% )', // Safari 6.0 - 9.0
28
  'filter': 'grayscale( 100% )',
29
  } );
30
+ $( '#woo_pp_ec_button_product > *' ).css( 'pointer-events', 'none' );
31
+ } );
32
+
33
+ // It's a variations form, button availability should depend on its events
34
+ if ( $( '.variations_form' ).length ) {
35
+ $( '#woo_pp_ec_button_product' ).trigger( 'disable' );
36
+
37
+ $( '.variations_form' )
38
+ .on( 'show_variation', function( event, form, purchasable ) {
39
+ $( '#woo_pp_ec_button_product' ).trigger( purchasable ? 'enable' : 'disable' );
40
+ } )
41
+ .on( 'hide_variation', function() {
42
+ $( '#woo_pp_ec_button_product' ).trigger( 'disable' );
43
+ } );
44
  }
45
 
46
  var get_attributes = function() {
68
  };
69
  };
70
 
71
+ var generate_cart = function( callback ) {
72
+ var data = {
73
+ 'nonce': wc_ppec_generate_cart_context.generate_cart_nonce,
74
+ 'qty': $( '.quantity .qty' ).val(),
75
+ 'attributes': $( '.variations_form' ).length ? get_attributes().data : [],
76
+ 'add-to-cart': $( '[name=add-to-cart]' ).val(),
77
+ };
78
 
79
+ $.ajax( {
80
+ type: 'POST',
81
+ data: data,
82
+ url: wc_ppec_generate_cart_context.ajaxurl,
83
+ success: callback,
 
84
  } );
85
+ };
86
 
87
+ window.wc_ppec_generate_cart = generate_cart;
88
+
89
+ // Non-SPB mode click handler, namespaced as 'legacy' as it's replaced by `payment` callback of Button API.
90
+ $( '#woo_pp_ec_button_product' ).on( 'click.legacy', function( event ) {
91
  event.preventDefault();
92
 
93
  if ( ! button_enabled ) {
94
  return;
95
  }
96
 
97
+ $( '#woo_pp_ec_button_product' ).trigger( 'disable' );
 
 
 
 
 
 
 
98
 
99
  var href = $(this).attr( 'href' );
100
 
101
+ generate_cart( function() {
102
+ window.location.href = href;
 
 
 
 
 
103
  } );
104
  } );
105
 
assets/js/wc-gateway-ppec-order-review.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ ;(function ( $, window, document ) {
2
+ 'use strict';
3
+
4
+ $( 'form.checkout' ).on( 'click', 'input[name="payment_method"]', function() {
5
+ var isPPEC = $( this ).is( '#payment_method_ppec_paypal' );
6
+ $( '#place_order' ).toggle( ! isPPEC );
7
+ $( '#woo_pp_ec_button_checkout' ).toggle( isPPEC );
8
+ } );
9
+ })( jQuery, window, document );
assets/js/wc-gateway-ppec-smart-payment-buttons.js ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global wc_ppec_context */
2
+ ;( function ( $, window, document ) {
3
+ 'use strict';
4
+
5
+ // Map funding method settings to enumerated options provided by PayPal.
6
+ var getFundingMethods = function( methods ) {
7
+ if ( ! methods ) {
8
+ return null;
9
+ }
10
+
11
+ var paypal_funding_methods = [];
12
+ for ( var i = 0; i < methods.length; i++ ) {
13
+ var method = paypal.FUNDING[ methods[ i ] ];
14
+ if ( method ) {
15
+ paypal_funding_methods.push( method );
16
+ }
17
+ }
18
+ return paypal_funding_methods;
19
+ }
20
+
21
+ var render = function( isMiniCart ) {
22
+ var prefix = isMiniCart ? 'mini_cart_' : '';
23
+ var button_size = wc_ppec_context[ prefix + 'button_size' ];
24
+ var button_layout = wc_ppec_context[ prefix + 'button_layout' ];
25
+ var button_label = wc_ppec_context[ prefix + 'button_label' ];
26
+ var allowed = wc_ppec_context[ prefix + 'allowed_methods' ];
27
+ var disallowed = wc_ppec_context[ prefix + 'disallowed_methods' ];
28
+
29
+ var selector = isMiniCart ? '#woo_pp_ec_button_mini_cart' : '#woo_pp_ec_button_' + wc_ppec_context.page;
30
+
31
+ paypal.Button.render( {
32
+ env: wc_ppec_context.environment,
33
+ locale: wc_ppec_context.locale,
34
+ commit: 'checkout' === wc_ppec_context.page && ! isMiniCart,
35
+
36
+ funding: {
37
+ allowed: getFundingMethods( allowed ),
38
+ disallowed: getFundingMethods( disallowed ),
39
+ },
40
+
41
+ style: {
42
+ color: wc_ppec_context.button_color,
43
+ shape: wc_ppec_context.button_shape,
44
+ layout: button_layout,
45
+ size: button_size,
46
+ label: button_label,
47
+ tagline: false,
48
+ },
49
+
50
+ validate: function( actions ) {
51
+ // Only enable on variable product page if purchasable variation selected.
52
+ $( '#woo_pp_ec_button_product' ).off( '.legacy' )
53
+ .on( 'enable', actions.enable )
54
+ .on( 'disable', actions.disable );
55
+ },
56
+
57
+ payment: function() {
58
+ // Clear any errors from previous attempt.
59
+ $( '.woocommerce-error', selector ).remove();
60
+
61
+ return new paypal.Promise( function( resolve, reject ) {
62
+ // First, generate cart if triggered from single product.
63
+ if ( 'product' === wc_ppec_context.page && ! isMiniCart ) {
64
+ window.wc_ppec_generate_cart( resolve );
65
+ } else {
66
+ resolve();
67
+ }
68
+ } ).then( function() {
69
+ // Make Express Checkout initialization request.
70
+ return paypal.request( {
71
+ method: 'post',
72
+ url: wc_ppec_context.start_checkout_url,
73
+ data: {
74
+ 'nonce': wc_ppec_context.start_checkout_nonce,
75
+ 'from_checkout': 'checkout' === wc_ppec_context.page && ! isMiniCart ? 'yes' : 'no',
76
+ },
77
+ } ).then( function( response ) {
78
+ if ( ! response.success ) {
79
+ // Render error notice inside button container.
80
+ var $message = $( '<ul class="woocommerce-error" role="alert">' )
81
+ .append( $( '<li>' ).text( response.data.message ) );
82
+ $( selector ).prepend( $message );
83
+ return null;
84
+ }
85
+ return response.data.token;
86
+ } );
87
+ } );
88
+ },
89
+
90
+ onAuthorize: function( data, actions ) {
91
+ if ( 'checkout' === wc_ppec_context.page && ! isMiniCart ) {
92
+ // Pass data necessary for authorizing payment to back-end.
93
+ $( 'form.checkout' )
94
+ .append( $( '<input type="hidden" name="paymentToken" /> ' ).attr( 'value', data.paymentToken ) )
95
+ .append( $( '<input type="hidden" name="payerID" /> ' ).attr( 'value', data.payerID ) )
96
+ .submit();
97
+ } else {
98
+ // Navigate to order confirmation URL specified in original request to PayPal from back-end.
99
+ return actions.redirect();
100
+ }
101
+ },
102
+
103
+ }, selector );
104
+ };
105
+
106
+ // Render cart, single product, or checkout buttons.
107
+ if ( wc_ppec_context.page ) {
108
+ render();
109
+ $( document.body ).on( 'updated_cart_totals updated_checkout', render.bind( this, false ) );
110
+ }
111
+
112
+ // Render buttons in mini-cart if present.
113
+ $( document.body ).on( 'wc_fragments_loaded wc_fragments_refreshed', function() {
114
+ var $button = $( '.widget_shopping_cart #woo_pp_ec_button_mini_cart' );
115
+ if ( $button.length ) {
116
+ // Clear any existing button in container, and render.
117
+ $button.empty();
118
+ render( true );
119
+ }
120
+ } );
121
+
122
+ } )( jQuery, window, document );
changelog.txt CHANGED
@@ -1,5 +1,13 @@
1
  *** Changelog ***
2
 
 
 
 
 
 
 
 
 
3
  = 1.5.6 - 2018-06-06 =
4
  * Fix - Virtual products cause issues with billing details validation.
5
 
1
  *** Changelog ***
2
 
3
+ = 1.6.0 - 2018-06-27 =
4
+ * Add - Smart Payment Buttons mode as alternative to directly embedded image links for all instances of PayPal button.
5
+ * Fix - Help tip alignment for image settings.
6
+ * Update - Enable PayPal Credit by default, and restrict its support by currency.
7
+ * Update - Omit 'Express Checkout' portion of default payment method title.
8
+ * Update - Enable Express Checkout on regular checkout page by default.
9
+ * Update - Enable Express Checkout on single product page by default.
10
+
11
  = 1.5.6 - 2018-06-06 =
12
  * Fix - Virtual products cause issues with billing details validation.
13
 
includes/abstracts/abstract-wc-gateway-ppec.php CHANGED
@@ -532,8 +532,7 @@ abstract class WC_Gateway_PPEC extends WC_Payment_Gateway {
532
  ?>
533
  <tr valign="top">
534
  <th scope="row" class="titledesc">
535
- <?php echo $this->get_tooltip_html( $data ); ?>
536
- <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
537
  </th>
538
 
539
  <td class="image-component-wrapper">
532
  ?>
533
  <tr valign="top">
534
  <th scope="row" class="titledesc">
535
+ <label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?> <?php echo $this->get_tooltip_html( $data ); ?></label>
 
536
  </th>
537
 
538
  <td class="image-component-wrapper">
includes/class-wc-gateway-ppec-cart-handler.php CHANGED
@@ -20,16 +20,22 @@ class WC_Gateway_PPEC_Cart_Handler {
20
  }
21
 
22
  add_action( 'woocommerce_before_cart_totals', array( $this, 'before_cart_totals' ) );
23
- add_action( 'woocommerce_widget_shopping_cart_buttons', array( $this, 'display_mini_paypal_button' ), 20 );
24
  add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_paypal_button' ), 20 );
25
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
26
 
 
 
 
 
 
 
27
  if ( 'yes' === wc_gateway_ppec()->settings->checkout_on_single_product_enabled ) {
28
  add_action( 'woocommerce_after_add_to_cart_form', array( $this, 'display_paypal_button_product' ), 1 );
29
  add_action( 'wc_ajax_wc_ppec_generate_cart', array( $this, 'wc_ajax_generate_cart' ) );
30
  }
31
 
32
  add_action( 'wc_ajax_wc_ppec_update_shipping_costs', array( $this, 'wc_ajax_update_shipping_costs' ) );
 
33
  }
34
 
35
  /**
@@ -118,6 +124,28 @@ class WC_Gateway_PPEC_Cart_Handler {
118
  wp_send_json( new stdClass() );
119
  }
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  /**
122
  * Display paypal button on the product page.
123
  *
@@ -136,10 +164,14 @@ class WC_Gateway_PPEC_Cart_Handler {
136
 
137
  ?>
138
  <div class="wcppec-checkout-buttons woo_pp_cart_buttons_div">
 
 
 
139
 
140
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button_product" class="wcppec-checkout-buttons__button">
141
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
142
  </a>
 
143
  </div>
144
  <?php
145
  }
@@ -168,6 +200,10 @@ class WC_Gateway_PPEC_Cart_Handler {
168
  </div>
169
  <?php endif; ?>
170
 
 
 
 
 
171
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button" class="wcppec-checkout-buttons__button">
172
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
173
  </a>
@@ -177,6 +213,8 @@ class WC_Gateway_PPEC_Cart_Handler {
177
  <img src="<?php echo esc_url( $paypal_credit_img_url ); ?>" alt="<?php _e( 'Pay with PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
178
  </a>
179
  <?php endif; ?>
 
 
180
  </div>
181
  <?php
182
  }
@@ -194,12 +232,66 @@ class WC_Gateway_PPEC_Cart_Handler {
194
  return;
195
  }
196
  ?>
 
 
 
 
 
 
 
197
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button" class="wcppec-cart-widget-button">
198
  <img src="<?php echo esc_url( 'https://www.paypalobjects.com/webstatic/en_US/i/btn/png/gold-rect-paypalcheckout-26px.png' ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
199
  </a>
 
200
  <?php
201
  }
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  /**
204
  * Frontend scripts
205
  */
@@ -209,7 +301,12 @@ class WC_Gateway_PPEC_Cart_Handler {
209
 
210
  wp_enqueue_style( 'wc-gateway-ppec-frontend-cart', wc_gateway_ppec()->plugin_url . 'assets/css/wc-gateway-ppec-frontend-cart.css' );
211
 
212
- if ( is_cart() ) {
 
 
 
 
 
213
  wp_enqueue_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
214
  wp_enqueue_script( 'wc-gateway-ppec-frontend-in-context-checkout', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-frontend-in-context-checkout.js', array( 'jquery' ), wc_gateway_ppec()->version, true );
215
  wp_localize_script( 'wc-gateway-ppec-frontend-in-context-checkout', 'wc_ppec_context',
@@ -223,11 +320,47 @@ class WC_Gateway_PPEC_Cart_Handler {
223
  'ajaxurl' => WC_AJAX::get_endpoint( 'wc_ppec_update_shipping_costs' ),
224
  )
225
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  }
227
 
228
- if ( is_product() ) {
229
  wp_enqueue_script( 'wc-gateway-ppec-generate-cart', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-generate-cart.js', array( 'jquery' ), wc_gateway_ppec()->version, true );
230
- wp_localize_script( 'wc-gateway-ppec-generate-cart', 'wc_ppec_context',
231
  array(
232
  'generate_cart_nonce' => wp_create_nonce( '_wc_ppec_generate_cart_nonce' ),
233
  'ajaxurl' => WC_AJAX::get_endpoint( 'wc_ppec_generate_cart' ),
20
  }
21
 
22
  add_action( 'woocommerce_before_cart_totals', array( $this, 'before_cart_totals' ) );
 
23
  add_action( 'woocommerce_proceed_to_checkout', array( $this, 'display_paypal_button' ), 20 );
24
  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
25
 
26
+ if ( 'yes' === wc_gateway_ppec()->settings->use_spb ) {
27
+ add_action( 'woocommerce_after_mini_cart', array( $this, 'display_mini_paypal_button' ), 20 );
28
+ } else {
29
+ add_action( 'woocommerce_widget_shopping_cart_buttons', array( $this, 'display_mini_paypal_button' ), 20 );
30
+ }
31
+
32
  if ( 'yes' === wc_gateway_ppec()->settings->checkout_on_single_product_enabled ) {
33
  add_action( 'woocommerce_after_add_to_cart_form', array( $this, 'display_paypal_button_product' ), 1 );
34
  add_action( 'wc_ajax_wc_ppec_generate_cart', array( $this, 'wc_ajax_generate_cart' ) );
35
  }
36
 
37
  add_action( 'wc_ajax_wc_ppec_update_shipping_costs', array( $this, 'wc_ajax_update_shipping_costs' ) );
38
+ add_action( 'wc_ajax_wc_ppec_start_checkout', array( $this, 'wc_ajax_start_checkout' ) );
39
  }
40
 
41
  /**
124
  wp_send_json( new stdClass() );
125
  }
126
 
127
+ /**
128
+ * Set Express Checkout and return token in response.
129
+ *
130
+ * @since 1.6.0
131
+ */
132
+ public function wc_ajax_start_checkout() {
133
+ if ( ! wp_verify_nonce( $_POST['nonce'], '_wc_ppec_start_checkout_nonce' ) ) {
134
+ wp_die( __( 'Cheatin&#8217; huh?', 'woocommerce-gateway-paypal-express-checkout' ) );
135
+ }
136
+
137
+ if ( isset( $_POST['from_checkout'] ) && 'yes' === $_POST['from_checkout'] ) {
138
+ add_filter( 'woocommerce_cart_needs_shipping', '__return_false' );
139
+ }
140
+
141
+ try {
142
+ wc_gateway_ppec()->checkout->start_checkout_from_cart();
143
+ wp_send_json_success( array( 'token' => WC()->session->paypal->token ) );
144
+ } catch( PayPal_API_Exception $e ) {
145
+ wp_send_json_error( array( 'message' => $e->getMessage() ) );
146
+ }
147
+ }
148
+
149
  /**
150
  * Display paypal button on the product page.
151
  *
164
 
165
  ?>
166
  <div class="wcppec-checkout-buttons woo_pp_cart_buttons_div">
167
+ <?php if ( 'yes' === $settings->use_spb ) : ?>
168
+ <div id="woo_pp_ec_button_product"></div>
169
+ <?php else : ?>
170
 
171
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button_product" class="wcppec-checkout-buttons__button">
172
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
173
  </a>
174
+ <?php endif; ?>
175
  </div>
176
  <?php
177
  }
200
  </div>
201
  <?php endif; ?>
202
 
203
+ <?php if ( 'yes' === $settings->use_spb ) : ?>
204
+ <div id="woo_pp_ec_button_cart"></div>
205
+ <?php else : ?>
206
+
207
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button" class="wcppec-checkout-buttons__button">
208
  <img src="<?php echo esc_url( $express_checkout_img_url ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
209
  </a>
213
  <img src="<?php echo esc_url( $paypal_credit_img_url ); ?>" alt="<?php _e( 'Pay with PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
214
  </a>
215
  <?php endif; ?>
216
+
217
+ <?php endif; ?>
218
  </div>
219
  <?php
220
  }
232
  return;
233
  }
234
  ?>
235
+
236
+ <?php if ( 'yes' === $settings->use_spb ) : ?>
237
+ <p class="woocommerce-mini-cart__buttons buttons wcppec-cart-widget-spb">
238
+ <span id="woo_pp_ec_button_mini_cart"></span>
239
+ </p>
240
+ <?php else : ?>
241
+
242
  <a href="<?php echo esc_url( add_query_arg( array( 'startcheckout' => 'true' ), wc_get_page_permalink( 'cart' ) ) ); ?>" id="woo_pp_ec_button" class="wcppec-cart-widget-button">
243
  <img src="<?php echo esc_url( 'https://www.paypalobjects.com/webstatic/en_US/i/btn/png/gold-rect-paypalcheckout-26px.png' ); ?>" alt="<?php _e( 'Check out with PayPal', 'woocommerce-gateway-paypal-express-checkout' ); ?>" style="width: auto; height: auto;">
244
  </a>
245
+ <?php endif; ?>
246
  <?php
247
  }
248
 
249
+ /**
250
+ * Convert from settings to values expected by PayPal Button API:
251
+ * - 'small' button size only allowed if layout is 'vertical'.
252
+ * - 'label' only allowed if layout is 'vertical'.
253
+ * - 'disallowed' funding methods if layout is 'vertical'.
254
+ * - 'allowed' funding methods if layout is 'horizontal'.
255
+ * - Only allow PayPal Credit if supported.
256
+ *
257
+ * @param array Raw settings.
258
+ *
259
+ * @return array Same array adapted to include data suitable for client-side rendering.
260
+ *
261
+ * @since 1.6.0
262
+ */
263
+ protected function get_button_settings( $settings, $context = '' ) {
264
+ $prefix = $context ? $context . '_' : $context;
265
+ $data = array(
266
+ 'button_layout' => $settings->{ $prefix . 'button_layout' },
267
+ 'button_size' => $settings->{ $prefix . 'button_size' },
268
+ 'hide_funding_methods' => $settings->{ $prefix . 'hide_funding_methods' },
269
+ 'credit_enabled' => $settings->{ $prefix . 'credit_enabled' },
270
+ );
271
+
272
+ $button_layout = $data['button_layout'];
273
+ $data['button_label'] = 'horizontal' === $button_layout ? 'buynow' : null;
274
+ $data['button_size'] = 'vertical' === $button_layout && 'small' === $data['button_size']
275
+ ? 'medium'
276
+ : $data['button_size'];
277
+
278
+ if ( ! wc_gateway_ppec_is_credit_supported() ) {
279
+ $data['credit_enabled'] = 'no';
280
+ if ( ! in_array( 'CREDIT', $data['hide_funding_methods'] ) ) {
281
+ $data['hide_funding_methods'][] = 'CREDIT';
282
+ }
283
+ }
284
+
285
+ if ( 'vertical' === $button_layout ) {
286
+ $data['disallowed_methods'] = $data['hide_funding_methods'];
287
+ } else {
288
+ $data['allowed_methods'] = 'yes' === $data['credit_enabled'] ? array( 'CREDIT' ) : array();
289
+ }
290
+ unset( $data['hide_funding_methods'], $data['credit_enabled'] );
291
+
292
+ return $data;
293
+ }
294
+
295
  /**
296
  * Frontend scripts
297
  */
301
 
302
  wp_enqueue_style( 'wc-gateway-ppec-frontend-cart', wc_gateway_ppec()->plugin_url . 'assets/css/wc-gateway-ppec-frontend-cart.css' );
303
 
304
+ $is_cart = is_cart() && 'yes' === $settings->cart_checkout_enabled;
305
+ $is_product = is_product() && 'yes' === $settings->checkout_on_single_product_enabled;
306
+ $is_checkout = is_checkout() && 'yes' === $settings->mark_enabled && ! wc_gateway_ppec()->checkout->has_active_session();
307
+ $page = $is_cart ? 'cart' : ( $is_product ? 'product' : ( $is_checkout ? 'checkout' : null ) );
308
+
309
+ if ( 'yes' !== $settings->use_spb && $is_cart ) {
310
  wp_enqueue_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
311
  wp_enqueue_script( 'wc-gateway-ppec-frontend-in-context-checkout', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-frontend-in-context-checkout.js', array( 'jquery' ), wc_gateway_ppec()->version, true );
312
  wp_localize_script( 'wc-gateway-ppec-frontend-in-context-checkout', 'wc_ppec_context',
320
  'ajaxurl' => WC_AJAX::get_endpoint( 'wc_ppec_update_shipping_costs' ),
321
  )
322
  );
323
+
324
+ } elseif ( 'yes' === $settings->use_spb ) {
325
+ wp_enqueue_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
326
+ wp_enqueue_script( 'wc-gateway-ppec-smart-payment-buttons', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-smart-payment-buttons.js', array( 'jquery', 'paypal-checkout-js' ), wc_gateway_ppec()->version, true );
327
+
328
+ $data = array(
329
+ 'environment' => 'sandbox' === $settings->get_environment() ? 'sandbox' : 'production',
330
+ 'locale' => $settings->get_paypal_locale(),
331
+ 'page' => $page,
332
+ 'button_color' => $settings->button_color,
333
+ 'button_shape' => $settings->button_shape,
334
+ 'start_checkout_nonce' => wp_create_nonce( '_wc_ppec_start_checkout_nonce' ),
335
+ 'start_checkout_url' => WC_AJAX::get_endpoint( 'wc_ppec_start_checkout' ),
336
+ );
337
+
338
+ if ( ! is_null( $page ) ) {
339
+ if ( 'product' === $page && 'yes' === $settings->single_product_settings_toggle ) {
340
+ $button_settings = $this->get_button_settings( $settings, 'single_product' );
341
+ } elseif ( 'checkout' === $page && 'yes' === $settings->mark_settings_toggle ) {
342
+ $button_settings = $this->get_button_settings( $settings, 'mark' );
343
+ } else {
344
+ $button_settings = $this->get_button_settings( $settings );
345
+ }
346
+
347
+ $data = array_merge( $data, $button_settings );
348
+ }
349
+
350
+ $settings_toggle = 'yes' === $settings->mini_cart_settings_toggle;
351
+ $mini_cart_data = $this->get_button_settings( $settings, $settings_toggle ? 'mini_cart' : '' );
352
+ foreach( $mini_cart_data as $key => $value ) {
353
+ unset( $mini_cart_data[ $key ] );
354
+ $mini_cart_data[ 'mini_cart_' . $key ] = $value;
355
+ }
356
+ $data = array_merge( $data, $mini_cart_data );
357
+
358
+ wp_localize_script( 'wc-gateway-ppec-smart-payment-buttons', 'wc_ppec_context', $data );
359
  }
360
 
361
+ if ( $is_product ) {
362
  wp_enqueue_script( 'wc-gateway-ppec-generate-cart', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-generate-cart.js', array( 'jquery' ), wc_gateway_ppec()->version, true );
363
+ wp_localize_script( 'wc-gateway-ppec-generate-cart', 'wc_ppec_generate_cart_context',
364
  array(
365
  'generate_cart_nonce' => wp_create_nonce( '_wc_ppec_generate_cart_nonce' ),
366
  'ajaxurl' => WC_AJAX::get_endpoint( 'wc_ppec_generate_cart' ),
includes/class-wc-gateway-ppec-gateway-loader.php CHANGED
@@ -21,6 +21,7 @@ class WC_Gateway_PPEC_Gateway_Loader {
21
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal.php' );
22
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal-credit.php' );
23
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal-addons.php' );
 
24
 
25
  add_filter( 'woocommerce_payment_gateways', array( $this, 'payment_gateways' ) );
26
  }
@@ -35,6 +36,11 @@ class WC_Gateway_PPEC_Gateway_Loader {
35
  public function payment_gateways( $methods ) {
36
  $settings = wc_gateway_ppec()->settings;
37
 
 
 
 
 
 
38
  if ( $this->can_use_addons() ) {
39
  $methods[] = 'WC_Gateway_PPEC_With_PayPal_Addons';
40
  } else {
21
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal.php' );
22
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal-credit.php' );
23
  require_once( $includes_path . 'class-wc-gateway-ppec-with-paypal-addons.php' );
24
+ require_once( $includes_path . 'class-wc-gateway-ppec-with-spb.php' );
25
 
26
  add_filter( 'woocommerce_payment_gateways', array( $this, 'payment_gateways' ) );
27
  }
36
  public function payment_gateways( $methods ) {
37
  $settings = wc_gateway_ppec()->settings;
38
 
39
+ if ( 'yes' === $settings->use_spb ) {
40
+ $methods[] = 'WC_Gateway_PPEC_With_SPB';
41
+ return $methods;
42
+ }
43
+
44
  if ( $this->can_use_addons() ) {
45
  $methods[] = 'WC_Gateway_PPEC_With_PayPal_Addons';
46
  } else {
includes/class-wc-gateway-ppec-plugin.php CHANGED
@@ -188,7 +188,7 @@ class WC_Gateway_PPEC_Plugin {
188
  <script>
189
  ( function( $ ) {
190
  $( '.ppec-dismiss-bootstrap-warning-message' ).on( 'click', '.notice-dismiss', function() {
191
- jQuery.post( "<?php echo admin_url( 'admin-ajax.php' ); ?>", {
192
  action: "ppec_dismiss_notice_message",
193
  dismiss_action: "ppec_dismiss_bootstrap_warning_message",
194
  nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
@@ -210,7 +210,7 @@ class WC_Gateway_PPEC_Plugin {
210
  <script>
211
  ( function( $ ) {
212
  $( '.ppec-dismiss-prompt-to-connect-message' ).on( 'click', '.notice-dismiss', function() {
213
- jQuery.post( "<?php echo admin_url( 'admin-ajax.php' ); ?>", {
214
  action: "ppec_dismiss_notice_message",
215
  dismiss_action: "ppec_dismiss_prompt_to_connect",
216
  nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
@@ -222,6 +222,41 @@ class WC_Gateway_PPEC_Plugin {
222
  }
223
  }
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  /**
226
  * AJAX handler for dismiss notice action.
227
  *
@@ -241,6 +276,9 @@ class WC_Gateway_PPEC_Plugin {
241
  case 'ppec_dismiss_prompt_to_connect':
242
  update_option( 'wc_gateway_ppec_prompt_to_connect_message_dismissed', 'yes' );
243
  break;
 
 
 
244
  }
245
  wp_die();
246
  }
@@ -300,6 +338,7 @@ class WC_Gateway_PPEC_Plugin {
300
  protected function _run() {
301
  require_once( $this->includes_path . 'functions.php' );
302
  $this->_load_handlers();
 
303
  }
304
 
305
  /**
188
  <script>
189
  ( function( $ ) {
190
  $( '.ppec-dismiss-bootstrap-warning-message' ).on( 'click', '.notice-dismiss', function() {
191
+ jQuery.post( "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", {
192
  action: "ppec_dismiss_notice_message",
193
  dismiss_action: "ppec_dismiss_bootstrap_warning_message",
194
  nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
210
  <script>
211
  ( function( $ ) {
212
  $( '.ppec-dismiss-prompt-to-connect-message' ).on( 'click', '.notice-dismiss', function() {
213
+ jQuery.post( "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", {
214
  action: "ppec_dismiss_notice_message",
215
  dismiss_action: "ppec_dismiss_prompt_to_connect",
216
  nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
222
  }
223
  }
224
 
225
+ public function show_spb_notice() {
226
+ // Should only show when PPEC is enabled but not in SPB mode.
227
+ if ( 'yes' !== $this->settings->enabled || 'yes' === $this->settings->use_spb ) {
228
+ return;
229
+ }
230
+
231
+ // Should only show on WooCommerce screens, the main dashboard, and on the plugins screen (as in WC_Admin_Notices).
232
+ $screen = get_current_screen();
233
+ $screen_id = $screen ? $screen->id : '';
234
+ if ( ! in_array( $screen_id, wc_get_screen_ids(), true ) && 'dashboard' !== $screen_id && 'plugins' !== $screen_id ) {
235
+ return;
236
+ }
237
+
238
+ if ( 'yes' !== get_option( 'wc_gateway_ppec_spb_notice_dismissed', 'no' ) ) {
239
+ $setting_link = $this->get_admin_setting_link();
240
+ $message = sprintf( __( '<p>PayPal&nbsp;Express&nbsp;Checkout with new <strong>Smart&nbsp;Payment&nbsp;Buttons™</strong> gives your customers the power to pay the way they want without leaving your site.</p><p>The <strong>existing buttons will be deprecated and removed</strong> in future releases. Upgrade to Smart&nbsp;Payment&nbsp;Buttons in the <a href="%s">PayPal&nbsp;Express&nbsp;Checkout settings</a>.</p>', 'woocommerce-gateway-paypal-express-checkout' ), esc_url( $setting_link ) );
241
+ ?>
242
+ <div class="notice notice-warning is-dismissible ppec-dismiss-spb-notice">
243
+ <?php echo wp_kses( $message, array( 'a' => array( 'href' => array() ), 'strong' => array(), 'p' => array() ) ); ?>
244
+ </div>
245
+ <script>
246
+ ( function( $ ) {
247
+ $( '.ppec-dismiss-spb-notice' ).on( 'click', '.notice-dismiss', function() {
248
+ jQuery.post( "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", {
249
+ action: "ppec_dismiss_notice_message",
250
+ dismiss_action: "ppec_dismiss_spb_notice",
251
+ nonce: "<?php echo esc_js( wp_create_nonce( 'ppec_dismiss_notice' ) ); ?>"
252
+ } );
253
+ } );
254
+ } )( jQuery );
255
+ </script>
256
+ <?php
257
+ }
258
+ }
259
+
260
  /**
261
  * AJAX handler for dismiss notice action.
262
  *
276
  case 'ppec_dismiss_prompt_to_connect':
277
  update_option( 'wc_gateway_ppec_prompt_to_connect_message_dismissed', 'yes' );
278
  break;
279
+ case 'ppec_dismiss_spb_notice':
280
+ update_option( 'wc_gateway_ppec_spb_notice_dismissed', 'yes' );
281
+ break;
282
  }
283
  wp_die();
284
  }
338
  protected function _run() {
339
  require_once( $this->includes_path . 'functions.php' );
340
  $this->_load_handlers();
341
+ add_action( 'admin_notices', array( $this, 'show_spb_notice' ) );
342
  }
343
 
344
  /**
includes/class-wc-gateway-ppec-with-spb.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly
5
+ }
6
+
7
+ class WC_Gateway_PPEC_With_SPB extends WC_Gateway_PPEC {
8
+ public function __construct() {
9
+ $this->id = 'ppec_paypal';
10
+ $this->icon = 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/pp-acceptance-small.png';
11
+
12
+ parent::__construct();
13
+
14
+ add_action( 'woocommerce_review_order_after_submit', array( $this, 'display_paypal_button' ) );
15
+ add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );
16
+ }
17
+
18
+ /**
19
+ * Display PayPal button on the checkout page order review.
20
+ */
21
+ public function display_paypal_button() {
22
+ ?>
23
+ <div id="woo_pp_ec_button_checkout"></div>
24
+ <?php
25
+ }
26
+
27
+ /**
28
+ * Output script for conditionally showing Smart Payment Buttons on regular checkout.
29
+ *
30
+ * @since 1.6.0
31
+ */
32
+ public function payment_scripts() {
33
+ if ( ! wc_gateway_ppec()->checkout->has_active_session() ) {
34
+ wp_enqueue_script( 'wc-gateway-ppec-order-review', wc_gateway_ppec()->plugin_url . 'assets/js/wc-gateway-ppec-order-review.js', array( 'jquery' ), wc_gateway_ppec()->version, true );
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Save data necessary for authorizing payment to session, in order to
40
+ * go ahead with processing payment and bypass redirecting to PayPal.
41
+ *
42
+ * @param int $order_id Order ID
43
+ *
44
+ * @return array
45
+ */
46
+ public function process_payment( $order_id ) {
47
+ if ( isset( $_POST['payerID'] ) && isset( $_POST['paymentToken'] ) ) {
48
+ $session = WC()->session->get( 'paypal' );
49
+
50
+ $session->checkout_completed = true;
51
+ $session->payer_id = $_POST['payerID'];
52
+ $session->token = $_POST['paymentToken'];
53
+
54
+ WC()->session->set( 'paypal', $session );
55
+ }
56
+
57
+ return parent::process_payment( $order_id );
58
+ }
59
+
60
+ }
includes/functions.php CHANGED
@@ -77,8 +77,7 @@ function wc_gateway_ppec_log( $message ) {
77
  */
78
  function wc_gateway_ppec_is_credit_supported() {
79
  $base = wc_get_base_location();
80
-
81
- return 'US' === $base['country'];
82
  }
83
 
84
  /**
77
  */
78
  function wc_gateway_ppec_is_credit_supported() {
79
  $base = wc_get_base_location();
80
+ return 'US' === $base['country'] && 'USD' === get_woocommerce_currency();
 
81
  }
82
 
83
  /**
includes/settings/settings-ppec.php CHANGED
@@ -45,9 +45,11 @@ if ( $enable_ips && $needs_sandbox_creds ) {
45
 
46
  $credit_enabled_label = __( 'Enable PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' );
47
  if ( ! wc_gateway_ppec_is_credit_supported() ) {
48
- $credit_enabled_label .= '<p><em>' . __( 'This option is disabled. Currently PayPal Credit only available for U.S. merchants.', 'woocommerce-gateway-paypal-express-checkout' ) . '</em></p>';
49
  }
50
 
 
 
51
  wc_enqueue_js( "
52
  jQuery( function( $ ) {
53
  var ppec_mark_fields = '#woocommerce_ppec_paypal_title, #woocommerce_ppec_paypal_description';
@@ -107,13 +109,148 @@ wc_enqueue_js( "
107
  e.preventDefault();
108
  } );
109
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  });
111
  " );
112
 
113
  /**
114
  * Settings for PayPal Gateway.
115
  */
116
- return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
117
  'enabled' => array(
118
  'title' => __( 'Enable/Disable', 'woocommerce-gateway-paypal-express-checkout' ),
119
  'type' => 'checkbox',
@@ -127,7 +264,7 @@ return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
127
  'title' => __( 'Title', 'woocommerce-gateway-paypal-express-checkout' ),
128
  'type' => 'text',
129
  'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout' ),
130
- 'default' => __( 'PayPal Express Checkout', 'woocommerce-gateway-paypal-express-checkout' ),
131
  'desc_tip' => true,
132
  ),
133
  'description' => array(
@@ -240,10 +377,10 @@ return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
240
  'placeholder' => __( 'Optional', 'woocommerce-gateway-paypal-express-checkout' ),
241
  ),
242
 
243
- 'display_settings' => array(
244
- 'title' => __( 'Display Settings', 'woocommerce-gateway-paypal-express-checkout' ),
245
  'type' => 'title',
246
- 'description' => __( 'Customize the appearance of Express Checkout in your store.', 'woocommerce-gateway-paypal-express-checkout' ),
247
  ),
248
  'brand_name' => array(
249
  'title' => __( 'Brand Name', 'woocommerce-gateway-paypal-express-checkout' ),
@@ -252,35 +389,6 @@ return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
252
  'default' => get_bloginfo( 'name', 'display' ),
253
  'desc_tip' => true,
254
  ),
255
- 'button_size' => array(
256
- 'title' => __( 'Button Size', 'woocommerce-gateway-paypal-express-checkout' ),
257
- 'type' => 'select',
258
- 'class' => 'wc-enhanced-select',
259
- 'description' => __( 'PayPal offers different sizes of the "PayPal Checkout" buttons, allowing you to select a size that best fits your site\'s theme. This setting will allow you to choose which size button(s) appear on your cart page.', 'woocommerce-gateway-paypal-express-checkout' ),
260
- 'default' => 'large',
261
- 'desc_tip' => true,
262
- 'options' => array(
263
- 'small' => __( 'Small', 'woocommerce-gateway-paypal-express-checkout' ),
264
- 'medium' => __( 'Medium', 'woocommerce-gateway-paypal-express-checkout' ),
265
- 'large' => __( 'Large', 'woocommerce-gateway-paypal-express-checkout' ),
266
- ),
267
- ),
268
- 'cart_checkout_enabled' => array(
269
- 'title' => __( 'Checkout on cart page', 'woocommerce-gateway-paypal-express-checkout' ),
270
- 'type' => 'checkbox',
271
- 'label' => __( 'Enable PayPal checkout on the cart page', 'woocommerce-gateway-paypal-express-checkout' ),
272
- 'description' => __( 'This shows or hides the PayPal checkout button on the cart page.', 'woocommerce-gateway-paypal-express-checkout' ),
273
- 'desc_tip' => true,
274
- 'default' => 'yes',
275
- ),
276
- 'mark_enabled' => array(
277
- 'title' => __( 'PayPal Mark', 'woocommerce-gateway-paypal-express-checkout' ),
278
- 'type' => 'checkbox',
279
- 'label' => __( 'Enable the PayPal Mark on regular checkout', 'woocommerce-gateway-paypal-express-checkout' ),
280
- 'description' => __( 'This enables the PayPal mark, which can be shown on regular WooCommerce checkout to use PayPal Express Checkout like a regular WooCommerce gateway.', 'woocommerce-gateway-paypal-express-checkout' ),
281
- 'desc_tip' => true,
282
- 'default' => 'no',
283
- ),
284
  'logo_image_url' => array(
285
  'title' => __( 'Logo Image (190×60)', 'woocommerce-gateway-paypal-express-checkout' ),
286
  'type' => 'image',
@@ -317,22 +425,6 @@ return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
317
  'Login' => _x( 'Login (PayPal account login)', 'Type of PayPal page', 'woocommerce-gateway-paypal-express-checkout' ),
318
  ),
319
  ),
320
- 'credit_enabled' => array(
321
- 'title' => __( 'Enable PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ),
322
- 'type' => 'checkbox',
323
- 'label' => $credit_enabled_label,
324
- 'disabled' => ! wc_gateway_ppec_is_credit_supported(),
325
- 'default' => 'no',
326
- 'desc_tip' => true,
327
- 'description' => __( 'This enables PayPal Credit, which displays a PayPal Credit button next to the Express Checkout button. PayPal Express Checkout lets you give customers access to financing through PayPal Credit® - at no additional cost to you. You get paid up front, even though customers have more time to pay. A pre-integrated payment button shows up next to the PayPal Button, and lets customers pay quickly with PayPal Credit®.', 'woocommerce-gateway-paypal-express-checkout' ),
328
- ),
329
- 'checkout_on_single_product_enabled' => array(
330
- 'title' => __( 'Checkout on Single Product', 'woocommerce-gateway-paypal-express-checkout' ),
331
- 'type' => 'checkbox',
332
- 'label' => __( 'Checkout on Single Product', 'woocommerce-gateway-paypal-express-checkout' ),
333
- 'default' => 'no',
334
- 'description' => __( 'Enable Express checkout on Single Product view.', 'woocommerce-gateway-paypal-express-checkout' ),
335
- ),
336
 
337
  'advanced' => array(
338
  'title' => __( 'Advanced Settings', 'woocommerce-gateway-paypal-express-checkout' ),
@@ -400,4 +492,202 @@ return apply_filters( 'woocommerce_paypal_express_checkout_settings', array(
400
  'drop' => __( 'Do not send line items to PayPal', 'woocommerce-gateway-paypal-express-checkout' ),
401
  ),
402
  ),
403
- ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  $credit_enabled_label = __( 'Enable PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' );
47
  if ( ! wc_gateway_ppec_is_credit_supported() ) {
48
+ $credit_enabled_label .= '<p><em>' . __( 'This option is disabled. Currently PayPal Credit only available for U.S. merchants using USD currency.', 'woocommerce-gateway-paypal-express-checkout' ) . '</em></p>';
49
  }
50
 
51
+ $credit_enabled_description = __( 'This enables PayPal Credit, which displays a PayPal Credit button next to the Express Checkout button. PayPal Express Checkout lets you give customers access to financing through PayPal Credit® - at no additional cost to you. You get paid up front, even though customers have more time to pay. A pre-integrated payment button shows up next to the PayPal Button, and lets customers pay quickly with PayPal Credit®. (Should be unchecked for stores involved in Real Money Gaming.)', 'woocommerce-gateway-paypal-express-checkout' );
52
+
53
  wc_enqueue_js( "
54
  jQuery( function( $ ) {
55
  var ppec_mark_fields = '#woocommerce_ppec_paypal_title, #woocommerce_ppec_paypal_description';
109
  e.preventDefault();
110
  } );
111
  }
112
+
113
+ $( '.woocommerce_ppec_paypal_button_layout' ).change( function( event ) {
114
+ if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) {
115
+ return;
116
+ }
117
+
118
+ // Show settings that pertain to selected layout in same section
119
+ var isVertical = 'vertical' === $( event.target ).val();
120
+ var table = $( event.target ).closest( 'table' );
121
+ table.find( '.woocommerce_ppec_paypal_vertical' ).closest( 'tr' ).toggle( isVertical );
122
+ table.find( '.woocommerce_ppec_paypal_horizontal' ).closest( 'tr' ).toggle( ! isVertical );
123
+
124
+ // Disable 'small' button size option in vertical layout only
125
+ var button_size = table.find( '.woocommerce_ppec_paypal_button_size' );
126
+ var button_size_option = button_size.find( 'option[value=\"small\"]' );
127
+ if ( button_size_option.prop( 'disabled' ) !== isVertical ) {
128
+ button_size.removeClass( 'enhanced' )
129
+ button_size_option.prop( 'disabled', isVertical );
130
+ $( document.body ).trigger( 'wc-enhanced-select-init' );
131
+ ! button_size.val() && button_size.val( 'responsive' ).change();
132
+ }
133
+ } ).change();
134
+
135
+ // Hide default layout and size settings if they'll be overridden anyway.
136
+ function showHideDefaultButtonSettings() {
137
+ var display =
138
+ $( '#woocommerce_ppec_paypal_cart_checkout_enabled' ).is( ':checked' ) ||
139
+ ( $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled' ).is( ':checked' ) && ! $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).is( ':checked' ) ) ||
140
+ ( $( '#woocommerce_ppec_paypal_mark_enabled' ).is( ':checked' ) && ! $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).is( ':checked' ) );
141
+
142
+ $( '#woocommerce_ppec_paypal_button_layout, #woocommerce_ppec_paypal_button_size, #woocommerce_ppec_paypal_hide_funding_methods, #woocommerce_ppec_paypal_credit_enabled' ).closest( 'tr' ).toggle( display );
143
+ display && $( '#woocommerce_ppec_paypal_button_layout' ).change();
144
+ }
145
+
146
+ // Toggle mini-cart section based on whether checkout on cart page is enabled
147
+ $( '#woocommerce_ppec_paypal_cart_checkout_enabled' ).change( function( event ) {
148
+ if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) {
149
+ return;
150
+ }
151
+
152
+ var checked = $( event.target ).is( ':checked' );
153
+ $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle, .woocommerce_ppec_paypal_mini_cart' )
154
+ .closest( 'tr' )
155
+ .add( '#woocommerce_ppec_paypal_mini_cart_settings' ) // Select title.
156
+ .next( 'p' ) // Select description if present.
157
+ .addBack()
158
+ .toggle( checked );
159
+ checked && $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle' ).change();
160
+ showHideDefaultButtonSettings();
161
+ } ).change();
162
+
163
+ $( '#woocommerce_ppec_paypal_mini_cart_settings_toggle' ).change( function( event ) {
164
+ // Only show settings specific to mini-cart if configured to override global settings.
165
+ var checked = $( event.target ).is( ':checked' );
166
+ $( '.woocommerce_ppec_paypal_mini_cart' ).closest( 'tr' ).toggle( checked );
167
+ checked && $( '#woocommerce_ppec_paypal_mini_cart_button_layout' ).change();
168
+ showHideDefaultButtonSettings();
169
+ } ).change();
170
+
171
+ $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled, #woocommerce_ppec_paypal_single_product_settings_toggle' ).change( function( event ) {
172
+ if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) {
173
+ return;
174
+ }
175
+
176
+ if ( ! $( '#woocommerce_ppec_paypal_checkout_on_single_product_enabled' ).is( ':checked' ) ) {
177
+ // If product page button is disabled, hide remaining settings in section.
178
+ $( '#woocommerce_ppec_paypal_single_product_settings_toggle, .woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).hide();
179
+ } else if ( ! $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).is( ':checked' ) ) {
180
+ // If product page button is enabled but not configured to override global settings, hide remaining settings in section.
181
+ $( '#woocommerce_ppec_paypal_single_product_settings_toggle' ).closest( 'tr' ).show();
182
+ $( '.woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).hide();
183
+ } else {
184
+ // Show all settings in section.
185
+ $( '#woocommerce_ppec_paypal_single_product_settings_toggle, .woocommerce_ppec_paypal_single_product' ).closest( 'tr' ).show();
186
+ $( '#woocommerce_ppec_paypal_single_product_button_layout' ).change();
187
+ }
188
+ showHideDefaultButtonSettings();
189
+ } ).change();
190
+
191
+ $( '#woocommerce_ppec_paypal_mark_enabled, #woocommerce_ppec_paypal_mark_settings_toggle' ).change( function() {
192
+ if ( ! $( '#woocommerce_ppec_paypal_use_spb' ).is( ':checked' ) ) {
193
+ return;
194
+ }
195
+
196
+ if ( ! $( '#woocommerce_ppec_paypal_mark_enabled' ).is( ':checked' ) ) {
197
+ // If checkout page button is disabled, hide remaining settings in section.
198
+ $( '#woocommerce_ppec_paypal_mark_settings_toggle, .woocommerce_ppec_paypal_mark' ).closest( 'tr' ).hide();
199
+ } else if ( ! $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).is( ':checked' ) ) {
200
+ // If checkout page button is enabled but not configured to override global settings, hide remaining settings in section.
201
+ $( '#woocommerce_ppec_paypal_mark_settings_toggle' ).closest( 'tr' ).show();
202
+ $( '.woocommerce_ppec_paypal_mark' ).closest( 'tr' ).hide();
203
+ } else {
204
+ // Show all settings in section.
205
+ $( '#woocommerce_ppec_paypal_mark_settings_toggle, .woocommerce_ppec_paypal_mark' ).closest( 'tr' ).show();
206
+ $( '#woocommerce_ppec_paypal_mark_button_layout' ).change();
207
+ }
208
+ showHideDefaultButtonSettings();
209
+ } ).change();
210
+
211
+ // Make sure handlers are only attached once if script is loaded multiple times.
212
+ $( '#woocommerce_ppec_paypal_use_spb' ).off( 'change' );
213
+
214
+ $( '#woocommerce_ppec_paypal_use_spb' ).change( function( event ) {
215
+ var checked = $( event.target ).is( ':checked' );
216
+
217
+ // Show settings specific to Smart Payment Buttons only if enabled.
218
+ $( '.woocommerce_ppec_paypal_spb' ).not( 'h3 ').closest( 'tr' ).toggle( checked );
219
+ $( '.woocommerce_ppec_paypal_spb' ).filter( 'h3' ).next( 'p' ).addBack().toggle( checked );
220
+
221
+ if ( checked ) {
222
+ // Trigger all logic that controls visibility of other settings.
223
+ $( '.woocommerce_ppec_paypal_visibility_toggle' ).change();
224
+ } else {
225
+ // If non-SPB mode is enabled, show all settings that may have been hidden.
226
+ $( '#woocommerce_ppec_paypal_button_size, #woocommerce_ppec_paypal_credit_enabled' ).closest( 'tr' ).show();
227
+ }
228
+
229
+ // Hide 'Responsive' button size option in SPB mode, and make sure to show 'Small' option.
230
+ var button_size = $( '#woocommerce_ppec_paypal_button_size' ).removeClass( 'enhanced' );
231
+ button_size.find( 'option[value=\"responsive\"]' ).prop( 'disabled', ! checked );
232
+ ! checked && button_size.find( 'option[value=\"small\"]' ).prop( 'disabled', false );
233
+ $( document.body ).trigger( 'wc-enhanced-select-init' );
234
+ } ).change();
235
+
236
+ // Reset button size values to default when switching modes.
237
+ $( '#woocommerce_ppec_paypal_use_spb' ).change( function( event ) {
238
+ if ( $( event.target ).is( ':checked' ) ) {
239
+ // In SPB mode, set to recommended 'Responsive' value so it is not missed.
240
+ $( '#woocommerce_ppec_paypal_button_size' ).val( 'responsive' ).change();
241
+ } else if ( ! $( '#woocommerce_ppec_paypal_button_size' ).val() ) {
242
+ // Set back to original default for non-SPB mode.
243
+ $( '#woocommerce_ppec_paypal_button_size' ).val( 'large' ).change();
244
+ }
245
+ } );
246
+
247
  });
248
  " );
249
 
250
  /**
251
  * Settings for PayPal Gateway.
252
  */
253
+ $settings = array(
254
  'enabled' => array(
255
  'title' => __( 'Enable/Disable', 'woocommerce-gateway-paypal-express-checkout' ),
256
  'type' => 'checkbox',
264
  'title' => __( 'Title', 'woocommerce-gateway-paypal-express-checkout' ),
265
  'type' => 'text',
266
  'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-paypal-express-checkout' ),
267
+ 'default' => __( 'PayPal', 'woocommerce-gateway-paypal-express-checkout' ),
268
  'desc_tip' => true,
269
  ),
270
  'description' => array(
377
  'placeholder' => __( 'Optional', 'woocommerce-gateway-paypal-express-checkout' ),
378
  ),
379
 
380
+ 'paypal_hosted_settings' => array(
381
+ 'title' => __( 'PayPal-hosted Checkout Settings', 'woocommerce-gateway-paypal-express-checkout' ),
382
  'type' => 'title',
383
+ 'description' => __( 'Customize the appearance of Express Checkout on the PayPal side.', 'woocommerce-gateway-paypal-express-checkout' ),
384
  ),
385
  'brand_name' => array(
386
  'title' => __( 'Brand Name', 'woocommerce-gateway-paypal-express-checkout' ),
389
  'default' => get_bloginfo( 'name', 'display' ),
390
  'desc_tip' => true,
391
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  'logo_image_url' => array(
393
  'title' => __( 'Logo Image (190×60)', 'woocommerce-gateway-paypal-express-checkout' ),
394
  'type' => 'image',
425
  'Login' => _x( 'Login (PayPal account login)', 'Type of PayPal page', 'woocommerce-gateway-paypal-express-checkout' ),
426
  ),
427
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
 
429
  'advanced' => array(
430
  'title' => __( 'Advanced Settings', 'woocommerce-gateway-paypal-express-checkout' ),
492
  'drop' => __( 'Do not send line items to PayPal', 'woocommerce-gateway-paypal-express-checkout' ),
493
  ),
494
  ),
495
+
496
+ 'button_settings' => array(
497
+ 'title' => __( 'Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
498
+ 'type' => 'title',
499
+ 'description' => __( 'Customize the appearance of Express Checkout on your site.', 'woocommerce-gateway-paypal-express-checkout' ),
500
+ ),
501
+ 'use_spb' => array(
502
+ 'title' => __( 'Smart Payment Buttons', 'woocommerce-gateway-paypal-express-checkout' ),
503
+ 'type' => 'checkbox',
504
+ 'default' => $this->get_option( 'button_size' ) ? 'no' : 'yes', // A 'button_size' value having been set indicates that settings have been initialized before, requiring merchant opt-in to SPB.
505
+ 'label' => __( 'Use Smart Payment Buttons', 'woocommerce-gateway-paypal-express-checkout' ),
506
+ 'description' => sprintf( __( 'Express Checkout\'s Smart Payment Buttons provide a variety of button customization options, such as color, language, shape, and multiple button layout. <a href="%s">Learn more about Smart Payment Buttons</a>.', 'woocommerce-gateway-paypal-express-checkout' ), 'https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/#smart-payment-buttons' ),
507
+ ),
508
+ 'button_color' => array(
509
+ 'title' => __( 'Button Color', 'woocommerce-gateway-paypal-express-checkout' ),
510
+ 'type' => 'select',
511
+ 'class' => 'wc-enhanced-select woocommerce_ppec_paypal_spb',
512
+ 'default' => 'gold',
513
+ 'desc_tip' => true,
514
+ 'description' => __( 'Controls the background color of the primary button. Use "Gold" to leverage PayPal\'s recognition and preference, or change it to match your site design or aesthetic.', 'woocommerce-gateway-paypal-express-checkout' ),
515
+ 'options' => array(
516
+ 'gold' => __( 'Gold (Recommended)', 'woocommerce-gateway-paypal-express-checkout' ),
517
+ 'blue' => __( 'Blue', 'woocommerce-gateway-paypal-express-checkout' ),
518
+ 'silver' => __( 'Silver', 'woocommerce-gateway-paypal-express-checkout' ),
519
+ 'black' => __( 'Black', 'woocommerce-gateway-paypal-express-checkout' ),
520
+ ),
521
+ ),
522
+ 'button_shape' => array(
523
+ 'title' => __( 'Button Shape', 'woocommerce-gateway-paypal-express-checkout' ),
524
+ 'type' => 'select',
525
+ 'class' => 'wc-enhanced-select woocommerce_ppec_paypal_spb',
526
+ 'default' => 'rect',
527
+ 'desc_tip' => true,
528
+ 'description' => __( 'The pill-shaped button\'s unique and powerful shape signifies PayPal in people\'s minds. Use the rectangular button as an alternative when pill-shaped buttons might pose design challenges.', 'woocommerce-gateway-paypal-express-checkout' ),
529
+ 'options' => array(
530
+ 'pill' => __( 'Pill', 'woocommerce-gateway-paypal-express-checkout' ),
531
+ 'rect' => __( 'Rectangle', 'woocommerce-gateway-paypal-express-checkout' ),
532
+ ),
533
+ ),
534
+ );
535
+
536
+ /**
537
+ * Settings that are copied to context-specific sections.
538
+ */
539
+ $per_context_settings = array(
540
+ 'button_layout' => array(
541
+ 'title' => __( 'Button Layout', 'woocommerce-gateway-paypal-express-checkout' ),
542
+ 'type' => 'select',
543
+ 'class' => 'wc-enhanced-select woocommerce_ppec_paypal_spb woocommerce_ppec_paypal_button_layout',
544
+ 'default' => 'vertical',
545
+ 'desc_tip' => true,
546
+ 'description' => __( 'If additional funding sources are available to the buyer through PayPal, such as Venmo, then multiple buttons are displayed in the space provided. Choose "vertical" for a dynamic list of alternative and local payment options, or "horizontal" when space is limited.', 'woocommerce-gateway-paypal-express-checkout' ),
547
+ 'options' => array(
548
+ 'vertical' => __( 'Vertical', 'woocommerce-gateway-paypal-express-checkout' ),
549
+ 'horizontal' => __( 'Horizontal', 'woocommerce-gateway-paypal-express-checkout' ),
550
+ ),
551
+ ),
552
+ 'button_size' => array(
553
+ 'title' => __( 'Button Size', 'woocommerce-gateway-paypal-express-checkout' ),
554
+ 'type' => 'select',
555
+ 'class' => 'wc-enhanced-select woocommerce_ppec_paypal_button_size',
556
+ 'default' => 'yes' === $this->get_option( 'use_spb', 'yes' ) ? 'responsive' : 'large',
557
+ 'desc_tip' => true,
558
+ 'description' => __( 'PayPal offers different sizes of the "PayPal Checkout" buttons, allowing you to select a size that best fits your site\'s theme. This setting will allow you to choose which size button(s) appear on your cart page. (The "Responsive" option adjusts to container size, and is available and recommended for Smart Payment Buttons.)', 'woocommerce-gateway-paypal-express-checkout' ),
559
+ 'options' => array(
560
+ 'responsive' => __( 'Responsive', 'woocommerce-gateway-paypal-express-checkout' ),
561
+ 'small' => __( 'Small', 'woocommerce-gateway-paypal-express-checkout' ),
562
+ 'medium' => __( 'Medium', 'woocommerce-gateway-paypal-express-checkout' ),
563
+ 'large' => __( 'Large', 'woocommerce-gateway-paypal-express-checkout' ),
564
+ ),
565
+ ),
566
+ 'hide_funding_methods' => array(
567
+ 'title' => 'Hide Funding Method(s)',
568
+ 'type' => 'multiselect',
569
+ 'class' => 'wc-enhanced-select woocommerce_ppec_paypal_spb woocommerce_ppec_paypal_vertical',
570
+ 'default' => array( 'CARD' ),
571
+ 'desc_tip' => true,
572
+ 'description' => __( 'Hides the specified funding methods.', 'woocommerce-gateway-paypal-express-checkout' ),
573
+ 'options' => array(
574
+ 'CREDIT' => __( 'PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ),
575
+ 'ELV' => __( 'ELV', 'woocommerce-gateway-paypal-express-checkout' ),
576
+ 'CARD' => __( 'Credit Card', 'woocommerce-gateway-paypal-express-checkout' ),
577
+ ),
578
+ ),
579
+ 'credit_enabled' => array(
580
+ 'title' => __( 'Enable PayPal Credit', 'woocommerce-gateway-paypal-express-checkout' ),
581
+ 'type' => 'checkbox',
582
+ 'label' => $credit_enabled_label,
583
+ 'disabled' => ! wc_gateway_ppec_is_credit_supported(),
584
+ 'class' => 'woocommerce_ppec_paypal_horizontal',
585
+ 'default' => 'no',
586
+ 'desc_tip' => true,
587
+ 'description' => __( 'This enables PayPal Credit, which displays a PayPal Credit button together with the PayPal Checkout button if the buyer is eligible. PayPal Express Checkout lets you give customers access to financing through PayPal Credit® - at no additional cost to you. You get paid up front, even though customers have more time to pay. A pre-integrated payment button shows up next to the PayPal Button, and lets customers pay quickly with PayPal Credit®.', 'woocommerce-gateway-paypal-express-checkout' ),
588
+ ),
589
+ );
590
+
591
+ /**
592
+ * Cart / global button settings.
593
+ */
594
+ $settings = array_merge( $settings, $per_context_settings );
595
+ $per_context_settings['button_size']['class'] .= ' woocommerce_ppec_paypal_spb';
596
+ $per_context_settings['credit_enabled']['class'] .= ' woocommerce_ppec_paypal_spb';
597
+
598
+ $settings['cart_checkout_enabled'] = array(
599
+ 'title' => __( 'Checkout on cart page', 'woocommerce-gateway-paypal-express-checkout' ),
600
+ 'type' => 'checkbox',
601
+ 'class' => 'woocommerce_ppec_paypal_visibility_toggle',
602
+ 'label' => __( 'Enable PayPal checkout on the cart page', 'woocommerce-gateway-paypal-express-checkout' ),
603
+ 'description' => __( 'This shows or hides the PayPal checkout button on the cart page.', 'woocommerce-gateway-paypal-express-checkout' ),
604
+ 'desc_tip' => true,
605
+ 'default' => 'yes',
606
+ );
607
+
608
+ /**
609
+ * Mini-cart button settings.
610
+ */
611
+ $settings['mini_cart_settings'] = array(
612
+ 'title' => __( 'Mini-cart Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
613
+ 'type' => 'title',
614
+ 'class' => 'woocommerce_ppec_paypal_spb',
615
+ );
616
+ $settings['mini_cart_settings_toggle'] = array(
617
+ 'title' => __( 'Configure Settings', 'woocommerce-gateway-paypal-express-checkout' ),
618
+ 'label' => __( 'Configure settings specific to mini-cart', 'woocommerce-gateway-paypal-express-checkout' ),
619
+ 'type' => 'checkbox',
620
+ 'class' => 'woocommerce_ppec_paypal_spb woocommerce_ppec_paypal_visibility_toggle',
621
+ 'default' => 'no',
622
+ 'desc_tip' => true,
623
+ 'description' => __( 'Optionally override global button settings above and configure buttons for this context.', 'woocommerce-gateway-paypal-express-checkout' ),
624
+ );
625
+ foreach( $per_context_settings as $key => $value ) {
626
+ $value['class'] .= ' woocommerce_ppec_paypal_mini_cart';
627
+ $settings[ 'mini_cart_' . $key ] = $value;
628
+ }
629
+
630
+ /**
631
+ * Single product button settings.
632
+ */
633
+ $settings['single_product_settings'] = array(
634
+ 'title' => __( 'Single Product Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
635
+ 'type' => 'title',
636
+ 'class' => 'woocommerce_ppec_paypal_spb',
637
+ );
638
+ $settings['checkout_on_single_product_enabled'] = array(
639
+ 'title' => __( 'Checkout on Single Product', 'woocommerce-gateway-paypal-express-checkout' ),
640
+ 'type' => 'checkbox',
641
+ 'class' => 'woocommerce_ppec_paypal_visibility_toggle',
642
+ 'label' => __( 'Checkout on Single Product', 'woocommerce-gateway-paypal-express-checkout' ),
643
+ 'default' => 'yes',
644
+ 'desc_tip' => true,
645
+ 'description' => __( 'Enable Express checkout on Single Product view.', 'woocommerce-gateway-paypal-express-checkout' ),
646
+ );
647
+ $settings['single_product_settings_toggle'] = array(
648
+ 'title' => __( 'Configure Settings', 'woocommerce-gateway-paypal-express-checkout' ),
649
+ 'label' => __( 'Configure settings specific to Single Product view', 'woocommerce-gateway-paypal-express-checkout' ),
650
+ 'type' => 'checkbox',
651
+ 'class' => 'woocommerce_ppec_paypal_spb woocommerce_ppec_paypal_visibility_toggle',
652
+ 'default' => 'yes',
653
+ 'desc_tip' => true,
654
+ 'description' => __( 'Optionally override global button settings above and configure buttons for this context.', 'woocommerce-gateway-paypal-express-checkout' ),
655
+ );
656
+ foreach( $per_context_settings as $key => $value ) {
657
+ $value['class'] .= ' woocommerce_ppec_paypal_single_product';
658
+ $settings[ 'single_product_' . $key ] = $value;
659
+ }
660
+ $settings['single_product_button_layout']['default'] = 'horizontal';
661
+
662
+ /**
663
+ * Regular checkout button settings.
664
+ */
665
+ $settings['mark_settings'] = array(
666
+ 'title' => __( 'Regular Checkout Button Settings', 'woocommerce-gateway-paypal-express-checkout' ),
667
+ 'type' => 'title',
668
+ 'class' => 'woocommerce_ppec_paypal_spb',
669
+ );
670
+ $settings['mark_enabled'] = array(
671
+ 'title' => __( 'PayPal Mark', 'woocommerce-gateway-paypal-express-checkout' ),
672
+ 'type' => 'checkbox',
673
+ 'class' => 'woocommerce_ppec_paypal_visibility_toggle',
674
+ 'label' => __( 'Enable the PayPal Mark on regular checkout', 'woocommerce-gateway-paypal-express-checkout' ),
675
+ 'description' => __( 'This enables the PayPal mark, which can be shown on regular WooCommerce checkout to use PayPal Express Checkout like a regular WooCommerce gateway.', 'woocommerce-gateway-paypal-express-checkout' ),
676
+ 'desc_tip' => true,
677
+ 'default' => 'yes',
678
+ );
679
+ $settings['mark_settings_toggle'] = array(
680
+ 'title' => __( 'Configure Settings', 'woocommerce-gateway-paypal-express-checkout' ),
681
+ 'label' => __( 'Configure settings specific to regular checkout', 'woocommerce-gateway-paypal-express-checkout' ),
682
+ 'type' => 'checkbox',
683
+ 'class' => 'woocommerce_ppec_paypal_spb woocommerce_ppec_paypal_visibility_toggle',
684
+ 'default' => 'no',
685
+ 'desc_tip' => true,
686
+ 'description' => __( 'Optionally override global button settings above and configure buttons for this context.', 'woocommerce-gateway-paypal-express-checkout' ),
687
+ );
688
+ foreach( $per_context_settings as $key => $value ) {
689
+ $value['class'] .= ' woocommerce_ppec_paypal_mark';
690
+ $settings[ 'mark_' . $key ] = $value;
691
+ }
692
+
693
+ return apply_filters( 'woocommerce_paypal_express_checkout_settings', $settings );
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey, fullysupportedphil, dsmithweb, corsonr, bor0, zandyring
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
4
  Requires at least: 4.4
5
- Tested up to: 4.9.0
6
- Stable tag: 1.5.6
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -87,12 +87,26 @@ Please use this to inform us about bugs, or make contributions via PRs.
87
 
88
  == Screenshots ==
89
 
90
- 1. Click the "Click Here to Set Up Your PayPal Account" button. If you want to test before goes live, you can switch the Environment, above the button, to Sandbox.
91
- 2. API credentials will be set after Easy Setup. Or, you can set that manually.
92
- 3. Checkout with PayPal directly from the Cart.
 
 
 
 
 
 
93
 
94
  == Changelog ==
95
 
 
 
 
 
 
 
 
 
96
  = 1.5.6 - 2018-06-06 =
97
  * Fix - Virtual products cause issues with billing details validation.
98
 
2
  Contributors: automattic, woothemes, akeda, dwainm, royho, allendav, slash1andy, woosteve, spraveenitpro, mikedmoore, fernashes, shellbeezy, danieldudzic, mikaey, fullysupportedphil, dsmithweb, corsonr, bor0, zandyring
3
  Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal
4
  Requires at least: 4.4
5
+ Tested up to: 4.9.6
6
+ Stable tag: 1.6.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
87
 
88
  == Screenshots ==
89
 
90
+ 1. Click the "Setup or link an existing PayPal account" button. If you want to test before going live, you can switch the Environment, above the button, to Sandbox.
91
+ 2. API credentials will be set after linking, or you can set them manually.
92
+ 3. See PayPal button settings below.
93
+ 4. Checkout with PayPal directly from the Cart.
94
+ 5. And without leaving the store.
95
+ 6. Confirm details after clicking "Continue".
96
+ 7. Choose PayPal from regular checkout page.
97
+ 8. Choose PayPal from single product page.
98
+ 9. Initiate checkout from mini-cart.
99
 
100
  == Changelog ==
101
 
102
+ = 1.6.0 - 2018-06-27 =
103
+ * Add - Smart Payment Buttons mode as alternative to directly embedded image links for all instances of PayPal button.
104
+ * Fix - Help tip alignment for image settings.
105
+ * Update - Enable PayPal Credit by default, and restrict its support by currency.
106
+ * Update - Omit 'Express Checkout' portion of default payment method title.
107
+ * Update - Enable Express Checkout on regular checkout page by default.
108
+ * Update - Enable Express Checkout on single product page by default.
109
+
110
  = 1.5.6 - 2018-06-06 =
111
  * Fix - Virtual products cause issues with billing details validation.
112
 
woocommerce-gateway-paypal-express-checkout.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce PayPal Express Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Express Checkout (https://www.paypal.com/us/webapps/mpp/express-checkout).
6
- * Version: 1.5.6
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2018 WooCommerce / PayPal.
@@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
27
  exit; // Exit if accessed directly
28
  }
29
 
30
- define( 'WC_GATEWAY_PPEC_VERSION', '1.5.6' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.
3
  * Plugin Name: WooCommerce PayPal Express Checkout Gateway
4
  * Plugin URI: https://woocommerce.com/products/woocommerce-gateway-paypal-express-checkout/
5
  * Description: A payment gateway for PayPal Express Checkout (https://www.paypal.com/us/webapps/mpp/express-checkout).
6
+ * Version: 1.6.0
7
  * Author: WooCommerce
8
  * Author URI: https://woocommerce.com
9
  * Copyright: © 2018 WooCommerce / PayPal.
27
  exit; // Exit if accessed directly
28
  }
29
 
30
+ define( 'WC_GATEWAY_PPEC_VERSION', '1.6.0' );
31
 
32
  /**
33
  * Return instance of WC_Gateway_PPEC_Plugin.