mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
init
This commit is contained in:
parent
ba97d7143d
commit
779eb31e4e
53 changed files with 8475 additions and 0 deletions
39
modules.local/ppcp-button/resources/js/modules/Renderer.js
Normal file
39
modules.local/ppcp-button/resources/js/modules/Renderer.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
class Renderer {
|
||||
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
render(buttonConfig) {
|
||||
|
||||
const script = document.createElement('script');
|
||||
|
||||
if (typeof paypal !== 'object') {
|
||||
script.setAttribute('src', this.config.url);
|
||||
script.addEventListener('load', (event) => {
|
||||
this.renderButtons(buttonConfig);
|
||||
})
|
||||
document.body.append(script);
|
||||
return;
|
||||
}
|
||||
|
||||
this.renderButtons(buttonConfig);
|
||||
}
|
||||
|
||||
renderButtons(buttonConfig) {
|
||||
|
||||
paypal.Buttons(
|
||||
buttonConfig
|
||||
).render(this.config.wrapper);
|
||||
}
|
||||
|
||||
hideButtons() {
|
||||
document.querySelector(this.config.wrapper).style.display = 'none';
|
||||
}
|
||||
|
||||
showButtons() {
|
||||
document.querySelector(this.config.wrapper).style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
export default Renderer;
|
Loading…
Add table
Add a link
Reference in a new issue