mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge branch 'master' of github.com:woocommerce/paypal-for-woocommerce
This commit is contained in:
commit
be331f9191
5 changed files with 80 additions and 20 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
#payment ul.payment_methods li img.ppcp-card-icon {
|
||||||
|
padding: 0 0 3px 3px;
|
||||||
|
max-height: 25px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
|
@ -321,6 +321,14 @@ class SmartButton implements SmartButtonInterface {
|
||||||
$load_script = true;
|
$load_script = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( is_checkout() && $this->can_render_dcc() ) {
|
||||||
|
wp_enqueue_style(
|
||||||
|
'ppcp-hosted-fields',
|
||||||
|
$this->module_url . '/assets/css/hosted-fields.css',
|
||||||
|
array(),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
}
|
||||||
if ( $load_script ) {
|
if ( $load_script ) {
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'ppcp-smart-button',
|
'ppcp-smart-button',
|
||||||
|
@ -459,17 +467,23 @@ class SmartButton implements SmartButtonInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the HTML for the DCC fields.
|
* Whether DCC fields can be rendered.
|
||||||
*
|
*
|
||||||
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting hasnt been found.
|
* @return bool
|
||||||
|
* @throws \WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException When a setting was not found.
|
||||||
|
*/
|
||||||
|
private function can_render_dcc() : bool {
|
||||||
|
|
||||||
|
return $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) && $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) && $this->dcc_applies->for_country_currency();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the HTML for the DCC fields.
|
||||||
*/
|
*/
|
||||||
public function dcc_renderer() {
|
public function dcc_renderer() {
|
||||||
|
|
||||||
$id = 'ppcp-hosted-fields';
|
$id = 'ppcp-hosted-fields';
|
||||||
$can_render_dcc = $this->dcc_applies->for_country_currency()
|
if ( ! $this->can_render_dcc() ) {
|
||||||
&& $this->settings->has( 'client_id' )
|
|
||||||
&& $this->settings->get( 'client_id' );
|
|
||||||
if ( ! $can_render_dcc ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,7 +503,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
) : '';
|
) : '';
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
'<div id="%1$s">
|
'<div id="%1$s" style="display:none;">
|
||||||
<button class="button alt">%6$s</button>
|
<button class="button alt">%6$s</button>
|
||||||
</div><div id="payments-sdk__contingency-lightbox"></div><style id="ppcp-hide-dcc">.payment_method_ppcp-credit-card-gateway {display:none;}</style>',
|
</div><div id="payments-sdk__contingency-lightbox"></div><style id="ppcp-hide-dcc">.payment_method_ppcp-credit-card-gateway {display:none;}</style>',
|
||||||
esc_attr( $id ),
|
esc_attr( $id ),
|
||||||
|
|
|
@ -6,7 +6,8 @@ module.exports = {
|
||||||
mode: isProduction ? 'production' : 'development',
|
mode: isProduction ? 'production' : 'development',
|
||||||
target: 'web',
|
target: 'web',
|
||||||
entry: {
|
entry: {
|
||||||
button: path.resolve('./resources/js/button.js')
|
button: path.resolve('./resources/js/button.js'),
|
||||||
|
"hosted-fields": path.resolve('./resources/css/hosted-fields.scss')
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, 'assets/'),
|
path: path.resolve(__dirname, 'assets/'),
|
||||||
|
|
|
@ -59,8 +59,44 @@ const groupToggleSelect = (selector, group) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const disableOptions = (sourceSelector, targetSelector) => {
|
||||||
|
|
||||||
|
const source = jQuery(sourceSelector);
|
||||||
|
const target = document.querySelector(targetSelector);
|
||||||
|
if (! target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const allOptions = Array.from(document.querySelectorAll('select[name="ppcp[disable_cards][]"] option'));
|
||||||
|
const replace = () => {
|
||||||
|
const validOptions = allOptions.filter(
|
||||||
|
(option) => {
|
||||||
|
|
||||||
|
return ! option.selected
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const selectedValidOptions = validOptions.map(
|
||||||
|
(option) => {
|
||||||
|
option = option.cloneNode(true);
|
||||||
|
option.selected = target.querySelector('option[value="' + option.value + '"]') && target.querySelector('option[value="' + option.value + '"]').selected;
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
target.innerHTML = '';
|
||||||
|
selectedValidOptions.forEach(
|
||||||
|
(option) => {
|
||||||
|
target.append(option);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
source.on('change',replace);
|
||||||
|
replace();
|
||||||
|
}
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
document.querySelector('#field-toggle_manual_input').addEventListener(
|
const manualInputToggle = document.querySelector('#field-toggle_manual_input');
|
||||||
|
if (manualInputToggle) {
|
||||||
|
manualInputToggle.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
(event) => {
|
(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -70,6 +106,8 @@ const groupToggleSelect = (selector, group) => {
|
||||||
document.querySelector('#field-client_secret').classList.toggle('show');
|
document.querySelector('#field-client_secret').classList.toggle('show');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
disableOptions('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]');
|
||||||
|
|
||||||
groupToggle(
|
groupToggle(
|
||||||
'#ppcp-button_enabled',
|
'#ppcp-button_enabled',
|
||||||
|
|
|
@ -133,9 +133,11 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
||||||
*/
|
*/
|
||||||
public function get_title() {
|
public function get_title() {
|
||||||
|
|
||||||
if ( is_admin() ) {
|
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||||
|
if ( ! is_checkout() || ( is_ajax() && isset( $_GET['wc-ajax'] ) && 'update_order_review' !== $_GET['wc-ajax'] ) ) {
|
||||||
return parent::get_title();
|
return parent::get_title();
|
||||||
}
|
}
|
||||||
|
//phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||||
$title = parent::get_title();
|
$title = parent::get_title();
|
||||||
$icons = $this->config->has( 'card_icons' ) ? (array) $this->config->get( 'card_icons' ) : array();
|
$icons = $this->config->has( 'card_icons' ) ? (array) $this->config->get( 'card_icons' ) : array();
|
||||||
if ( empty( $icons ) ) {
|
if ( empty( $icons ) ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue