+
$this->sdk_url,
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
+ 'is_admin' => false,
'preferences' => array(
'checkout_data_mode' => $checkout_data_mode,
),
@@ -204,6 +205,7 @@ protected function data_for_cart_page(
return array(
'sdk_url' => $this->sdk_url,
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
+ 'is_admin' => false,
'preferences' => array(
'checkout_data_mode' => $checkout_data_mode,
),
@@ -252,6 +254,7 @@ protected function data_for_admin_page(
return array(
'sdk_url' => $this->sdk_url,
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
+ 'is_admin' => true,
'preferences' => array(
'checkout_data_mode' => $checkout_data_mode,
),
diff --git a/modules/ppcp-button/resources/css/gateway.scss b/modules/ppcp-button/resources/css/gateway.scss
index 42b216e92..85f2356e7 100644
--- a/modules/ppcp-button/resources/css/gateway.scss
+++ b/modules/ppcp-button/resources/css/gateway.scss
@@ -1,3 +1,5 @@
+@use "mixins/apm-button" as apm-button;
+
#place_order.ppcp-hidden {
display: none !important;
}
@@ -15,3 +17,12 @@
.ppc-button-wrapper #ppcp-messages:first-child {
padding-top: 10px;
}
+
+// Prevents spacing after button group.
+#ppc-button-ppcp-gateway {
+ line-height: 0;
+}
+
+.ppcp-button-apm {
+ @include apm-button.button;
+}
diff --git a/modules/ppcp-button/resources/css/mixins/apm-button.scss b/modules/ppcp-button/resources/css/mixins/apm-button.scss
new file mode 100644
index 000000000..1de993b2b
--- /dev/null
+++ b/modules/ppcp-button/resources/css/mixins/apm-button.scss
@@ -0,0 +1,18 @@
+
+@mixin button {
+ min-width: 200px;
+ max-width: 750px;
+ line-height: 0;
+
+ .ppcp-width-min & {
+ height: 35px;
+ }
+
+ .ppcp-width-300 & {
+ height: 45px;
+ }
+
+ .ppcp-width-500 & {
+ height: 55px;
+ }
+}
diff --git a/modules/ppcp-button/resources/js/modules/Helper/ApmButton.js b/modules/ppcp-button/resources/js/modules/Helper/ApmButton.js
new file mode 100644
index 000000000..5e5c7fa0d
--- /dev/null
+++ b/modules/ppcp-button/resources/js/modules/Helper/ApmButton.js
@@ -0,0 +1,83 @@
+
+export const apmButtonInit = (selector = '.ppcp-button-apm') => {
+ if (window.apmButton) {
+ return;
+ }
+ window.apmButton = new ApmButton(selector);
+}
+
+export class ApmButton {
+
+ constructor(selector) {
+ this.selector = selector;
+ this.containers = [];
+
+ jQuery(window).resize(() => {
+ this.refresh();
+ }).resize();
+
+ // TODO: detect changes don't rely on setInterval
+ setInterval(() => {
+ jQuery(selector).each((index, el) => {
+ const parent = jQuery(el).parent();
+ if (!this.containers.some($el => $el.is(parent))) {
+ this.containers.push(parent);
+ }
+ });
+
+ this.refresh();
+ }, 100);
+ }
+
+ refresh() {
+ for (const container of this.containers) {
+ const containerClasses = [];
+ const $container = jQuery(container);
+
+ // Check width and add classes
+ const width = $container.width();
+
+ if (width >= 500) {
+ containerClasses.push('ppcp-width-500');
+ } else if (width >= 300) {
+ containerClasses.push('ppcp-width-300');
+ } else {
+ containerClasses.push('ppcp-width-min');
+ }
+
+ $container.removeClass('ppcp-width-500 ppcp-width-300 ppcp-width-min');
+ $container.addClass(containerClasses.join(' '));
+
+ // Check first apm button
+ const $firstApmButton = $container.find(this.selector + ':visible').first();
+ const $firstElement = $container.children(':visible').first();
+
+ let $spacingTopButton = null;
+ if (!$firstApmButton.is($firstElement)) {
+ $spacingTopButton = $firstApmButton;
+ }
+
+ // Check last apm button
+ const $lastApmButton = $container.find(this.selector + ':visible').last();
+
+ // Assign margins to buttons
+ $container.find(this.selector).each((index, el) => {
+ const $el = jQuery(el);
+ const height = $el.height();
+
+ if ($el.is($spacingTopButton)) {
+ $el.css('margin-top', `${Math.round(height * 0.3)}px`);
+ }
+
+ if ($el.is($lastApmButton)) {
+ $el.css('margin-bottom', `0px`);
+ return true;
+ }
+
+ $el.css('margin-bottom', `${Math.round(height * 0.3)}px`);
+ });
+
+ }
+ }
+
+}
diff --git a/modules/ppcp-googlepay/resources/css/styles.scss b/modules/ppcp-googlepay/resources/css/styles.scss
index 82755efd8..5bdf8edae 100644
--- a/modules/ppcp-googlepay/resources/css/styles.scss
+++ b/modules/ppcp-googlepay/resources/css/styles.scss
@@ -1,8 +1,6 @@
.ppcp-button-googlepay {
- margin: 7px 0;
overflow: hidden;
min-height: 40px;
- height: 45px;
&.ppcp-button-pill {
border-radius: 50px;
@@ -10,13 +8,6 @@
&.ppcp-button-minicart {
display: block;
- height: 40px;
- }
-}
-
-.woocommerce-checkout {
- .ppcp-button-googlepay {
- margin-top: 0;
}
}
@@ -25,14 +16,12 @@
.wp-block-woocommerce-checkout {
.ppcp-button-googlepay {
margin: 0;
- height: 48px;
}
}
.wp-block-woocommerce-cart {
.ppcp-button-googlepay {
margin: 0;
- height: 48px;
}
}
diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
index 9197cd5a5..ed70fd55b 100644
--- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js
+++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
@@ -3,10 +3,13 @@ import {setVisible} from '../../../ppcp-button/resources/js/modules/Helper/Hidin
import {setEnabled} from '../../../ppcp-button/resources/js/modules/Helper/ButtonDisabler';
import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder";
import UpdatePaymentData from "./Helper/UpdatePaymentData";
+import {apmButtonInit} from "../../../ppcp-button/resources/js/modules/Helper/ApmButton";
class GooglepayButton {
constructor(context, externalHandler, buttonConfig, ppcpConfig) {
+ apmButtonInit();
+
this.isInitialized = false;
this.context = context;
diff --git a/modules/ppcp-googlepay/resources/js/boot-admin.js b/modules/ppcp-googlepay/resources/js/boot-admin.js
index 577733b6b..3b971986f 100644
--- a/modules/ppcp-googlepay/resources/js/boot-admin.js
+++ b/modules/ppcp-googlepay/resources/js/boot-admin.js
@@ -67,7 +67,7 @@ import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/Wi
buttonConfig.button.wrapper = selector;
applyConfigOptions(buttonConfig);
- const wrapperElement = `
`;
+ const wrapperElement = `
`;
if (!jQuery(selector).length) {
jQuery(ppcpConfig.button.wrapper).after(wrapperElement);
diff --git a/modules/ppcp-googlepay/resources/js/boot-block.js b/modules/ppcp-googlepay/resources/js/boot-block.js
index 69baf2d5e..3b68456b9 100644
--- a/modules/ppcp-googlepay/resources/js/boot-block.js
+++ b/modules/ppcp-googlepay/resources/js/boot-block.js
@@ -51,7 +51,7 @@ const GooglePayComponent = () => {
}, [paypalLoaded, googlePayLoaded]);
return (
-
+
);
}
diff --git a/modules/ppcp-googlepay/src/Assets/Button.php b/modules/ppcp-googlepay/src/Assets/Button.php
index df482c73f..15f16e381 100644
--- a/modules/ppcp-googlepay/src/Assets/Button.php
+++ b/modules/ppcp-googlepay/src/Assets/Button.php
@@ -311,7 +311,7 @@ function () {
add_action(
$render_placeholder,
function () {
- echo '
';
+ echo '
';
},
21
);
@@ -325,7 +325,7 @@ function () {
*/
private function googlepay_button(): void {
?>
-