Version Description
- Tweak - Updated FAQ that emphasizes this plugin only works in the U.S. currently
- Fix - Updated JS SDK to 2.24.1 which should fixes issue where credit card fields working intermittently
- Tweak - Add filter on credit card icons
- Tweak - Provide default title for cards and PayPal account methods
Download this release
Release Info
Developer | akeda |
Plugin | WooCommerce PayPal Powered by Braintree Payment Gateway |
Version | 1.2.2 |
Comparing to | |
See all releases |
Code changes from version 1.2.1 to 1.2.2
assets/js/cart.js
CHANGED
@@ -1,7 +1,11 @@
|
|
|
|
1 |
jQuery( document ).ready( function( $ ) {
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
|
|
5 |
$( 'body' ).block( {
|
6 |
message: null,
|
7 |
overlayCSS: {
|
@@ -24,32 +28,78 @@ jQuery( document ).ready( function( $ ) {
|
|
24 |
} );
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
|
55 |
-
} );
|
1 |
+
// globals jQuery, paypalBraintreeData, braintree
|
2 |
jQuery( document ).ready( function( $ ) {
|
3 |
|
4 |
+
var integrationRef = null,
|
5 |
+
rendering = false, // state during braintree setup
|
6 |
+
container = paypalBraintreeData.checkoutWithPayPalContainer; // shortcut
|
7 |
|
8 |
+
function onPaymentMethodReceived( paymentData ) {
|
9 |
$( 'body' ).block( {
|
10 |
message: null,
|
11 |
overlayCSS: {
|
28 |
} );
|
29 |
}
|
30 |
|
31 |
+
function onReady( integration ) {
|
32 |
+
integrationRef = integration;
|
33 |
+
rendering = false;
|
34 |
+
};
|
35 |
|
36 |
+
function init() {
|
37 |
+
if ( 'undefined' === typeof braintree ) {
|
38 |
+
return;
|
39 |
+
}
|
40 |
+
|
41 |
+
if ( 'undefined' === typeof paypalBraintreeData || 'undefined' === typeof paypalBraintreeData.token || 'undefined' === typeof paypalBraintreeData.checkoutWithPayPal ) {
|
42 |
+
return;
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( ! paypalBraintreeData.checkoutWithPayPal ) {
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( 0 === $( '#' + container ).length ) {
|
50 |
+
return;
|
51 |
+
}
|
52 |
|
53 |
+
renderButton();
|
54 |
+
|
55 |
+
// Currently there's no one global event that triggered when cart is
|
56 |
+
// udpated, so need to register callback to two events and avoid possible
|
57 |
+
// conflict with flag `rendering`.
|
58 |
+
$( document.body ).on( 'updated_wc_div', onCartUpdated );
|
59 |
+
$( document.body ).on( 'updated_cart_totals', onCartUpdated );
|
60 |
}
|
61 |
|
62 |
+
function renderButton() {
|
63 |
+
var setupArgs = {
|
64 |
+
paypal : {
|
65 |
+
container: container,
|
66 |
+
singleUse: true, // cart checkout must always be single use
|
67 |
+
amount: paypalBraintreeData.checkoutWithPayPal.amount,
|
68 |
+
currency: paypalBraintreeData.checkoutWithPayPal.currency
|
69 |
+
},
|
70 |
+
onReady: onReady,
|
71 |
+
onPaymentMethodReceived: onPaymentMethodReceived
|
72 |
+
};
|
73 |
+
|
74 |
+
rendering = true;
|
75 |
+
braintree.setup( paypalBraintreeData.token, "custom", setupArgs );
|
76 |
}
|
77 |
|
78 |
+
function onCartUpdated() {
|
79 |
+
// A call to setup already made.
|
80 |
+
if ( rendering ) {
|
81 |
+
return;
|
82 |
+
}
|
83 |
+
|
84 |
+
if ( ! integrationRef ) {
|
85 |
+
return;
|
86 |
+
}
|
87 |
+
|
88 |
+
// Teardown old reference.
|
89 |
+
if ( integrationRef && 'function' === typeof integrationRef.teardown ) {
|
90 |
+
integrationRef.teardown( function() {
|
91 |
+
integrationRef = null;
|
92 |
+
} );
|
93 |
+
}
|
94 |
+
|
95 |
+
// Update amount and currency from updated data after cart is udpated.
|
96 |
+
paypalBraintreeData.checkoutWithPayPal.amount = $( '#' + container ).data( 'amount' );
|
97 |
+
paypalBraintreeData.checkoutWithPayPal.currency = $( '#' + container ).data( 'currency' );
|
98 |
+
|
99 |
+
// Rerender the button.
|
100 |
+
renderButton();
|
101 |
+
}
|
102 |
|
103 |
+
init();
|
104 |
|
105 |
+
} );
|
assets/js/checkout.js
CHANGED
@@ -40,7 +40,12 @@ jQuery( document ).ready( function( $ ) {
|
|
40 |
};
|
41 |
|
42 |
function onError( response ) {
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
};
|
45 |
|
46 |
function onCheckoutPlaceOrder() {
|
@@ -83,6 +88,7 @@ jQuery( document ).ready( function( $ ) {
|
|
83 |
currency: paypalBraintreeData.checkoutWithPayPal.currency
|
84 |
},
|
85 |
onReady: onReady,
|
|
|
86 |
onPaymentMethodReceived: onPaymentMethodReceived
|
87 |
} );
|
88 |
};
|
@@ -103,6 +109,7 @@ jQuery( document ).ready( function( $ ) {
|
|
103 |
id: checkoutFormID,
|
104 |
hostedFields: paypalBraintreeData.hostedFields,
|
105 |
onReady: onReady,
|
|
|
106 |
onPaymentMethodReceived: onPaymentMethodReceived
|
107 |
} );
|
108 |
};
|
@@ -214,4 +221,4 @@ jQuery( document ).ready( function( $ ) {
|
|
214 |
|
215 |
setInterval( checkSetup, 250 );
|
216 |
|
217 |
-
} );
|
40 |
};
|
41 |
|
42 |
function onError( response ) {
|
43 |
+
var message = response;
|
44 |
+
if ( response && response.message ) {
|
45 |
+
message = response.message;
|
46 |
+
}
|
47 |
+
|
48 |
+
console.log( 'WooCommerce: PayPal Powered by Braintree: an error occurred:', message );
|
49 |
};
|
50 |
|
51 |
function onCheckoutPlaceOrder() {
|
88 |
currency: paypalBraintreeData.checkoutWithPayPal.currency
|
89 |
},
|
90 |
onReady: onReady,
|
91 |
+
onError: onError,
|
92 |
onPaymentMethodReceived: onPaymentMethodReceived
|
93 |
} );
|
94 |
};
|
109 |
id: checkoutFormID,
|
110 |
hostedFields: paypalBraintreeData.hostedFields,
|
111 |
onReady: onReady,
|
112 |
+
onError: onError,
|
113 |
onPaymentMethodReceived: onPaymentMethodReceived
|
114 |
} );
|
115 |
};
|
221 |
|
222 |
setInterval( checkSetup, 250 );
|
223 |
|
224 |
+
} );
|
classes/class-wc-gateway-paypal-braintree-pay-with-card.php
CHANGED
@@ -7,17 +7,24 @@
|
|
7 |
|
8 |
class WC_Gateway_Paypal_Braintree_Pay_With_Card extends WC_Gateway_Paypal_Braintree {
|
9 |
|
|
|
|
|
|
|
10 |
public function __construct() {
|
11 |
|
12 |
$this->id = 'paypalbraintree_cards';
|
13 |
|
14 |
parent::__construct();
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
$this->checkout_template = 'checkout/paypal-braintree-pay-with-card.php';
|
18 |
$this->title = $this->get_option( 'title_cards' );
|
19 |
$this->description = $this->get_option( 'description_cards' );
|
20 |
|
21 |
}
|
22 |
-
|
23 |
}
|
7 |
|
8 |
class WC_Gateway_Paypal_Braintree_Pay_With_Card extends WC_Gateway_Paypal_Braintree {
|
9 |
|
10 |
+
/**
|
11 |
+
* WC_Gateway_Paypal_Braintree_Pay_With_Card constructor.
|
12 |
+
*/
|
13 |
public function __construct() {
|
14 |
|
15 |
$this->id = 'paypalbraintree_cards';
|
16 |
|
17 |
parent::__construct();
|
18 |
|
19 |
+
/**
|
20 |
+
* Filter the accepted credit card icons for Paypal Powered by Braintree.
|
21 |
+
*
|
22 |
+
* @param string $card_icons_url disployed on the checkout page.
|
23 |
+
*/
|
24 |
+
$this->icon = apply_filters( 'wc_gateway_paypal_braintree_card_icons_image_url', plugins_url( '../assets/images/payments/payment-method-cards.png', __FILE__ ) );
|
25 |
$this->checkout_template = 'checkout/paypal-braintree-pay-with-card.php';
|
26 |
$this->title = $this->get_option( 'title_cards' );
|
27 |
$this->description = $this->get_option( 'description_cards' );
|
28 |
|
29 |
}
|
|
|
30 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic, woothemes, akeda, allendav, royho, slash1andy, woostev
|
|
3 |
Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal, braintree
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 4.5.2
|
6 |
-
Stable tag: 1.2.
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
@@ -63,7 +63,7 @@ Yes!
|
|
63 |
|
64 |
= What currencies can I use? =
|
65 |
|
66 |
-
|
67 |
|
68 |
= Does this support both production mode and sandbox mode for testing? =
|
69 |
|
@@ -100,6 +100,12 @@ New feature requests and bugs reports can be made in the plugin forum.
|
|
100 |
|
101 |
== Changelog ==
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
= 1.2.1 =
|
104 |
* Fix - Issue where Subscriptions with free trial was not processed
|
105 |
* Fix - Missing "Change Payment" button in "My Subscriptions" section
|
3 |
Tags: ecommerce, e-commerce, commerce, woothemes, wordpress ecommerce, store, sales, sell, shop, shopping, cart, checkout, configurable, paypal, braintree
|
4 |
Requires at least: 4.4
|
5 |
Tested up to: 4.5.2
|
6 |
+
Stable tag: 1.2.2
|
7 |
License: GPLv3
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
|
63 |
|
64 |
= What currencies can I use? =
|
65 |
|
66 |
+
PayPal Powered by Braintree for WooCommerce is available in the U.S. only.
|
67 |
|
68 |
= Does this support both production mode and sandbox mode for testing? =
|
69 |
|
100 |
|
101 |
== Changelog ==
|
102 |
|
103 |
+
= 1.2.2 =
|
104 |
+
* Tweak - Updated FAQ that emphasizes this plugin only works in the U.S. currently
|
105 |
+
* Fix - Updated JS SDK to 2.24.1 which should fixes issue where credit card fields working intermittently
|
106 |
+
* Tweak - Add filter on credit card icons
|
107 |
+
* Tweak - Provide default title for cards and PayPal account methods
|
108 |
+
|
109 |
= 1.2.1 =
|
110 |
* Fix - Issue where Subscriptions with free trial was not processed
|
111 |
* Fix - Missing "Change Payment" button in "My Subscriptions" section
|
woocommerce-gateway-paypal-powered-by-braintree.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* Description: Receive payments using Paypal Powered by Braintree. A server with cURL, SSL support, and a valid SSL certificate is required (for security reasons) for this gateway to function. Requires PHP 5.4+
|
6 |
* Author: WooThemes
|
7 |
* Author URI: http://woothemes.com/
|
8 |
-
* Version: 1.2.
|
9 |
*
|
10 |
* Copyright (c) 2016 WooThemes
|
11 |
*
|
@@ -339,9 +339,14 @@ class WC_PayPal_Braintree_Loader {
|
|
339 |
return;
|
340 |
}
|
341 |
|
|
|
|
|
|
|
|
|
|
|
342 |
?>
|
343 |
-
|
344 |
-
|
345 |
<?php
|
346 |
}
|
347 |
|
@@ -396,67 +401,18 @@ class WC_PayPal_Braintree_Loader {
|
|
396 |
}
|
397 |
wp_enqueue_style( 'paypal_braintree_styles' );
|
398 |
|
399 |
-
// See if we should enqueue any JavaScript at all
|
400 |
-
$
|
401 |
-
$
|
402 |
-
$should_enqueue_cart_script = is_cart() && $this->does_checkout_with_paypal_support_shop_currency() && ! $this->does_cart_contain_any_subscriptions();
|
403 |
|
404 |
if ( ! $should_enqueue_cart_script && ! $should_enqueue_checkout_script ) {
|
405 |
return;
|
406 |
}
|
407 |
|
408 |
-
|
409 |
-
|
410 |
-
} else {
|
411 |
-
$postback_class = 'WC_Gateway_Paypal_Braintree_Pay_With_PayPal';
|
412 |
-
}
|
413 |
-
|
414 |
-
// Note: The postback URL is only used for cart initiated Checkout with PayPal flow
|
415 |
-
$details_postback_url = false;
|
416 |
-
if ( $should_enqueue_cart_script ) {
|
417 |
-
$details_postback_url = WC()->api_request_url( $postback_class );
|
418 |
-
$details_postback_url = add_query_arg( 'action', 'checkout_details', $details_postback_url );
|
419 |
-
}
|
420 |
-
|
421 |
-
// Only bother including Checkout with PayPal if the currency is supported
|
422 |
-
// (Checkout with PayPal supports fewer currencies than hosted fields)
|
423 |
-
$checkout_with_paypal = false;
|
424 |
-
if ( $this->does_checkout_with_paypal_support_shop_currency() ) {
|
425 |
-
$checkout_with_paypal = array(
|
426 |
-
'amount' => WC()->cart->total,
|
427 |
-
'currency' => get_woocommerce_currency(),
|
428 |
-
'singleUse' => true,
|
429 |
-
'detailsPostbackURL' => $details_postback_url
|
430 |
-
);
|
431 |
-
}
|
432 |
-
|
433 |
-
// Only bother including hosted fields data if this is a checkout page (not a cart page)
|
434 |
-
$hosted_fields = false;
|
435 |
-
if ( $should_enqueue_checkout_script ) {
|
436 |
-
$hosted_fields = array(
|
437 |
-
'number' => array(
|
438 |
-
'selector' => '#wc-paypal-braintree-card-number',
|
439 |
-
'placeholder' => '0000000000000000'
|
440 |
-
),
|
441 |
-
'cvv' => array(
|
442 |
-
'selector' => '#wc-paypal-braintree-cvv',
|
443 |
-
'placeholder' => 'CVV'
|
444 |
-
),
|
445 |
-
'expirationDate' => array(
|
446 |
-
'selector' => '#wc-paypal-braintree-expiration-date',
|
447 |
-
'placeholder' => 'MM/YY'
|
448 |
-
),
|
449 |
-
'styles' => array(
|
450 |
-
'input' => array(
|
451 |
-
'font-size' => '12pt',
|
452 |
-
'color' => '#3A3A3A',
|
453 |
-
'font-family' => 'monospace'
|
454 |
-
)
|
455 |
-
)
|
456 |
-
);
|
457 |
-
}
|
458 |
|
459 |
-
// Sanity check
|
460 |
if ( ! $checkout_with_paypal && ! $hosted_fields ) {
|
461 |
return;
|
462 |
}
|
@@ -468,15 +424,16 @@ class WC_PayPal_Braintree_Loader {
|
|
468 |
$client_token = $braintree_gateway->clientToken()->generate();
|
469 |
|
470 |
$paypal_braintree_data = array(
|
471 |
-
'token'
|
472 |
-
'checkoutWithPayPal'
|
473 |
-
'
|
|
|
474 |
);
|
475 |
|
476 |
// Allow things like subscriptions to filter the setup (e.g. to set checkoutWithPayPal singleUse to false)
|
477 |
$paypal_braintree_data = apply_filters( 'wc_gateway_paypal_braintree_data', $paypal_braintree_data );
|
478 |
|
479 |
-
wp_register_script( 'paypal_braintree', 'https://js.braintreegateway.com/
|
480 |
if ( $should_enqueue_checkout_script ) {
|
481 |
wp_register_script( 'gateway_paypal_braintree', plugins_url( 'assets/js/checkout.js', __FILE__ ), array( 'jquery', 'paypal_braintree' ) );
|
482 |
} else if ( $should_enqueue_cart_script ) {
|
@@ -488,6 +445,101 @@ class WC_PayPal_Braintree_Loader {
|
|
488 |
|
489 |
}
|
490 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
|
492 |
/**
|
493 |
* Returns true if our gateways are enabled, false otherwise
|
@@ -633,7 +685,7 @@ class WC_PayPal_Braintree_Loader {
|
|
633 |
'title' => __( 'PayPal Title', 'woocommerce-gateway-paypal-braintree' ),
|
634 |
'type' => 'text',
|
635 |
'description' => __( 'This controls the title which the user sees during checkout for PayPal.', 'woocommerce-gateway-paypal-braintree' ),
|
636 |
-
'default' => '',
|
637 |
'desc_tip' => true
|
638 |
),
|
639 |
'description_paypal' => array(
|
@@ -647,7 +699,7 @@ class WC_PayPal_Braintree_Loader {
|
|
647 |
'title' => __( 'Cards Title', 'woocommerce-gateway-paypal-braintree' ),
|
648 |
'type' => 'text',
|
649 |
'description' => __( 'This controls the title which the user sees during checkout for credit and debit cards.', 'woocommerce-gateway-paypal-braintree' ),
|
650 |
-
'default' => '',
|
651 |
'desc_tip' => true
|
652 |
),
|
653 |
'description_cards' => array(
|
5 |
* Description: Receive payments using Paypal Powered by Braintree. A server with cURL, SSL support, and a valid SSL certificate is required (for security reasons) for this gateway to function. Requires PHP 5.4+
|
6 |
* Author: WooThemes
|
7 |
* Author URI: http://woothemes.com/
|
8 |
+
* Version: 1.2.2
|
9 |
*
|
10 |
* Copyright (c) 2016 WooThemes
|
11 |
*
|
339 |
return;
|
340 |
}
|
341 |
|
342 |
+
// We need to pass amount and currency as data attribute to checkout
|
343 |
+
// with PayPal container so that when cart is updated via AJAX we could
|
344 |
+
// teardown and setup the button.
|
345 |
+
$amount = WC()->cart->total;
|
346 |
+
$currency = get_woocommerce_currency();
|
347 |
?>
|
348 |
+
<div id="paypal-braintree-button-container" data-amount="<?php echo esc_attr( $amount ); ?>" data-currency="<?php echo esc_attr( $currency ); ?>">
|
349 |
+
</div>
|
350 |
<?php
|
351 |
}
|
352 |
|
401 |
}
|
402 |
wp_enqueue_style( 'paypal_braintree_styles' );
|
403 |
|
404 |
+
// See if we should enqueue any JavaScript at all.
|
405 |
+
$should_enqueue_checkout_script = $this->_is_hosted_fields_supported();
|
406 |
+
$should_enqueue_cart_script = $this->_is_checkout_from_cart_supported();
|
|
|
407 |
|
408 |
if ( ! $should_enqueue_cart_script && ! $should_enqueue_checkout_script ) {
|
409 |
return;
|
410 |
}
|
411 |
|
412 |
+
$checkout_with_paypal = $this->_get_checkout_with_paypal_params();
|
413 |
+
$hosted_fields = $this->_get_hosted_field_params();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
|
415 |
+
// Sanity check.
|
416 |
if ( ! $checkout_with_paypal && ! $hosted_fields ) {
|
417 |
return;
|
418 |
}
|
424 |
$client_token = $braintree_gateway->clientToken()->generate();
|
425 |
|
426 |
$paypal_braintree_data = array(
|
427 |
+
'token' => $client_token,
|
428 |
+
'checkoutWithPayPal' => $checkout_with_paypal,
|
429 |
+
'checkoutWithPayPalContainer' => 'paypal-braintree-button-container',
|
430 |
+
'hostedFields' => $hosted_fields,
|
431 |
);
|
432 |
|
433 |
// Allow things like subscriptions to filter the setup (e.g. to set checkoutWithPayPal singleUse to false)
|
434 |
$paypal_braintree_data = apply_filters( 'wc_gateway_paypal_braintree_data', $paypal_braintree_data );
|
435 |
|
436 |
+
wp_register_script( 'paypal_braintree', 'https://js.braintreegateway.com/js/braintree-2.24.1.min.js', array( 'jquery' ) );
|
437 |
if ( $should_enqueue_checkout_script ) {
|
438 |
wp_register_script( 'gateway_paypal_braintree', plugins_url( 'assets/js/checkout.js', __FILE__ ), array( 'jquery', 'paypal_braintree' ) );
|
439 |
} else if ( $should_enqueue_cart_script ) {
|
445 |
|
446 |
}
|
447 |
|
448 |
+
/**
|
449 |
+
* Whether checkout with PayPal from cart page is supported.
|
450 |
+
*
|
451 |
+
* @since 1.2.2
|
452 |
+
*
|
453 |
+
* @return bool Returns true if supported
|
454 |
+
*/
|
455 |
+
private function _is_checkout_from_cart_supported() {
|
456 |
+
return is_cart() && $this->does_checkout_with_paypal_support_shop_currency() && ! $this->does_cart_contain_any_subscriptions();
|
457 |
+
}
|
458 |
+
|
459 |
+
/**
|
460 |
+
* Whether rendering hosted fields in checkout page is supported.
|
461 |
+
*
|
462 |
+
* @since 1.2.2
|
463 |
+
*
|
464 |
+
* @return bool Returns true if supported
|
465 |
+
*/
|
466 |
+
private function _is_hosted_fields_supported() {
|
467 |
+
return is_checkout() && ! $this->does_session_have_postback_data();
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Get hosted field params that will be replaced by iframe via braintree JS.
|
472 |
+
*
|
473 |
+
* @since 1.2.2
|
474 |
+
*
|
475 |
+
* @return bool|array False if hosted field is not supported otherwise returns
|
476 |
+
* hosted field params
|
477 |
+
*/
|
478 |
+
private function _get_hosted_field_params() {
|
479 |
+
if ( ! $this->_is_hosted_fields_supported( ) ) {
|
480 |
+
return false;
|
481 |
+
}
|
482 |
+
|
483 |
+
return array(
|
484 |
+
'number' => array(
|
485 |
+
'selector' => '#wc-paypal-braintree-card-number',
|
486 |
+
'placeholder' => '0000000000000000',
|
487 |
+
),
|
488 |
+
'cvv' => array(
|
489 |
+
'selector' => '#wc-paypal-braintree-cvv',
|
490 |
+
'placeholder' => 'CVV',
|
491 |
+
),
|
492 |
+
'expirationDate' => array(
|
493 |
+
'selector' => '#wc-paypal-braintree-expiration-date',
|
494 |
+
'placeholder' => 'MM/YY',
|
495 |
+
),
|
496 |
+
'styles' => array(
|
497 |
+
'input' => array(
|
498 |
+
'font-size' => '12pt',
|
499 |
+
'color' => '#3A3A3A',
|
500 |
+
'font-family' => 'monospace',
|
501 |
+
)
|
502 |
+
),
|
503 |
+
);
|
504 |
+
}
|
505 |
+
|
506 |
+
/**
|
507 |
+
* Get checkout with PayPal params.
|
508 |
+
*
|
509 |
+
* This params will be passed via wp_localize_script as options to braintree.setup
|
510 |
+
* to render checkout with PayPal button in cart page.
|
511 |
+
*
|
512 |
+
* @since 1.2.2
|
513 |
+
*
|
514 |
+
* @return bool|array
|
515 |
+
*/
|
516 |
+
private function _get_checkout_with_paypal_params() {
|
517 |
+
$postback_class = 'WC_Gateway_Paypal_Braintree_Pay_With_PayPal';
|
518 |
+
if ( $this->subscription_support_enabled ) {
|
519 |
+
$postback_class = 'WC_Gateway_Paypal_Braintree_Pay_With_PayPal_Subscription';
|
520 |
+
}
|
521 |
+
|
522 |
+
// Note: The postback URL is only used for cart initiated Checkout with PayPal flow.
|
523 |
+
$details_postback_url = false;
|
524 |
+
if ( $this->_is_checkout_from_cart_supported() ) {
|
525 |
+
$details_postback_url = WC()->api_request_url( $postback_class );
|
526 |
+
$details_postback_url = add_query_arg( 'action', 'checkout_details', $details_postback_url );
|
527 |
+
}
|
528 |
+
|
529 |
+
// Only bother including Checkout with PayPal if the currency is supported
|
530 |
+
// (Checkout with PayPal supports fewer currencies than hosted fields).
|
531 |
+
$checkout_with_paypal = false;
|
532 |
+
if ( $this->does_checkout_with_paypal_support_shop_currency() ) {
|
533 |
+
$checkout_with_paypal = array(
|
534 |
+
'amount' => WC()->cart->total,
|
535 |
+
'currency' => get_woocommerce_currency(),
|
536 |
+
'singleUse' => true,
|
537 |
+
'detailsPostbackURL' => $details_postback_url
|
538 |
+
);
|
539 |
+
}
|
540 |
+
|
541 |
+
return $checkout_with_paypal;
|
542 |
+
}
|
543 |
|
544 |
/**
|
545 |
* Returns true if our gateways are enabled, false otherwise
|
685 |
'title' => __( 'PayPal Title', 'woocommerce-gateway-paypal-braintree' ),
|
686 |
'type' => 'text',
|
687 |
'description' => __( 'This controls the title which the user sees during checkout for PayPal.', 'woocommerce-gateway-paypal-braintree' ),
|
688 |
+
'default' => __( 'PayPal Account', 'woocommerce-gateway-paypal-braintree' ),
|
689 |
'desc_tip' => true
|
690 |
),
|
691 |
'description_paypal' => array(
|
699 |
'title' => __( 'Cards Title', 'woocommerce-gateway-paypal-braintree' ),
|
700 |
'type' => 'text',
|
701 |
'description' => __( 'This controls the title which the user sees during checkout for credit and debit cards.', 'woocommerce-gateway-paypal-braintree' ),
|
702 |
+
'default' => __( 'Credit or Debit Card (PayPal)', 'woocommerce-gateway-paypal-braintree' ),
|
703 |
'desc_tip' => true
|
704 |
),
|
705 |
'description_cards' => array(
|