2020-04-02 08:38:00 +03:00
|
|
|
class Renderer {
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
constructor(config)
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
this.config = config;
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
render(buttonConfig)
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
renderButtons(buttonConfig)
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
|
|
|
|
paypal.Buttons(
|
|
|
|
buttonConfig
|
|
|
|
).render(this.config.wrapper);
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
hideButtons()
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
document.querySelector(this.config.wrapper).style.display = 'none';
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:16:18 +03:00
|
|
|
showButtons()
|
|
|
|
{
|
2020-04-02 08:38:00 +03:00
|
|
|
document.querySelector(this.config.wrapper).style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Renderer;
|