Merge pull request #2153 from woocommerce/PCP-2794-add-pay-later-messaging-to-block-cart-checkout

Refactor the Pay Later Messaging block and add dedicated Cart/Checkout blocks (2794)
This commit is contained in:
Emili Castells 2024-04-22 16:56:28 +02:00 committed by GitHub
commit e0afc257b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 4323 additions and 272 deletions

5
.gitignore vendored
View file

@ -4,9 +4,8 @@
node_modules node_modules
.phpunit.result.cache .phpunit.result.cache
yarn-error.log yarn-error.log
modules/ppcp-button/assets/* modules/*/vendor/*
modules/ppcp-wc-gateway/assets/js modules/*/assets/*
modules/ppcp-wc-gateway/assets/css
*.zip *.zip
.env .env
.env.e2e .env.e2e

View file

@ -55,3 +55,13 @@ function as_unschedule_action($hook, $args = array(), $group = '') {}
* @return int The action ID. * @return int The action ID.
*/ */
function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false ) {} function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '', $unique = false ) {}
/**
* HTML API: WP_HTML_Tag_Processor class
*/
class WP_HTML_Tag_Processor {
public function __construct( $html ) {}
public function next_tag( $query = null ) {}
public function set_attribute( $name, $value ) {}
public function get_updated_html() {}
}

View file

@ -6,6 +6,7 @@
*/ */
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule; use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
use WooCommerce\PayPalCommerce\PayLaterWCBlocks\PayLaterWCBlocksModule;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\PayLaterConfiguratorModule; use WooCommerce\PayPalCommerce\PayLaterConfigurator\PayLaterConfiguratorModule;
use WooCommerce\PayPalCommerce\PluginModule; use WooCommerce\PayPalCommerce\PluginModule;
@ -72,6 +73,10 @@ return function ( string $root_dir ): iterable {
$modules[] = ( require "$modules_dir/ppcp-paylater-block/module.php" )(); $modules[] = ( require "$modules_dir/ppcp-paylater-block/module.php" )();
} }
if ( PayLaterWCBlocksModule::is_module_loading_required() ) {
$modules[] = ( require "$modules_dir/ppcp-paylater-wc-blocks/module.php" )();
}
if ( PayLaterConfiguratorModule::is_enabled() ) { if ( PayLaterConfiguratorModule::is_enabled() ) {
$modules[] = ( require "$modules_dir/ppcp-paylater-configurator/module.php" )(); $modules[] = ( require "$modules_dir/ppcp-paylater-configurator/module.php" )();
} }

156
modules/ppcp-blocks/composer.lock generated Normal file
View file

