mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Migrate the PayPal buttons inside of the Express Checkout in the editor to @paypal/react-paypal-js with a unique namespace to avoid conflicts with the Pay Later messaging block
This commit is contained in:
parent
8b4594ad92
commit
40e8aa2874
4 changed files with 62 additions and 5 deletions
|
@ -10,6 +10,7 @@
|
||||||
"Edge >= 14"
|
"Edge >= 14"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@paypal/react-paypal-js": "^8.2.0",
|
||||||
"core-js": "^3.25.0"
|
"core-js": "^3.25.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -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'
|
||||||
|
@ -500,6 +501,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;
|
||||||
|
|
||||||
|
@ -564,7 +589,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;
|
||||||
|
@ -580,7 +605,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) {
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -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"
|
||||||
|
@ -1840,6 +1867,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"
|
||||||
|
|
|
@ -90,13 +90,12 @@ export default function Edit( { attributes, clientId, setAttributes } ) {
|
||||||
return (<div {...props}><Spinner/></div>)
|
return (<div {...props}><Spinner/></div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlParams = scriptParams === false ? {
|
const urlParams = {
|
||||||
clientId: 'test',
|
clientId: 'test',
|
||||||
components: 'messages',
|
|
||||||
} : {
|
|
||||||
...scriptParams.url_params,
|
...scriptParams.url_params,
|
||||||
...{
|
...{
|
||||||
components: 'messages',
|
components: 'messages',
|
||||||
|
dataNamespace: 'ppcp-block-editor-paylater-message',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue