From 1ce5e27f3736fedd4c47b64016f0e108c8d5e2e6 Mon Sep 17 00:00:00 2001 From: Kirill Braslavsky Date: Fri, 19 Mar 2021 17:40:11 +0200 Subject: [PATCH] Revert "enqueue PayPal script from backend" This reverts commit 238a71f9a463063bdb2bb08deaad234bf81cc9ad. --- modules/ppcp-button/resources/js/button.js | 23 ++++++++++++++++++- .../src/Assets/class-smartbutton.php | 10 +------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index a3eb06f52..067bc5347 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -73,6 +73,27 @@ const bootstrap = () => { document.addEventListener( 'DOMContentLoaded', () => { - bootstrap(); + if (!typeof (PayPalCommerceGateway)) { + console.error('PayPal button could not be configured.'); + return; + } + const script = document.createElement('script'); + + script.addEventListener('load', (event) => { + bootstrap(); + }); + script.setAttribute('src', PayPalCommerceGateway.button.url); + Object.entries(PayPalCommerceGateway.script_attributes).forEach( + (keyValue) => { + script.setAttribute(keyValue[0], keyValue[1]); + } + ); + + if (PayPalCommerceGateway.data_client_id.set_attribute) { + dataClientIdAttributeHandler(script, PayPalCommerceGateway.data_client_id); + return; + } + + document.body.append(script); }, ); diff --git a/modules/ppcp-button/src/Assets/class-smartbutton.php b/modules/ppcp-button/src/Assets/class-smartbutton.php index df3cefffc..6dbfec312 100644 --- a/modules/ppcp-button/src/Assets/class-smartbutton.php +++ b/modules/ppcp-button/src/Assets/class-smartbutton.php @@ -351,19 +351,11 @@ class SmartButton implements SmartButtonInterface { wp_enqueue_script( 'ppcp-smart-button', $this->module_url . '/assets/js/button.js', - array( 'jquery', 'ppcp-paypal-buttons' ), + array( 'jquery' ), 1, true ); - wp_enqueue_script( - 'ppcp-paypal-buttons', - $this->url(), - array('jquery'), - null, - false - ); - wp_localize_script( 'ppcp-smart-button', 'PayPalCommerceGateway',