@ -0,0 +1,156 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "30c5bd428bece98b555ddc0b2da044f3",
"packages": [
{
"name": "container-interop/service-provider",
"version": "v0.4.1",
"source": {
"type": "git",
"url": "https://github.com/container-interop/service-provider.git",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/e04441ca21ef03e10dce70b0af29269281eec6dc",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc",
"shasum": ""
},
"require": {
"psr/container": "^1.0 || ^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Interop\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Promoting container interoperability through standard service providers",
"homepage": "https://github.com/container-interop/service-provider",
"support": {
"issues": "https://github.com/container-interop/service-provider/issues",
"source": "https://github.com/container-interop/service-provider/tree/v0.4.1"
},
"time": "2023-12-14T14:50:12+00:00"
},
{
"name": "dhii/module-interface",
"version": "v0.3.0-alpha2",
"source": {
"type": "git",
"url": "https://github.com/Dhii/module-interface.git",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dhii/module-interface/zipball/0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"shasum": ""
},
"require": {
"container-interop/service-provider": "^0.4",
"php": "^7.1 | ^8.0",
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
"slevomat/coding-standard": "^6.0",
"vimeo/psalm": "^3.11.7 | ^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.3.x-dev"
}
},
"autoload": {
"psr-4": {
"Dhii\\Modular\\Module\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dhii Team",
"email": "development@dhii.co"
}
],
"description": "Interfaces for modules",
"support": {
"issues": "https://github.com/Dhii/module-interface/issues",
"source": "https://github.com/Dhii/module-interface/tree/v0.3.0-alpha2"
},
"time": "2021-08-23T08:23:01+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/1.1.2"
},
"time": "2021-11-05T16:50:12+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.2 | ^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View file

@ -10,13 +10,16 @@
"Edge >= 14" "Edge >= 14"
], ],
"dependencies": { "dependencies": {
"core-js": "^3.25.0" "@paypal/react-paypal-js": "^8.2.0",
"core-js": "^3.25.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.19", "@babel/core": "^7.19",
"@babel/preset-env": "^7.19", "@babel/preset-env": "^7.19",
"@babel/preset-react": "^7.18.6", "@babel/preset-react": "^7.18.6",
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0", "@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
"babel-loader": "^8.2", "babel-loader": "^8.2",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",

View file

@ -16,6 +16,7 @@ import {
import { import {
loadPaypalScriptPromise loadPaypalScriptPromise
} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading' } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
import { PayPalScriptProvider, PayPalButtons } from "@paypal/react-paypal-js";
import { import {
normalizeStyleForFundingSource normalizeStyleForFundingSource
} from '../../../ppcp-button/resources/js/modules/Helper/Style' } from '../../../ppcp-button/resources/js/modules/Helper/Style'
@ -507,6 +508,30 @@ const PayPalComponent = ({
); );
} }
const BlockEditorPayPalComponent = ({
fundingSource,
}) => {
const urlParams = {
clientId: 'test',
...config.scriptData.url_params,
dataNamespace: 'ppcp-blocks-editor-paypal-buttons',
components: 'buttons',
}
return (
<PayPalScriptProvider
options={urlParams}
>
<PayPalButtons
fundingSource={fundingSource}
onClick={(data, actions) => {
return false;
}}
/>
</PayPalScriptProvider>
)
}
const features = ['products']; const features = ['products'];
let block_enabled = true; let block_enabled = true;
@ -571,7 +596,7 @@ if (block_enabled) {
name: config.id, name: config.id,
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>, label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
content: <PayPalComponent isEditing={false}/>, content: <PayPalComponent isEditing={false}/>,
edit: <PayPalComponent isEditing={true}/>, edit: <BlockEditorPayPalComponent fundingSource={fundingSource} />,
ariaLabel: config.title, ariaLabel: config.title,
canMakePayment: () => { canMakePayment: () => {
return true; return true;
@ -587,7 +612,7 @@ if (block_enabled) {
paymentMethodId: config.id, paymentMethodId: config.id,
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>, label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
content: <PayPalComponent isEditing={false} fundingSource={fundingSource}/>, content: <PayPalComponent isEditing={false} fundingSource={fundingSource}/>,
edit: <PayPalComponent isEditing={true} fundingSource={fundingSource}/>, edit: <BlockEditorPayPalComponent fundingSource={fundingSource} />,
ariaLabel: config.title, ariaLabel: config.title,
canMakePayment: async () => { canMakePayment: async () => {
if (!paypalScriptPromise) { if (!paypalScriptPromise) {

View file

@ -110,6 +110,13 @@ class BlocksModule implements ModuleInterface {
} }
); );
add_filter(
'woocommerce_paypal_payments_sdk_components_hook',
function( array $components ) {
$components[] = 'buttons';
return $components;
}
);
} }
/** /**

View file

@ -1005,6 +1005,28 @@
"@jridgewell/resolve-uri" "3.1.0" "@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14" "@jridgewell/sourcemap-codec" "1.4.14"
"@paypal/paypal-js@^8.0.4":
version "8.0.4"
resolved "https://registry.yarnpkg.com/@paypal/paypal-js/-/paypal-js-8.0.4.tgz#abe9f40f519b1d2c306adddfbe733be03eb26ce5"
integrity sha512-91g5fhRBHGEBoikDzQT6uBn3PzlJQ75g0c3MvqVJqN0XRm5kHa9wz+6+Uaq8QQuxRzz5C2x55Zg057CW6EuwpQ==
dependencies:
promise-polyfill "^8.3.0"
"@paypal/react-paypal-js@^8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@paypal/react-paypal-js/-/react-paypal-js-8.2.0.tgz#4b1a142bbb68e62dca4a92da4a6b5568f54901f0"
integrity sha512-SworUfu0BNNcqoh0O53Ke4MFpx2m3qJRu3hayXvlluEEXJpKqGSV5aaSGFhbsZqi8hnbsx/hZR7BQbmqsggiGQ==
dependencies:
"@paypal/paypal-js" "^8.0.4"
"@paypal/sdk-constants" "^1.0.122"
"@paypal/sdk-constants@^1.0.122":
version "1.0.145"
resolved "https://registry.yarnpkg.com/@paypal/sdk-constants/-/sdk-constants-1.0.145.tgz#f373cd3b7cf0409c28e121629b8f1855faf2e77b"
integrity sha512-2tclrVX3L44YRJ09H4kkqma/UeAjRJarwH5SyPip10O5S+2ByE1HiyspAJ6hIWSjMngFVqjNyUCnrGcuQA3ldg==
dependencies:
hi-base32 "^0.5.0"
"@types/eslint-scope@^3.7.3": "@types/eslint-scope@^3.7.3":
version "3.7.4" version "3.7.4"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16" resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16"
@ -1179,7 +1201,7 @@
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1" resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1"
integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q== integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q==
"@woocommerce/dependency-extraction-webpack-plugin@^2.2.0": "@woocommerce/dependency-extraction-webpack-plugin@2.2.0":
version "2.2.0" version "2.2.0"
resolved "https://registry.yarnpkg.com/@woocommerce/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz#230d674a67585bc32e31bc28485bec99b41dbd1f" resolved "https://registry.yarnpkg.com/@woocommerce/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz#230d674a67585bc32e31bc28485bec99b41dbd1f"
integrity sha512-0wDY3EIUwWrPm0KrWvt1cf2SZDSX7CzBXvv4TyCqWOPuVPvC/ajyY8kD1HTFI80q6/RHoxWf3BYCmhuBzPbe9A== integrity sha512-0wDY3EIUwWrPm0KrWvt1cf2SZDSX7CzBXvv4TyCqWOPuVPvC/ajyY8kD1HTFI80q6/RHoxWf3BYCmhuBzPbe9A==
@ -1599,6 +1621,11 @@ has@^1.0.3:
dependencies: dependencies:
function-bind "^1.1.1" function-bind "^1.1.1"
hi-base32@^0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/hi-base32/-/hi-base32-0.5.1.tgz#1279f2ddae2673219ea5870c2121d2a33132857e"
integrity sha512-EmBBpvdYh/4XxsnUybsPag6VikPYnN30td+vQk+GI3qpahVEG9+gTkG0aXVxTjBqQ5T6ijbWIu77O+C5WFWsnA==
immutable@^4.0.0: immutable@^4.0.0:
version "4.1.0" version "4.1.0"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.1.0.tgz#f795787f0db780183307b9eb2091fcac1f6fafef" resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.1.0.tgz#f795787f0db780183307b9eb2091fcac1f6fafef"
@ -1674,7 +1701,7 @@ jest-worker@^27.4.5:
merge-stream "^2.0.0" merge-stream "^2.0.0"
supports-color "^8.0.0" supports-color "^8.0.0"
js-tokens@^4.0.0: "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
@ -1745,6 +1772,13 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow== integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==
loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
make-dir@^3.0.2, make-dir@^3.1.0: make-dir@^3.0.2, make-dir@^3.1.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
@ -1789,6 +1823,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
p-limit@^2.2.0: p-limit@^2.2.0:
version "2.3.0" version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
@ -1840,6 +1879,11 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
dependencies: dependencies:
find-up "^4.0.0" find-up "^4.0.0"
promise-polyfill@^8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.3.0.tgz#9284810268138d103807b11f4e23d5e945a4db63"
integrity sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==
punycode@^2.1.0: punycode@^2.1.0:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
@ -1852,6 +1896,23 @@ randombytes@^2.1.0:
dependencies: dependencies:
safe-buffer "^5.1.0" safe-buffer "^5.1.0"
react-dom@^17.0.0:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"
react@^17.0.0:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
readdirp@~3.6.0: readdirp@~3.6.0:
version "3.6.0" version "3.6.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
@ -1957,6 +2018,14 @@ sass@^1.42.1:
immutable "^4.0.0" immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0" source-map-js ">=0.6.2 <2.0.0"
scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
schema-utils@^2.6.5: schema-utils@^2.6.5:
version "2.7.1" version "2.7.1"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7"

View file

@ -14,7 +14,7 @@
} }
} }
.ppc-button-wrapper #ppcp-messages:first-child { .ppc-button-wrapper .ppcp-messages:first-child {
padding-top: 10px; padding-top: 10px;
} }

View file

@ -34,6 +34,7 @@ use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply; use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule; use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockModule;
use WooCommerce\PayPalCommerce\PayLaterWCBlocks\PayLaterWCBlocksModule;
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentToken; use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentToken;
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreateSetupToken; use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreateSetupToken;
use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentTokenForGuest; use WooCommerce\PayPalCommerce\SavePaymentMethods\Endpoint\CreatePaymentTokenForGuest;
@ -438,7 +439,20 @@ class SmartButton implements SmartButtonInterface {
wp_is_block_theme() wp_is_block_theme()
); );
$get_hook = function ( string $location ) use ( $default_pay_order_hook, $is_block_theme ): ?array { $has_paylater_block =
(
PayLaterBlockModule::is_block_enabled( $this->settings_status ) &&
has_block( 'woocommerce-paypal-payments/paylater-messages' )
) ||
(
PayLaterWCBlocksModule::is_block_enabled( $this->settings_status, $location ) &&
(
has_block( 'woocommerce-paypal-payments/checkout-paylater-messages' ) ||
has_block( 'woocommerce-paypal-payments/cart-paylater-messages' )
)
);
$get_hook = function ( string $location ) use ( $default_pay_order_hook, $is_block_theme, $has_paylater_block ): ?array {
switch ( $location ) { switch ( $location ) {
case 'checkout': case 'checkout':
return $this->messages_renderer_hook( $location, 'woocommerce_review_order_before_payment', 10 ); return $this->messages_renderer_hook( $location, 'woocommerce_review_order_before_payment', 10 );
@ -457,11 +471,14 @@ class SmartButton implements SmartButtonInterface {
? $this->messages_renderer_block( $location, 'core/navigation', 10 ) ? $this->messages_renderer_block( $location, 'core/navigation', 10 )
: $this->messages_renderer_hook( $location, 'loop_start', 20 ); : $this->messages_renderer_hook( $location, 'loop_start', 20 );
default: default:
return null; return $has_paylater_block
? $this->messages_renderer_hook( $location, 'ppcp_paylater_message_block', 10 )
: null;
} }
}; };
$hook = $get_hook( $location ); $hook = $get_hook( $location );
if ( ! $hook ) { if ( ! $hook ) {
return false; return false;
} }
@ -492,7 +509,7 @@ class SmartButton implements SmartButtonInterface {
function () { function () {
echo ' echo '
<script> <script>
document.querySelector("#payment").before(document.querySelector("#ppcp-messages")) document.querySelector("#payment").before(document.querySelector(".ppcp-messages"))
</script>'; </script>';
} }
); );
@ -601,10 +618,6 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
return false; return false;
} }
if ( in_array( $this->context(), array( 'checkout-block', 'cart-block' ), true ) ) {
return false;
}
return $this->should_load_buttons() || $this->should_load_messages() || $this->can_render_dcc(); return $this->should_load_buttons() || $this->should_load_messages() || $this->can_render_dcc();
} }
@ -655,7 +668,11 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
$messaging_enabled_for_current_location = $this->settings_status->is_pay_later_messaging_enabled_for_location( $location ); $messaging_enabled_for_current_location = $this->settings_status->is_pay_later_messaging_enabled_for_location( $location );
$has_paylater_block = has_block( 'woocommerce-paypal-payments/paylater-messages' ) && PayLaterBlockModule::is_block_enabled( $this->settings_status ); $has_paylater_block = PayLaterBlockModule::is_block_enabled( $this->settings_status ) && has_block( 'woocommerce-paypal-payments/paylater-messages' );
if ( 'cart-block' === $location || 'checkout-block' === $location ) {
return true;
}
switch ( $location ) { switch ( $location ) {
case 'checkout': case 'checkout':
@ -667,9 +684,6 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
return $messaging_enabled_for_current_location; return $messaging_enabled_for_current_location;
case 'block-editor': case 'block-editor':
return true; return true;
case 'checkout-block':
case 'cart-block':
return $has_paylater_block || $this->is_block_editor();
default: default:
return $has_paylater_block; return $has_paylater_block;
} }
@ -789,7 +803,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
*/ */
do_action( "ppcp_before_{$location_hook}_message_wrapper" ); do_action( "ppcp_before_{$location_hook}_message_wrapper" );
$messages_placeholder = '<div id="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>'; $messages_placeholder = '<div class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) { if ( is_array( $block_params ) && ( $block_params['blockName'] ?? false ) ) {
$this->render_after_block( $this->render_after_block(
@ -888,7 +902,20 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
$styling_per_location = $this->settings->has( 'pay_later_enable_styling_per_messaging_location' ) && $this->settings->get( 'pay_later_enable_styling_per_messaging_location' ); $styling_per_location = $this->settings->has( 'pay_later_enable_styling_per_messaging_location' ) && $this->settings->get( 'pay_later_enable_styling_per_messaging_location' );
$location = $styling_per_location ? $location : 'general'; $location = $styling_per_location ? $location : 'general';
$setting_name_prefix = "pay_later_{$location}_message";
// Map checkout-block and cart-block message options to checkout and cart options.
switch ( $location ) {
case 'checkout-block':
$location = 'checkout';
break;
case 'cart-block':
$location = 'cart';
break;
default:
break;
}
$setting_name_prefix = "pay_later_{$location}_message";
$layout = $this->settings->has( "{$setting_name_prefix}_layout" ) ? $this->settings->get( "{$setting_name_prefix}_layout" ) : 'text'; $layout = $this->settings->has( "{$setting_name_prefix}_layout" ) ? $this->settings->get( "{$setting_name_prefix}_layout" ) : 'text';
$logo_type = $this->settings->has( "{$setting_name_prefix}_logo" ) ? $this->settings->get( "{$setting_name_prefix}_logo" ) : 'primary'; $logo_type = $this->settings->has( "{$setting_name_prefix}_logo" ) ? $this->settings->get( "{$setting_name_prefix}_logo" ) : 'primary';
@ -899,7 +926,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
$text_size = $this->settings->has( "{$setting_name_prefix}_text_size" ) ? $this->settings->get( "{$setting_name_prefix}_text_size" ) : '12'; $text_size = $this->settings->has( "{$setting_name_prefix}_text_size" ) ? $this->settings->get( "{$setting_name_prefix}_text_size" ) : '12';
return array( return array(
'wrapper' => '#ppcp-messages', 'wrapper' => '.ppcp-messages',
'is_hidden' => ! $this->is_pay_later_filter_enabled_for_location( $this->context() ), 'is_hidden' => ! $this->is_pay_later_filter_enabled_for_location( $this->context() ),
'block' => array( 'block' => array(
'enabled' => PayLaterBlockModule::is_block_enabled( $this->settings_status ), 'enabled' => PayLaterBlockModule::is_block_enabled( $this->settings_status ),

View file

@ -7,40 +7,45 @@
"description": "PayPal Pay Later messaging will be displayed for eligible customers. Customers automatically see the most relevant Pay Later offering.", "description": "PayPal Pay Later messaging will be displayed for eligible customers. Customers automatically see the most relevant Pay Later offering.",
"example": {}, "example": {},
"attributes": { "attributes": {
"id": { "id": {
"type": "string" "type": "string"
}, },
"layout": { "layout": {
"type": "string", "type": "string",
"default": "flex" "default": "flex"
}, },
"logo": { "logo": {
"type": "string", "type": "string",
"default": "inline" "default": "inline"
}, },
"position": { "position": {
"type": "string", "type": "string",
"default": "left" "default": "left"
}, },
"color": { "color": {
"type": "string", "type": "string",
"default": "black" "default": "black"
}, },
"flexColor": { "size": {
"type": "string", "type": "string",
"default": "white" "default": "14"
}, },
"flexRatio": { "flexColor": {
"type": "string", "type": "string",
"default": "8x1" "default": "white"
}, },
"placement": { "flexRatio": {
"type": "string", "type": "string",
"default": "auto" "default": "8x1"
} },
"placement": {
"type": "string",
"default": "auto"
}
}, },
"supports": { "supports": {
"html": false "html": false,
"multiple": false
}, },
"textdomain": "woocommerce-paypal-payments", "textdomain": "woocommerce-paypal-payments",
"editorScript": "ppcp-paylater-block", "editorScript": "ppcp-paylater-block",

156
modules/ppcp-paylater-block/composer.lock generated Normal file
View file

@ -0,0 +1,156 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "51e234e39d0fd6bbb67fe2186683facd",
"packages": [
{
"name": "container-interop/service-provider",
"version": "v0.4.1",
"source": {
"type": "git",
"url": "https://github.com/container-interop/service-provider.git",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/e04441ca21ef03e10dce70b0af29269281eec6dc",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc",
"shasum": ""
},
"require": {
"psr/container": "^1.0 || ^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Interop\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Promoting container interoperability through standard service providers",
"homepage": "https://github.com/container-interop/service-provider",
"support": {
"issues": "https://github.com/container-interop/service-provider/issues",
"source": "https://github.com/container-interop/service-provider/tree/v0.4.1"
},
"time": "2023-12-14T14:50:12+00:00"
},
{
"name": "dhii/module-interface",
"version": "v0.3.0-alpha2",
"source": {
"type": "git",
"url": "https://github.com/Dhii/module-interface.git",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dhii/module-interface/zipball/0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"shasum": ""
},
"require": {
"container-interop/service-provider": "^0.4",
"php": "^7.1 | ^8.0",
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
"slevomat/coding-standard": "^6.0",
"vimeo/psalm": "^3.11.7 | ^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.3.x-dev"
}
},
"autoload": {
"psr-4": {
"Dhii\\Modular\\Module\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dhii Team",
"email": "development@dhii.co"
}
],
"description": "Interfaces for modules",
"support": {
"issues": "https://github.com/Dhii/module-interface/issues",
"source": "https://github.com/Dhii/module-interface/tree/v0.3.0-alpha2"
},
"time": "2021-08-23T08:23:01+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/1.1.2"
},
"time": "2021-11-05T16:50:12+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.2 | ^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View file

@ -10,13 +10,16 @@
"Edge >= 14" "Edge >= 14"
], ],
"dependencies": { "dependencies": {
"core-js": "^3.25.0" "@paypal/react-paypal-js": "^8.2.0",
"core-js": "^3.25.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.19", "@babel/core": "^7.19",
"@babel/preset-env": "^7.19", "@babel/preset-env": "^7.19",
"@babel/preset-react": "^7.18.6", "@babel/preset-react": "^7.18.6",
"@woocommerce/dependency-extraction-webpack-plugin": "^2.2.0", "@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
"babel-loader": "^8.2", "babel-loader": "^8.2",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",

View file

@ -1,29 +0,0 @@
import { useRef, useEffect } from '@wordpress/element';
export default function PayPalMessages({
amount,
style,
onRender,
}) {
const containerRef = useRef(null);
useEffect(() => {
const messages = paypal.Messages({
amount,
style,
onRender,
});
messages.render(containerRef.current)
.catch(err => {
// Ignore when component destroyed.
if (!containerRef.current || containerRef.current.children.length === 0) {
return;
}
console.error(err);
});
}, [amount, style, onRender]);
return <div ref={containerRef}/>
}

View file

@ -2,19 +2,16 @@ import { __ } from '@wordpress/i18n';
import { useState, useEffect } from '@wordpress/element'; import { useState, useEffect } from '@wordpress/element';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; import { PanelBody, SelectControl, Spinner } from '@wordpress/components';
import { useScriptParams } from "./hooks/script-params"; import { PayPalScriptProvider, PayPalMessages } from '@paypal/react-paypal-js';
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading' import { useScriptParams } from './hooks/script-params';
import PayPalMessages from "./components/PayPalMessages";
export default function Edit( { attributes, clientId, setAttributes } ) { export default function Edit({ attributes, clientId, setAttributes }) {
const { layout, logo, position, color, size, flexColor, flexRatio, placement, id } = attributes; const { layout, logo, position, color, size, flexColor, flexRatio, placement, id } = attributes;
const isFlex = layout === 'flex'; const isFlex = layout === 'flex';
const [paypalScriptState, setPaypalScriptState] = useState(null); const [loaded, setLoaded] = useState(false);
const [rendered, setRendered] = useState(false); let amount;
let amount = undefined;
const postContent = String(wp.data.select('core/editor')?.getEditedPostContent()); const postContent = String(wp.data.select('core/editor')?.getEditedPostContent());
if (postContent.includes('woocommerce/checkout') || postContent.includes('woocommerce/cart')) { if (postContent.includes('woocommerce/checkout') || postContent.includes('woocommerce/cart')) {
amount = 50.0; amount = 50.0;
@ -36,159 +33,171 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent']; let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent'];
if (PcpPayLaterBlock.vaultingEnabled || !PcpPayLaterBlock.placementEnabled) { if (PcpPayLaterBlock.vaultingEnabled || !PcpPayLaterBlock.placementEnabled) {
classes = ['ppcp-paylater-block-preview', 'ppcp-paylater-unavailable', 'block-editor-warning']; classes.push('ppcp-paylater-unavailable', 'block-editor-warning');
} }
const props = useBlockProps({className: classes}); const props = useBlockProps({ className: classes.join(' ') });
const loadingElement = <div {...props}><Spinner/></div>;
useEffect(() => { useEffect(() => {
if (!id) { if (!id) {
setAttributes({id: 'ppcp-' + clientId}); setAttributes({ id: `ppcp-${clientId}` });
} }
}, []); }, [id, clientId]);
if (PcpPayLaterBlock.vaultingEnabled) { if (PcpPayLaterBlock.vaultingEnabled) {
return <div {...props}> return (
<div className={'block-editor-warning__contents'}> <div {...props}>
<h3>{__('PayPal Pay Later Messaging', 'woocommerce-paypal-payments')}</h3> <div className='block-editor-warning__contents'>
<p className={'block-editor-warning__message'}>{__('Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}</p> <p className='block-editor-warning__message'>
<div className={'class="block-editor-warning__actions"'}> {__('Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}
<span className={'block-editor-warning__action'}> </p>
<a href={PcpPayLaterBlock.settingsUrl} className={'components-button is-primary'}> <div className='block-editor-warning__actions'>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')} <span className='block-editor-warning__action'>
</a> <a href={PcpPayLaterBlock.payLaterSettingsUrl}>
</span> <button type='button' className='components-button is-primary'>
<span className={'block-editor-warning__action'}> {__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
<button onClick={() => wp.data.dispatch( 'core/block-editor' ).removeBlock(clientId)} type={'button'} className={'components-button is-secondary'}> </button>
{__('Remove Block', 'woocommerce-paypal-payments')} </a>
</button> </span>
</span> <span className='block-editor-warning__action'>
<button
onClick={() => wp.data.dispatch('core/block-editor').removeBlock(clientId)}
type='button' className='components-button is-secondary'>
{__('Remove Block', 'woocommerce-paypal-payments')}
</button>
</span>
</div>
</div> </div>
</div> </div>
</div> );
} }
if (!PcpPayLaterBlock.placementEnabled) { if (!PcpPayLaterBlock.placementEnabled) {
return <div {...props}> return (
<div className={'block-editor-warning__contents'}> <div {...props}>
<h3>{__('PayPal Pay Later Messaging', 'woocommerce-paypal-payments')}</h3> <div className='block-editor-warning__contents'>
<p className={'block-editor-warning__message'}>{__('Pay Later Messaging cannot be used while the “WooCommerce Block” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}</p> <p className='block-editor-warning__message'>
<div className={'class="block-editor-warning__actions"'}> {__('Pay Later Messaging cannot be used while the “WooCommerce Block” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}
<span className={'block-editor-warning__action'}> </p>
<a href={PcpPayLaterBlock.payLaterSettingsUrl} className={'components-button is-primary'}> <div className='block-editor-warning__actions'>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')} <span className='block-editor-warning__action'>
</a> <a href={PcpPayLaterBlock.payLaterSettingsUrl}>
</span> <button type='button' className='components-button is-primary'>
<span className={'block-editor-warning__action'}> {__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
<button onClick={() => wp.data.dispatch( 'core/block-editor' ).removeBlock(clientId)} type={'button'} className={'components-button is-secondary'}> </button>
{__('Remove Block', 'woocommerce-paypal-payments')} </a>
</button> </span>
</span> <span className='block-editor-warning__action'>
<button
onClick={() => wp.data.dispatch('core/block-editor').removeBlock(clientId)}
type='button' className='components-button is-secondary'>
{__('Remove Block', 'woocommerce-paypal-payments')}
</button>
</span>
</div>
</div> </div>
</div> </div>
</div> );
} }
let scriptParams = useScriptParams(PcpPayLaterBlock.ajax.cart_script_params); const scriptParams = useScriptParams(PcpPayLaterBlock.ajax.cart_script_params);
if (scriptParams === null) { if (scriptParams === null) {
return loadingElement; return <div {...props}><Spinner/></div>;
}
if (scriptParams === false) {
scriptParams = {
url_params: {
clientId: 'test',
}
}
}
scriptParams.url_params.components = 'messages,buttons,funding-eligibility';
if (!paypalScriptState) {
loadPaypalScript(scriptParams, () => {
setPaypalScriptState('loaded')
}, () => {
setPaypalScriptState('failed')
});
}
if (paypalScriptState !== 'loaded') {
return loadingElement;
} }
return ( const urlParams = {
<> ...scriptParams.url_params,
<InspectorControls> components: 'messages',
<PanelBody title={ __( 'Settings', 'woocommerce-paypal-payments' ) }> dataNamespace: 'ppcp-block-editor-paylater-message',
};
return (
<>
<InspectorControls>
<PanelBody title={__('Settings', 'woocommerce-paypal-payments')}>
<SelectControl <SelectControl
label={ __( 'Layout', 'woocommerce-paypal-payments' ) } label={__('Layout', 'woocommerce-paypal-payments')}
options={ [ options={[
{ label: __( 'Text', 'woocommerce-paypal-payments' ), value: 'text' }, { label: __('Text', 'woocommerce-paypal-payments'), value: 'text' },
{ label: __( 'Banner', 'woocommerce-paypal-payments' ), value: 'flex' }, { label: __('Banner', 'woocommerce-paypal-payments'), value: 'flex' },
] } ]}
value={ layout } value={layout}
onChange={ ( value ) => setAttributes( { layout: value } ) } onChange={(value) => setAttributes({ layout: value })}
/> />
{ !isFlex && (<SelectControl {!isFlex && (
label={__('Logo', 'woocommerce-paypal-payments')} <SelectControl
options={[ label={__('Logo', 'woocommerce-paypal-payments')}
{ label: __('Full logo', 'woocommerce-paypal-payments'), value: 'primary' }, options={[
{ label: __('Monogram', 'woocommerce-paypal-payments'), value: 'alternative' }, { label: __('Full logo', 'woocommerce-paypal-payments'), value: 'primary' },
{ label: __('Inline', 'woocommerce-paypal-payments'), value: 'inline' }, { label: __('Monogram', 'woocommerce-paypal-payments'), value: 'alternative' },
{ label: __('Message only', 'woocommerce-paypal-payments'), value: 'none' }, { label: __('Inline', 'woocommerce-paypal-payments'), value: 'inline' },
]} { label: __('Message only', 'woocommerce-paypal-payments'), value: 'none' },
value={logo} ]}
onChange={(value) => setAttributes({logo: value})} value={logo}
/>)} onChange={(value) => setAttributes({ logo: value })}
{ !isFlex && logo === 'primary' && (<SelectControl />
label={__('Logo Position', 'woocommerce-paypal-payments')} )}
options={[ {!isFlex && logo === 'primary' && (
{ label: __( 'Left', 'woocommerce-paypal-payments' ), value: 'left' }, <SelectControl
{ label: __( 'Right', 'woocommerce-paypal-payments' ), value: 'right' }, label={__('Logo Position', 'woocommerce-paypal-payments')}
{ label: __( 'Top', 'woocommerce-paypal-payments' ), value: 'top' }, options={[
]} { label: __('Left', 'woocommerce-paypal-payments'), value: 'left' },
value={position} { label: __('Right', 'woocommerce-paypal-payments'), value: 'right' },
onChange={(value) => setAttributes({position: value})} { label: __('Top', 'woocommerce-paypal-payments'), value: 'top' },
/>)} ]}
{ !isFlex && (<SelectControl value={position}
label={__('Text Color', 'woocommerce-paypal-payments')} onChange={(value) => setAttributes({ position: value })}
options={[ />
{ label: __( 'Black / Blue logo', 'woocommerce-paypal-payments' ), value: 'black' }, )}
{ label: __( 'White / White logo', 'woocommerce-paypal-payments' ), value: 'white' }, {!isFlex && (
{ label: __( 'Monochrome', 'woocommerce-paypal-payments' ), value: 'monochrome' }, <SelectControl
{ label: __( 'Black / Gray logo', 'woocommerce-paypal-payments' ), value: 'grayscale' }, label={__('Text Color', 'woocommerce-paypal-payments')}
]} options={[
value={color} { label: __('Black / Blue logo', 'woocommerce-paypal-payments'), value: 'black' },
onChange={(value) => setAttributes({color: value})} { label: __('White / White logo', 'woocommerce-paypal-payments'), value: 'white' },
/>)} { label: __('Monochrome', 'woocommerce-paypal-payments'), value: 'monochrome' },
{ !isFlex && (<SelectControl { label: __('Black / Gray logo', 'woocommerce-paypal-payments'), value: 'grayscale' },
label={__('Text Size', 'woocommerce-paypal-payments')} ]}
options={[ value={color}
{ label: __( 'Small', 'woocommerce-paypal-payments' ), value: '12' }, onChange={(value) => setAttributes({ color: value })}
{ label: __( 'Medium', 'woocommerce-paypal-payments' ), value: '14' }, />
{ label: __( 'Large', 'woocommerce-paypal-payments' ), value: '16' }, )}
]} {!isFlex && (
value={size} <SelectControl
onChange={(value) => setAttributes({size: value})} label={__('Text Size', 'woocommerce-paypal-payments')}
/>)} options={[
{ isFlex && (<SelectControl { label: __('Small', 'woocommerce-paypal-payments'), value: '12' },
label={__('Color', 'woocommerce-paypal-payments')} { label: __('Medium', 'woocommerce-paypal-payments'), value: '14' },
options={[ { label: __('Large', 'woocommerce-paypal-payments'), value: '16' },
{ label: __( 'Blue', 'woocommerce-paypal-payments' ), value: 'blue' }, ]}
{ label: __( 'Black', 'woocommerce-paypal-payments' ), value: 'black' }, value={size}
{ label: __( 'White', 'woocommerce-paypal-payments' ), value: 'white' }, onChange={(value) => setAttributes({ size: value })}
{ label: __( 'White (no border)', 'woocommerce-paypal-payments' ), value: 'white-no-border' }, />
]} )}
value={flexColor} {isFlex && (
onChange={(value) => setAttributes({flexColor: value})} <SelectControl
/>)} label={__('Color', 'woocommerce-paypal-payments')}
{ isFlex && (<SelectControl options={[
label={__('Ratio', 'woocommerce-paypal-payments')} { label: __('Blue', 'woocommerce-paypal-payments'), value: 'blue' },
options={[ { label: __('Black', 'woocommerce-paypal-payments'), value: 'black' },
{ label: __( '8x1', 'woocommerce-paypal-payments' ), value: '8x1' }, { label: __('White', 'woocommerce-paypal-payments'), value: 'white' },
{ label: __( '20x1', 'woocommerce-paypal-payments' ), value: '20x1' }, { label: __('White (no border)', 'woocommerce-paypal-payments'), value: 'white-no-border' },
]} ]}
value={flexRatio} value={flexColor}
onChange={(value) => setAttributes({flexRatio: value})} onChange={(value) => setAttributes({ flexColor: value })}
/>)} />
)}
{isFlex && (
<SelectControl
label={__('Ratio', 'woocommerce-paypal-payments')}
options={[
{ label: __('8x1', 'woocommerce-paypal-payments'), value: '8x1' },
{ label: __('20x1', 'woocommerce-paypal-payments'), value: '20x1' },
]}
value={flexRatio}
onChange={(value) => setAttributes({ flexRatio: value })}
/>
)}
<SelectControl <SelectControl
label={ __( 'Placement page', 'woocommerce-paypal-payments' ) } label={ __( 'Placement page', 'woocommerce-paypal-payments' ) }
help={ __( 'Used for the analytics dashboard in the merchant account.', 'woocommerce-paypal-payments' ) } help={ __( 'Used for the analytics dashboard in the merchant account.', 'woocommerce-paypal-payments' ) }
@ -203,20 +212,23 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
value={ placement } value={ placement }
onChange={ ( value ) => setAttributes( { placement: value } ) } onChange={ ( value ) => setAttributes( { placement: value } ) }
/> />
</PanelBody> </PanelBody>
</InspectorControls> </InspectorControls>
<div {...props}> <div {...props}>
<div className={'ppcp-overlay-child'}> <div className='ppcp-overlay-child'>
<PayPalMessages <PayPalScriptProvider options={urlParams}>
style={previewStyle} <PayPalMessages
amount={amount} style={previewStyle}
onRender={() => setRendered(true)} forceReRender={[previewStyle]}
/> onRender={() => setLoaded(true)}
amount={amount}
/>
</PayPalScriptProvider>
</div> </div>
<div className={'ppcp-overlay-child ppcp-unclicable-overlay'}> {/* make the message not clickable */} <div className='ppcp-overlay-child ppcp-unclicable-overlay'> {/* make the message not clickable */}
{!rendered && (<Spinner/>)} {!loaded && <Spinner />}
</div> </div>
</div> </div>
</> </>
); );
} }

View file

@ -1,7 +1,6 @@
import { registerBlockType } from '@wordpress/blocks'; import { registerBlockType } from '@wordpress/blocks';
import Edit from './edit'; import Edit from './edit';
import save from './save';
const paypalIcon = ( const paypalIcon = (
<svg width="584.798" height="720" viewBox="0 0 154.728 190.5"> <svg width="584.798" height="720" viewBox="0 0 154.728 190.5">
@ -18,7 +17,9 @@ const blockId = 'woocommerce-paypal-payments/paylater-messages';
registerBlockType( blockId, { registerBlockType( blockId, {
icon: paypalIcon, icon: paypalIcon,
edit: Edit, edit: Edit,
save, save() {
return null;
},
} ); } );
document.addEventListener( 'DOMContentLoaded', () => { document.addEventListener( 'DOMContentLoaded', () => {

View file

@ -1,26 +0,0 @@
import { useBlockProps } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { layout, logo, position, color, size, flexColor, flexRatio, placement, id } = attributes;
const paypalAttributes = layout === 'flex' ? {
'data-pp-style-layout': 'flex',
'data-pp-style-color': flexColor,
'data-pp-style-ratio': flexRatio,
} : {
'data-pp-style-layout': 'text',
'data-pp-style-logo-type': logo,
'data-pp-style-logo-position': position,
'data-pp-style-text-color': color,
'data-pp-style-text-size': size,
};
if (placement && placement !== 'auto') {
paypalAttributes['data-pp-placement'] = placement;
}
const props = {
className: 'ppcp-paylater-message-block',
id,
...paypalAttributes,
};
return <div { ...useBlockProps.save(props) }></div>;
}

View file

@ -9,10 +9,11 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterBlock; namespace WooCommerce\PayPalCommerce\PayLaterBlock;
use WooCommerce\PayPalCommerce\PayLaterBlock\PayLaterBlockRenderer;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array( return array(
'paylater-block.url' => static function ( ContainerInterface $container ): string { 'paylater-block.url' => static function ( ContainerInterface $container ): string {
/** /**
* Cannot return false for this path. * Cannot return false for this path.
* *
@ -23,4 +24,7 @@ return array(
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php' dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
); );
}, },
'paylater-block.renderer' => static function (): PayLaterBlockRenderer {
return new PayLaterBlockRenderer();
},
); );

View file

@ -99,7 +99,23 @@ class PayLaterBlockModule implements ModuleInterface {
* *
* @psalm-suppress PossiblyFalseArgument * @psalm-suppress PossiblyFalseArgument
*/ */
register_block_type( dirname( realpath( __FILE__ ), 2 ) ); register_block_type(
dirname( realpath( __FILE__ ), 2 ),
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
$renderer = $c->get( 'paylater-block.renderer' );
ob_start();
// phpcs:ignore -- No need to escape it, the PayLaterBlockRenderer class is responsible for escaping.
echo $renderer->render(
// phpcs:ignore
$attributes,
// phpcs:ignore
$c
);
return ob_get_clean();
},
)
);
}, },
20 20
); );

View file

@ -0,0 +1,65 @@
<?php
/**
* Defines the PayLaterBlockRenderer class.
*
* This file is responsible for rendering the Pay Later Messaging block.
*
* @package WooCommerce\PayPalCommerce\PayLaterBlock
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterBlock;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
/**
* Class PayLaterBlockRenderer
*/
class PayLaterBlockRenderer {
/**
* Renders the Pay Later Messaging block.
*
* @param array $attributes The block attributes.
* @param ContainerInterface $c The container.
* @return string The rendered HTML.
*/
public function render( array $attributes, ContainerInterface $c ): string {
if ( PayLaterBlockModule::is_block_enabled( $c->get( 'wcgateway.settings.status' ) ) ) {
$html = '<div id="' . esc_attr( $attributes['id'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
$processor = new \WP_HTML_Tag_Processor( $html );
if ( $processor->next_tag( 'div' ) ) {
$layout = $attributes['layout'] ?? 'text';
if ( 'flex' === $layout ) {
$processor->set_attribute( 'data-pp-style-layout', 'flex' );
$processor->set_attribute( 'data-pp-style-color', esc_attr( $attributes['flexColor'] ?? '' ) );
$processor->set_attribute( 'data-pp-style-ratio', esc_attr( $attributes['flexRatio'] ?? '' ) );
} else {
$processor->set_attribute( 'data-pp-style-layout', 'text' );
$processor->set_attribute( 'data-pp-style-logo-type', esc_attr( $attributes['logo'] ?? '' ) );
$processor->set_attribute( 'data-pp-style-logo-position', esc_attr( $attributes['position'] ?? '' ) );
$processor->set_attribute( 'data-pp-style-text-color', esc_attr( $attributes['color'] ?? '' ) );
$processor->set_attribute( 'data-pp-style-text-size', esc_attr( $attributes['size'] ?? '' ) );
}
if ( ( $attributes['placement'] ?? 'auto' ) !== 'auto' ) {
$processor->set_attribute( 'data-pp-placement', esc_attr( $attributes['placement'] ) );
}
}
$updated_html = $processor->get_updated_html();
return sprintf(
'<div id="ppcp-paylater-message-block" %1$s>%2$s</div>',
wp_kses_data( get_block_wrapper_attributes() ),
$updated_html
);
}
return '';
}
}

View file

@ -1005,6 +1005,28 @@
"@jridgewell/resolve-uri" "3.1.0" "@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14" "@jridgewell/sourcemap-codec" "1.4.14"
"@paypal/paypal-js@^8.0.4":
version "8.0.4"
resolved "https://registry.yarnpkg.com/@paypal/paypal-js/-/paypal-js-8.0.4.tgz#abe9f40f519b1d2c306adddfbe733be03eb26ce5"
integrity sha512-91g5fhRBHGEBoikDzQT6uBn3PzlJQ75g0c3MvqVJqN0XRm5kHa9wz+6+Uaq8QQuxRzz5C2x55Zg057CW6EuwpQ==
dependencies:
promise-polyfill "^8.3.0"
"@paypal/react-paypal-js@^8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@paypal/react-paypal-js/-/react-paypal-js-8.2.0.tgz#4b1a142bbb68e62dca4a92da4a6b5568f54901f0"
integrity sha512-SworUfu0BNNcqoh0O53Ke4MFpx2m3qJRu3hayXvlluEEXJpKqGSV5aaSGFhbsZqi8hnbsx/hZR7BQbmqsggiGQ==
dependencies:
"@paypal/paypal-js" "^8.0.4"
"@paypal/sdk-constants" "^1.0.122"
"@paypal/sdk-constants@^1.0.122":
version "1.0.145"
resolved "https://registry.yarnpkg.com/@paypal/sdk-constants/-/sdk-constants-1.0.145.tgz#f373cd3b7cf0409c28e121629b8f1855faf2e77b"
integrity sha512-2tclrVX3L44YRJ09H4kkqma/UeAjRJarwH5SyPip10O5S+2ByE1HiyspAJ6hIWSjMngFVqjNyUCnrGcuQA3ldg==
dependencies:
hi-base32 "^0.5.0"
"@types/eslint-scope@^3.7.3": "@types/eslint-scope@^3.7.3":
version "3.7.4" version "3.7.4"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16" resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16"
@ -1179,7 +1201,7 @@
resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1" resolved "https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1"
integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q== integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q==
"@woocommerce/dependency-extraction-webpack-plugin@^2.2.0": "@woocommerce/dependency-extraction-webpack-plugin@2.2.0":
version "2.2.0" version "2.2.0"
resolved "https://registry.yarnpkg.com/@woocommerce/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz#230d674a67585bc32e31bc28485bec99b41dbd1f" resolved "https://registry.yarnpkg.com/@woocommerce/dependency-extraction-webpack-plugin/-/dependency-extraction-webpack-plugin-2.2.0.tgz#230d674a67585bc32e31bc28485bec99b41dbd1f"
integrity sha512-0wDY3EIUwWrPm0KrWvt1cf2SZDSX7CzBXvv4TyCqWOPuVPvC/ajyY8kD1HTFI80q6/RHoxWf3BYCmhuBzPbe9A== integrity sha512-0wDY3EIUwWrPm0KrWvt1cf2SZDSX7CzBXvv4TyCqWOPuVPvC/ajyY8kD1HTFI80q6/RHoxWf3BYCmhuBzPbe9A==
@ -1599,6 +1621,11 @@ has@^1.0.3:
dependencies: dependencies:
function-bind "^1.1.1" function-bind "^1.1.1"
hi-base32@^0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/hi-base32/-/hi-base32-0.5.1.tgz#1279f2ddae2673219ea5870c2121d2a33132857e"
integrity sha512-EmBBpvdYh/4XxsnUybsPag6VikPYnN30td+vQk+GI3qpahVEG9+gTkG0aXVxTjBqQ5T6ijbWIu77O+C5WFWsnA==
immutable@^4.0.0: immutable@^4.0.0:
version "4.1.0" version "4.1.0"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.1.0.tgz#f795787f0db780183307b9eb2091fcac1f6fafef" resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.1.0.tgz#f795787f0db780183307b9eb2091fcac1f6fafef"
@ -1674,7 +1701,7 @@ jest-worker@^27.4.5:
merge-stream "^2.0.0" merge-stream "^2.0.0"
supports-color "^8.0.0" supports-color "^8.0.0"
js-tokens@^4.0.0: "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
@ -1745,6 +1772,13 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow== integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==
loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
make-dir@^3.0.2, make-dir@^3.1.0: make-dir@^3.0.2, make-dir@^3.1.0:
version "3.1.0" version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
@ -1789,6 +1823,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==
p-limit@^2.2.0: p-limit@^2.2.0:
version "2.3.0" version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
@ -1840,6 +1879,11 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0:
dependencies: dependencies:
find-up "^4.0.0" find-up "^4.0.0"
promise-polyfill@^8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.3.0.tgz#9284810268138d103807b11f4e23d5e945a4db63"
integrity sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==
punycode@^2.1.0: punycode@^2.1.0:
version "2.1.1" version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
@ -1852,6 +1896,23 @@ randombytes@^2.1.0:
dependencies: dependencies:
safe-buffer "^5.1.0" safe-buffer "^5.1.0"
react-dom@^17.0.0:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"
react@^17.0.0:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
readdirp@~3.6.0: readdirp@~3.6.0:
version "3.6.0" version "3.6.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7" resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
@ -1957,6 +2018,14 @@ sass@^1.42.1:
immutable "^4.0.0" immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0" source-map-js ">=0.6.2 <2.0.0"
scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
schema-utils@^2.6.5: schema-utils@^2.6.5:
version "2.7.1" version "2.7.1"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7"

View file

@ -0,0 +1,14 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": "3.25.0"
}
],
[
"@babel/preset-react"
]
]
}

View file

@ -0,0 +1,3 @@
node_modules
assets/js
assets/css

View file

@ -0,0 +1,17 @@
{
"name": "woocommerce/ppcp-paylater-wc-blocks",
"type": "dhii-mod",
"description": "Pay Later WooCommerce Blocks module for PPCP",
"license": "GPL-2.0",
"require": {
"php": "^7.2 | ^8.0",
"dhii/module-interface": "^0.3.0-alpha1"
},
"autoload": {
"psr-4": {
"WooCommerce\\PayPalCommerce\\PayLaterWCBlocks\\": "src"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View file

@ -0,0 +1,156 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "bbff959c846d515b5cfe39e6d175972b",
"packages": [
{
"name": "container-interop/service-provider",
"version": "v0.4.1",
"source": {
"type": "git",
"url": "https://github.com/container-interop/service-provider.git",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/container-interop/service-provider/zipball/e04441ca21ef03e10dce70b0af29269281eec6dc",
"reference": "e04441ca21ef03e10dce70b0af29269281eec6dc",
"shasum": ""
},
"require": {
"psr/container": "^1.0 || ^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Interop\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Promoting container interoperability through standard service providers",
"homepage": "https://github.com/container-interop/service-provider",
"support": {
"issues": "https://github.com/container-interop/service-provider/issues",
"source": "https://github.com/container-interop/service-provider/tree/v0.4.1"
},
"time": "2023-12-14T14:50:12+00:00"
},
{
"name": "dhii/module-interface",
"version": "v0.3.0-alpha2",
"source": {
"type": "git",
"url": "https://github.com/Dhii/module-interface.git",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dhii/module-interface/zipball/0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"reference": "0e39f167d7ed8990c82f5d2e6084159d1a502a5b",
"shasum": ""
},
"require": {
"container-interop/service-provider": "^0.4",
"php": "^7.1 | ^8.0",
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
"slevomat/coding-standard": "^6.0",
"vimeo/psalm": "^3.11.7 | ^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.3.x-dev"
}
},
"autoload": {
"psr-4": {
"Dhii\\Modular\\Module\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dhii Team",
"email": "development@dhii.co"
}
],
"description": "Interfaces for modules",
"support": {
"issues": "https://github.com/Dhii/module-interface/issues",
"source": "https://github.com/Dhii/module-interface/tree/v0.3.0-alpha2"
},
"time": "2021-08-23T08:23:01+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"shasum": ""
},
"require": {
"php": ">=7.4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"support": {
"issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/1.1.2"
},
"time": "2021-11-05T16:50:12+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.2 | ^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View file

@ -0,0 +1,12 @@
<?php
/**
* The Pay Later WooCommerce Blocks module extensions.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
return array();

View file

@ -0,0 +1,16 @@
<?php
/**
* The Pay Later WooCommerce Blocks module.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
return static function (): ModuleInterface {
return new PayLaterWCBlocksModule();
};

View file

@ -0,0 +1,36 @@
{
"name": "ppcp-paylater-wc-blocks",
"version": "1.0.0",
"license": "GPL-3.0-or-later",
"browserslist": [
"> 0.5%",
"Safari >= 8",
"Chrome >= 41",
"Firefox >= 43",
"Edge >= 14"
],
"dependencies": {
"@paypal/react-paypal-js": "^8.2.0",
"core-js": "^3.25.0",
"react": "^17.0.0",
"react-dom": "^17.0.0"
},
"devDependencies": {
"@babel/core": "^7.19",
"@babel/preset-env": "^7.19",
"@babel/preset-react": "^7.18.6",
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
"babel-loader": "^8.2",
"cross-env": "^7.0.3",
"file-loader": "^6.2.0",
"sass": "^1.42.1",
"sass-loader": "^12.1.0",
"webpack": "^5.76",
"webpack-cli": "^4.10"
},
"scripts": {
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
"dev": "cross-env BABEL_ENV=default webpack --watch"
}
}

View file

@ -0,0 +1,33 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "woocommerce-paypal-payments/cart-paylater-messages",
"title": "Cart - PayPal Pay Later messaging",
"category": "woocommerce-paypal-payments",
"description": "PayPal Pay Later messaging will be displayed for eligible customers. Customers automatically see the most relevant Pay Later offering.",
"example": {},
"parent": [ "woocommerce/cart-totals-block" ],
"attributes": {
"blockId": {
"type": "string",
"default": "woocommerce-paypal-payments/cart-paylater-messages"
},
"ppcpId": {
"type": "string"
},
"lock": {
"type": "object",
"default": {
"remove": true,
"move": false
}
}
},
"supports": {
"html": false,
"inserter": false,
"multiple": false
},
"textdomain": "woocommerce-paypal-payments",
"editorScript": "ppcp-cart-paylater-block"
}

View file

@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import Edit from './edit';
import metadata from './block.json';
const paypalIcon = (
<svg width="584.798" height="720" viewBox="0 0 154.728 190.5">
<g transform="translate(898.192 276.071)">
<path
clipPath="none"
d="M-837.663-237.968a5.49 5.49 0 0 0-5.423 4.633l-9.013 57.15-8.281 52.514-.005.044.01-.044 8.281-52.514c.421-2.669 2.719-4.633 5.42-4.633h26.404c26.573 0 49.127-19.387 53.246-45.658.314-1.996.482-3.973.52-5.924v-.003h-.003c-6.753-3.543-14.683-5.565-23.372-5.565z"
fill="#001c64"
/>
<path
clipPath="none"
d="M-766.506-232.402c-.037 1.951-.207 3.93-.52 5.926-4.119 26.271-26.673 45.658-53.246 45.658h-26.404c-2.701 0-4.999 1.964-5.42 4.633l-8.281 52.514-5.197 32.947a4.46 4.46 0 0 0 4.405 5.153h28.66a5.49 5.49 0 0 0 5.423-4.633l7.55-47.881c.423-2.669 2.722-4.636 5.423-4.636h16.876c26.573 0 49.124-19.386 53.243-45.655 2.924-18.649-6.46-35.614-22.511-44.026z"
fill="#0070e0"
/>
<path
clipPath="none"
d="M-870.225-276.071a5.49 5.49 0 0 0-5.423 4.636l-22.489 142.608a4.46 4.46 0 0 0 4.405 5.156h33.351l8.281-52.514 9.013-57.15a5.49 5.49 0 0 1 5.423-4.633h47.782c8.691 0 16.621 2.025 23.375 5.563.46-23.917-19.275-43.666-46.412-43.666z"
fill="#003087"
/>
</g>
</svg>
);
registerBlockType(metadata, {
icon: paypalIcon,
edit: Edit,
save() {
return null;
},
});

View file

@ -0,0 +1,138 @@
import { __ } from '@wordpress/i18n';
import { useState, useEffect } from '@wordpress/element';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, Spinner } from '@wordpress/components';
import { PayPalScriptProvider, PayPalMessages } from '@paypal/react-paypal-js';
import { useScriptParams } from '../../../../ppcp-paylater-block/resources/js/hooks/script-params';
export default function Edit({ attributes, clientId, setAttributes }) {
const { id, ppcpId } = attributes;
const [loaded, setLoaded] = useState(false);
let amount;
const postContent = String(wp.data.select('core/editor')?.getEditedPostContent());
if (postContent.includes('woocommerce/checkout') || postContent.includes('woocommerce/cart')) {
amount = 50.0;
}
const cartConfig = PcpCartPayLaterBlock.config.cart;
// Dynamically setting previewStyle based on the layout attribute
let previewStyle = {};
if (cartConfig.layout === 'flex') {
previewStyle = {
layout: cartConfig.layout,
color: cartConfig.color,
ratio: cartConfig.ratio,
};
} else {
previewStyle = {
layout: cartConfig.layout,
logo: {
position: cartConfig['logo-position'],
type: cartConfig['logo-type'],
},
text: {
color: cartConfig['text-color'],
size: cartConfig['text-size'],
},
};
}
let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent'];
if (PcpCartPayLaterBlock.vaultingEnabled || !PcpCartPayLaterBlock.placementEnabled) {
classes = [...classes, 'ppcp-paylater-unavailable', 'block-editor-warning'];
}
const props = useBlockProps({ className: classes.join(' ') });
useEffect(() => {
if (!ppcpId) {
setAttributes({ ppcpId: `ppcp-${clientId}` });
}
}, [ppcpId, clientId]);
if (PcpCartPayLaterBlock.vaultingEnabled) {
return (
<div {...props}>
<div className='block-editor-warning__contents'>
<p className='block-editor-warning__message'>
{__('Cart - Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}
</p>
<div className='block-editor-warning__actions'>
<span className='block-editor-warning__action'>
<a href={PcpCartPayLaterBlock.settingsUrl}>
<button type='button' className='components-button is-primary'>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</span>
</div>
</div>
</div>
);
}
if (!PcpCartPayLaterBlock.placementEnabled) {
return (
<div {...props}>
<div className='block-editor-warning__contents'>
<p className='block-editor-warning__message'>
{__('Cart - Pay Later Messaging cannot be used while the “Cart” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}
</p>
<div className='block-editor-warning__actions'>
<span className='block-editor-warning__action'>
<a href={PcpCartPayLaterBlock.payLaterSettingsUrl}>
<button type='button' className='components-button is-primary'>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</span>
</div>
</div>
</div>
);
}
const scriptParams = useScriptParams(PcpCartPayLaterBlock.ajax.cart_script_params);
if (scriptParams === null) {
return <div {...props}><Spinner /></div>;
}
const urlParams = {
...scriptParams.url_params,
components: 'messages',
dataNamespace: 'ppcp-block-editor-cart-paylater-message',
};
return (
<>
<InspectorControls>
<PanelBody title={__('Customize your messaging', 'woocommerce-paypal-payments')}>
<p>
{__('Choose the layout and color of your messaging in the PayPal Payments Pay Later settings for the “Cart” messaging placement.', 'woocommerce-paypal-payments')}
</p>
<a href={PcpCartPayLaterBlock.payLaterSettingsUrl}>
<button type='button' className='components-button is-primary'>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</PanelBody>
</InspectorControls>
<div {...props}>
<div className='ppcp-overlay-child'>
<PayPalScriptProvider options={urlParams}>
<PayPalMessages
style={previewStyle}
onRender={() => setLoaded(true)}
amount={amount}
/>
</PayPalScriptProvider>
</div>
<div className='ppcp-overlay-child ppcp-unclicable-overlay'> {/* make the message not clickable */}
{!loaded && <Spinner />}
</div>
</div>
</>
);
}

View file

@ -0,0 +1,33 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "woocommerce-paypal-payments/checkout-paylater-messages",
"title": "Checkout - PayPal Pay Later messaging",
"category": "woocommerce-paypal-payments",
"description": "PayPal Pay Later messaging will be displayed for eligible customers. Customers automatically see the most relevant Pay Later offering.",
"example": {},
"parent": [ "woocommerce/checkout-totals-block" ],
"attributes": {
"blockId": {
"type": "string",
"default": "woocommerce-paypal-payments/checkout-paylater-messages"
},
"ppcpId": {
"type": "string"
},
"lock": {
"type": "object",
"default": {
"remove": true,
"move": false
}
}
},
"supports": {
"html": false,
"inserter": false,
"multiple": false
},
"textdomain": "woocommerce-paypal-payments",
"editorScript": "ppcp-checkout-paylater-block"
}

View file

@ -0,0 +1,41 @@
/**
* External dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import Edit from './edit';
import metadata from './block.json';
const paypalIcon = (
<svg width="584.798" height="720" viewBox="0 0 154.728 190.5">
<g transform="translate(898.192 276.071)">
<path
clipPath="none"
d="M-837.663-237.968a5.49 5.49 0 0 0-5.423 4.633l-9.013 57.15-8.281 52.514-.005.044.01-.044 8.281-52.514c.421-2.669 2.719-4.633 5.42-4.633h26.404c26.573 0 49.127-19.387 53.246-45.658.314-1.996.482-3.973.52-5.924v-.003h-.003c-6.753-3.543-14.683-5.565-23.372-5.565z"
fill="#001c64"
/>
<path
clipPath="none"
d="M-766.506-232.402c-.037 1.951-.207 3.93-.52 5.926-4.119 26.271-26.673 45.658-53.246 45.658h-26.404c-2.701 0-4.999 1.964-5.42 4.633l-8.281 52.514-5.197 32.947a4.46 4.46 0 0 0 4.405 5.153h28.66a5.49 5.49 0 0 0 5.423-4.633l7.55-47.881c.423-2.669 2.722-4.636 5.423-4.636h16.876c26.573 0 49.124-19.386 53.243-45.655 2.924-18.649-6.46-35.614-22.511-44.026z"
fill="#0070e0"
/>
<path
clipPath="none"
d="M-870.225-276.071a5.49 5.49 0 0 0-5.423 4.636l-22.489 142.608a4.46 4.46 0 0 0 4.405 5.156h33.351l8.281-52.514 9.013-57.15a5.49 5.49 0 0 1 5.423-4.633h47.782c8.691 0 16.621 2.025 23.375 5.563.46-23.917-19.275-43.666-46.412-43.666z"
fill="#003087"
/>
</g>
</svg>
);
registerBlockType(metadata, {
icon: paypalIcon,
edit: Edit,
save() {
return null;
},
});

View file

@ -0,0 +1,132 @@
import { __ } from '@wordpress/i18n';
import { useState, useEffect } from '@wordpress/element';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, Spinner } from '@wordpress/components';
import { PayPalScriptProvider, PayPalMessages } from '@paypal/react-paypal-js';
import { useScriptParams } from '../../../../ppcp-paylater-block/resources/js/hooks/script-params';
export default function Edit({ attributes, clientId, setAttributes }) {
const { id, ppcpId } = attributes;
const [loaded, setLoaded] = useState(false);
let amount = undefined;
const postContent = String(wp.data.select('core/editor')?.getEditedPostContent());
if (postContent.includes('woocommerce/checkout') || postContent.includes('woocommerce/cart')) {
amount = 50.0;
}
const checkoutConfig = PcpCheckoutPayLaterBlock.config.checkout;
// Dynamically setting previewStyle based on the layout attribute
let previewStyle = {};
if (checkoutConfig.layout === 'flex') {
previewStyle = {
layout: checkoutConfig.layout,
color: checkoutConfig.color,
ratio: checkoutConfig.ratio,
};
} else {
previewStyle = {
layout: checkoutConfig.layout,
logo: {
position: checkoutConfig['logo-position'],
type: checkoutConfig['logo-type'],
},
text: {
color: checkoutConfig['text-color'],
size: checkoutConfig['text-size'],
},
};
}
let classes = ['ppcp-paylater-block-preview', 'ppcp-overlay-parent'];
if (PcpCheckoutPayLaterBlock.vaultingEnabled || !PcpCheckoutPayLaterBlock.placementEnabled) {
classes = ['ppcp-paylater-block-preview', 'ppcp-paylater-unavailable', 'block-editor-warning'];
}
const props = useBlockProps({ className: classes });
useEffect(() => {
if (!ppcpId) {
setAttributes({ ppcpId: 'ppcp-' + clientId });
}
}, [ppcpId, clientId]);
if (PcpCheckoutPayLaterBlock.vaultingEnabled) {
return (
<div {...props}>
<div className={'block-editor-warning__contents'}>
<p className={'block-editor-warning__message'}>{__('Checkout - Pay Later Messaging cannot be used while PayPal Vaulting is active. Disable PayPal Vaulting in the PayPal Payment settings to reactivate this block', 'woocommerce-paypal-payments')}</p>
<div className={'block-editor-warning__actions'}>
<span className={'block-editor-warning__action'}>
<a href={PcpCheckoutPayLaterBlock.settingsUrl}>
<button type={'button'} className={'components-button is-primary'}>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</span>
</div>
</div>
</div>
);
}
if (!PcpCheckoutPayLaterBlock.placementEnabled) {
return (
<div {...props}>
<div className={'block-editor-warning__contents'}>
<p className={'block-editor-warning__message'}>{__('Checkout - Pay Later Messaging cannot be used while the “Checkout” messaging placement is disabled. Enable the placement in the PayPal Payments Pay Later settings to reactivate this block.', 'woocommerce-paypal-payments')}</p>
<div className={'block-editor-warning__actions'}>
<span className={'block-editor-warning__action'}>
<a href={PcpCheckoutPayLaterBlock.payLaterSettingsUrl}>
<button type={'button'} className={'components-button is-primary'}>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</span>
</div>
</div>
</div>
);
}
const scriptParams = useScriptParams(PcpCheckoutPayLaterBlock.ajax.cart_script_params);
if (scriptParams === null) {
return <div {...props}><Spinner/></div>;
}
const urlParams = {
...scriptParams.url_params,
components: 'messages',
dataNamespace: 'ppcp-block-editor-checkout-paylater-message',
};
return (
<>
<InspectorControls>
<PanelBody title={__('Customize your messaging', 'woocommerce-paypal-payments')}>
<p>{__('Choose the layout and color of your messaging in the PayPal Payments Pay Later settings for the “Checkout” messaging placement.', 'woocommerce-paypal-payments')}</p>
<a href={PcpCheckoutPayLaterBlock.payLaterSettingsUrl}>
<button type={'button'} className={'components-button is-primary'}>
{__('PayPal Payments Settings', 'woocommerce-paypal-payments')}
</button>
</a>
</PanelBody>
</InspectorControls>
<div {...props}>
<div className={'ppcp-overlay-child'}>
<PayPalScriptProvider options={urlParams}>
<PayPalMessages
style={previewStyle}
onRender={() => setLoaded(true)}
amount={amount}
/>
</PayPalScriptProvider>
</div>
<div className={'ppcp-overlay-child ppcp-unclicable-overlay'}> {/* make the message not clickable */}
{!loaded && <Spinner/>}
</div>
</div>
</>
);
}

View file

@ -0,0 +1,30 @@
<?php
/**
* The Pay Later WooCommerce Blocks module services.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array(
'paylater-wc-blocks.url' => static function ( ContainerInterface $container ): string {
/**
* Cannot return false for this path.
*
* @psalm-suppress PossiblyFalseArgument
*/
return plugins_url(
'/modules/ppcp-paylater-wc-blocks/',
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
);
},
'paylater-wc-blocks.renderer' => static function (): PayLaterWCBlocksRenderer {
return new PayLaterWCBlocksRenderer();
},
);

View file

@ -0,0 +1,257 @@
<?php
/**
* The Pay Later WooCommerce Blocks module.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
use WooCommerce\PayPalCommerce\Button\Endpoint\CartScriptParamsEndpoint;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WooCommerce\PayPalCommerce\PayLaterWCBlocks\PayLaterWCBlocksUtils;
/**
* Class PayLaterWCBlocksModule
*/
class PayLaterWCBlocksModule implements ModuleInterface {
/**
* Returns whether the block module should be loaded.
*
* @return bool true if the module should be loaded, otherwise false.
*/
public static function is_module_loading_required(): bool {
return apply_filters(
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'woocommerce.feature-flags.woocommerce_paypal_payments.paylater_wc_blocks_enabled',
getenv( 'PCP_PAYLATER_WC_BLOCKS' ) !== '0'
);
}
/**
* Returns whether the block is enabled.
*
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $location The location to check.
* @return bool true if the block is enabled, otherwise false.
*/
public static function is_block_enabled( SettingsStatus $settings_status, string $location ): bool {
return self::is_module_loading_required() && $settings_status->is_pay_later_messaging_enabled_for_location( $location );
}
/**
* Returns whether the placement is enabled.
*
* @param SettingsStatus $settings_status The Settings status helper.
* @param string $location The location to check.
* @return bool true if the placement is enabled, otherwise false.
*/
public static function is_placement_enabled( SettingsStatus $settings_status, string $location ) : bool {
return self::is_block_enabled( $settings_status, $location );
}
/**
* {@inheritDoc}
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
$messages_apply = $c->get( 'button.helper.messages-apply' );
assert( $messages_apply instanceof MessagesApply );
if ( ! $messages_apply->for_country() ) {
return;
}
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );
add_action(
'init',
function () use ( $c, $settings ): void {
$config_factory = $c->get( 'paylater-configurator.factory.config' );
assert( $config_factory instanceof ConfigFactory );
$script_handle = 'ppcp-cart-paylater-block';
wp_register_script(
$script_handle,
$c->get( 'paylater-wc-blocks.url' ) . 'assets/js/cart-paylater-block.js',
array(),
$c->get( 'ppcp.asset-version' ),
true
);
wp_localize_script(
$script_handle,
'PcpCartPayLaterBlock',
array(
'ajax' => array(
'cart_script_params' => array(
'endpoint' => \WC_AJAX::get_endpoint( CartScriptParamsEndpoint::ENDPOINT ),
),
),
'config' => $config_factory->from_settings( $settings ),
'settingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ),
'vaultingEnabled' => $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ),
'placementEnabled' => self::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), 'cart' ),
'payLaterSettingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-pay-later' ),
)
);
$script_handle = 'ppcp-checkout-paylater-block';
wp_register_script(
$script_handle,
$c->get( 'paylater-wc-blocks.url' ) . 'assets/js/checkout-paylater-block.js',
array(),
$c->get( 'ppcp.asset-version' ),
true
);
wp_localize_script(
$script_handle,
'PcpCheckoutPayLaterBlock',
array(
'ajax' => array(
'cart_script_params' => array(
'endpoint' => \WC_AJAX::get_endpoint( CartScriptParamsEndpoint::ENDPOINT ),
),
),
'config' => $config_factory->from_settings( $settings ),
'settingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' ),
'vaultingEnabled' => $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ),
'placementEnabled' => self::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), 'checkout' ),
'payLaterSettingsUrl' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-pay-later' ),
)
);
},
20
);
/**
* Registers slugs as block categories with WordPress.
*/
add_action(
'block_categories_all',
function ( array $categories ): array {
return array_merge(
$categories,
array(
array(
'slug' => 'woocommerce-paypal-payments',
'title' => __( 'PayPal Blocks', 'woocommerce-paypal-payments' ),
),
)
);
},
10,
2
);
/**
* Cannot return false for this path.
*
* @psalm-suppress PossiblyFalseArgument
*/
if ( function_exists( 'register_block_type' ) ) {
register_block_type(
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CartPayLaterMessagesBlock',
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
return PayLaterWCBlocksUtils::render_paylater_block(
$attributes['blockId'] ?? 'woocommerce-paypal-payments/cart-paylater-messages',
$attributes['ppcpId'] ?? 'ppcp-cart-paylater-messages',
'cart',
$c
);
},
)
);
}
/**
* Cannot return false for this path.
*
* @psalm-suppress PossiblyFalseArgument
*/
if ( function_exists( 'register_block_type' ) ) {
register_block_type(
dirname( realpath( __FILE__ ), 2 ) . '/resources/js/CheckoutPayLaterMessagesBlock',
array(
'render_callback' => function ( array $attributes ) use ( $c ) {
return PayLaterWCBlocksUtils::render_paylater_block(
$attributes['blockId'] ?? 'woocommerce-paypal-payments/checkout-paylater-messages',
$attributes['ppcpId'] ?? 'ppcp-checkout-paylater-messages',
'checkout',
$c
);
},
)
);
}
// This is a fallback for the default Cart block that haven't been saved with the inserted Pay Later messaging block.
add_filter(
'render_block_woocommerce/cart-totals-block',
function ( string $block_content ) use ( $c ) {
if ( false === strpos( $block_content, 'woocommerce-paypal-payments/cart-paylater-messages' ) ) {
return PayLaterWCBlocksUtils::render_and_insert_paylater_block(
$block_content,
'woocommerce-paypal-payments/cart-paylater-messages',
'ppcp-cart-paylater-messages',
'cart',
$c
);
}
return $block_content;
},
10,
1
);
// This is a fallback for the default Checkout block that haven't been saved with the inserted Checkout - Pay Later messaging block.
add_filter(
'render_block_woocommerce/checkout-totals-block',
function ( string $block_content ) use ( $c ) {
if ( false === strpos( $block_content, 'woocommerce-paypal-payments/checkout-paylater-messages' ) ) {
return PayLaterWCBlocksUtils::render_and_insert_paylater_block(
$block_content,
'woocommerce-paypal-payments/checkout-paylater-messages',
'ppcp-checkout-paylater-messages',
'checkout',
$c
);
}
return $block_content;
},
10,
1
);
}
/**
* Returns the key for the module.
*
* @return void
*/
public function getKey() {
}
}

View file

@ -0,0 +1,32 @@
<?php
/**
* The Pay Later WooCommerce Blocks Renderer.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
/**
* Class PayLaterWCBlocksRenderer
*/
class PayLaterWCBlocksRenderer {
/**
* Renders the WC Pay Later Messaging blocks.
*
* @param array $attributes The block attributes.
* @param string $location The location of the block.
* @param ContainerInterface $c The container.
* @return string|void
*/
public function render( array $attributes, string $location, ContainerInterface $c ) {
if ( PayLaterWCBlocksModule::is_placement_enabled( $c->get( 'wcgateway.settings.status' ), $location ) ) {
return '<div id="' . esc_attr( $attributes['ppcpId'] ?? '' ) . '" data-block-name="' . esc_attr( $attributes['blockId'] ?? '' ) . '" class="ppcp-messages" data-partner-attribution-id="Woo_PPCP"></div>';
}
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
* The Pay Later WooCommerce Blocks Utils.
*
* @package WooCommerce\PayPalCommerce\PayLaterWCBlocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\PayLaterWCBlocks;
/**
* Class PayLaterWCBlocksUtils
*/
class PayLaterWCBlocksUtils {
/**
* Inserts content before the last div in a block.
*
* @param string $block_content The block content.
* @param string $content_to_insert The content to insert.
* @return string The block content with the content inserted.
*/
public static function insert_before_last_div( string $block_content, string $content_to_insert ): string {
$last_index = strrpos( $block_content, '</div>' );
if ( $last_index !== false ) {
$block_content = substr_replace( $block_content, $content_to_insert, $last_index, 0 );
}
return $block_content;
}
/**
* Renders a PayLater message block and inserts it before the last closing div tag if the block id is not already present.
*
* @param string $block_content Current content of the block.
* @param string $block_id ID of the block to render.
* @param string $ppcp_id ID for the PPCP component.
* @param string $context Rendering context (cart or checkout).
* @param mixed $container Dependency injection container.
* @return string Updated block content.
*/
public static function render_and_insert_paylater_block( string $block_content, string $block_id, string $ppcp_id, string $context, $container ): string {
$paylater_message_block = self::render_paylater_block( $block_id, $ppcp_id, $context, $container );
if ( false !== $paylater_message_block ) {
return self::insert_before_last_div( $block_content, $paylater_message_block );
}
return $block_content;
}
/**
* Renders the PayLater block based on the provided parameters.
*
* @param string $block_id ID of the block to render.
* @param string $ppcp_id ID for the PPCP component.
* @param string $context Rendering context (cart or checkout).
* @param mixed $container Dependency injection container.
* @return false|string Rendered content.
*/
public static function render_paylater_block( string $block_id, string $ppcp_id, string $context, $container ) {
$renderer = $container->get( 'paylater-wc-blocks.renderer' );
ob_start();
// phpcs:ignore -- No need to escape it, the PayLaterWCBlocksRenderer class is responsible for escaping.
echo $renderer->render(
array(
// phpcs:ignore
'blockId' => $block_id,
// phpcs:ignore
'ppcpId' => $ppcp_id,
),
// phpcs:ignore
$context,
// phpcs:ignore
$container
);
return ob_get_clean();
}
}

View file

@ -0,0 +1,56 @@
const path = require("path");
const isProduction = process.env.NODE_ENV === "production";
const DependencyExtractionWebpackPlugin = require("@woocommerce/dependency-extraction-webpack-plugin");
module.exports = {
devtool: isProduction ? "source-map" : "eval-source-map",
mode: isProduction ? "production" : "development",
target: "web",
plugins: [new DependencyExtractionWebpackPlugin()],
entry: {
"cart-paylater-block": path.resolve(
process.cwd(),
"resources",
"js",
"CartPayLaterMessagesBlock",
"cart-paylater-block.js"
),
"checkout-paylater-block": path.resolve(
process.cwd(),
"resources",
"js",
"CheckoutPayLaterMessagesBlock",
"checkout-paylater-block.js"
),
},
output: {
path: path.resolve(__dirname, "assets/"),
filename: "js/[name].js",
},
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: "file-loader",
options: {
name: "css/[name].css",
},
},
{ loader: "sass-loader" },
],
},
],
},
};

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@
"install:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn install", "install:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn install",
"install:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn install", "install:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn install",
"install:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn install", "install:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn install",
"install:modules:ppcp-paylater-wc-blocks": "cd modules/ppcp-paylater-wc-blocks && yarn install",
"install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install", "install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install",
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install", "install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install", "install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
@ -25,6 +26,7 @@
"build:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run build", "build:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run build",
"build:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run build", "build:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run build",
"build:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn run build", "build:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn run build",
"build:modules:ppcp-paylater-wc-blocks": "cd modules/ppcp-paylater-wc-blocks && yarn run build",
"build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build", "build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build",
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build", "build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build", "build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
@ -41,6 +43,7 @@
"watch:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run watch", "watch:modules:ppcp-applepay": "cd modules/ppcp-applepay && yarn run watch",
"watch:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run watch", "watch:modules:ppcp-blocks": "cd modules/ppcp-blocks && yarn run watch",
"watch:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn run watch", "watch:modules:ppcp-paylater-block": "cd modules/ppcp-paylater-block && yarn run watch",
"watch:modules:ppcp-paylater-wc-blocks": "cd modules/ppcp-paylater-wc-blocks && yarn run watch",
"watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch", "watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch",
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch", "watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch", "watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
@ -89,6 +92,8 @@
}, },
"dependencies": { "dependencies": {
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"npm-run-all": "^4.1.5" "npm-run-all": "^4.1.5",
"playwright": "^1.43.0",
"run-s": "^0.0.0"
} }
} }

View file

@ -131,6 +131,11 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg== integrity sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==
fsevents@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
function-bind@^1.1.1: function-bind@^1.1.1:
version "1.1.1" version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
@ -427,6 +432,20 @@ pify@^3.0.0:
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg== integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
playwright-core@1.43.0:
version "1.43.0"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.43.0.tgz#d8079acb653abebb0b63062e432479647a4e1271"
integrity sha512-iWFjyBUH97+pUFiyTqSLd8cDMMOS0r2ZYz2qEsPjH8/bX++sbIJT35MSwKnp1r/OQBAqC5XO99xFbJ9XClhf4w==
playwright@^1.43.0:
version "1.43.0"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.43.0.tgz#2c2efd4ee2a25defd8c24c98ccb342bdd9d435f5"
integrity sha512-SiOKHbVjTSf6wHuGCbqrEyzlm6qvXcv7mENP+OZon1I07brfZLGdfWV0l/efAzVx7TF3Z45ov1gPEkku9q25YQ==
dependencies:
playwright-core "1.43.0"
optionalDependencies:
fsevents "2.3.2"
read-pkg@^3.0.0: read-pkg@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389" resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-3.0.0.tgz#9cbc686978fee65d16c00e2b19c237fcf6e38389"
@ -454,6 +473,11 @@ resolve@^1.10.0:
path-parse "^1.0.7" path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0" supports-preserve-symlinks-flag "^1.0.0"
run-s@^0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/run-s/-/run-s-0.0.0.tgz#599912be20c00ba7698655c9936d075d31b71754"
integrity sha512-KPDNauF2Tpnm3nG0+0LJuJxwBFrhAdthpM8bVdDvjWQA7pWP7QoNwEl1+dJ7WVJj81AQP/i6kl6JUmAk7tg3Og==
safe-regex-test@^1.0.0: safe-regex-test@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/safe-regex-test/-/safe-regex-test-1.0.0.tgz#793b874d524eb3640d1873aad03596db2d4f2295" resolved "https://registry.yarnpkg.com/safe-regex-test/-/safe-regex-test-1.0.0.tgz#793b874d524eb3640d1873aad03596db2d4f2295"