mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Fix lint
Add throttling to simulate_cart ajax call
This commit is contained in:
parent
a0480e35bb
commit
84a362a7c5
13 changed files with 203 additions and 114 deletions
|
@ -1,3 +1,6 @@
|
|||
import {loadScript} from "@paypal/paypal-js";
|
||||
import widgetBuilder from "./Renderer/WidgetBuilder";
|
||||
|
||||
const storageKey = 'ppcp-data-client-id';
|
||||
|
||||
const validateToken = (token, user) => {
|
||||
|
@ -24,7 +27,7 @@ const storeToken = (token) => {
|
|||
sessionStorage.setItem(storageKey, JSON.stringify(token));
|
||||
}
|
||||
|
||||
const dataClientIdAttributeHandler = (script, config) => {
|
||||
const dataClientIdAttributeHandler = (scriptOptions, config, callback) => {
|
||||
fetch(config.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -42,8 +45,14 @@ const dataClientIdAttributeHandler = (script, config) => {
|
|||
return;
|
||||
}
|
||||
storeToken(data);
|
||||
script.setAttribute('data-client-token', data.token);
|
||||
document.body.appendChild(script);
|
||||
|
||||
scriptOptions['data-client-token'] = data.token;
|
||||
|
||||
loadScript(scriptOptions).then((paypal) => {
|
||||
if (typeof callback === 'function') {
|
||||
callback(paypal);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue