2020-04-08 18:50:29 +03:00
|
|
|
import MiniCartBootstap from './modules/MiniCartBootstap';
|
|
|
|
import SingleProductBootstap from './modules/SingleProductBootstap';
|
|
|
|
import CartBootstrap from './modules/CartBootstap';
|
|
|
|
import CheckoutBootstap from './modules/CheckoutBootstap';
|
2020-04-09 12:23:44 +03:00
|
|
|
import Renderer from './modules/Renderer';
|
2020-04-02 08:38:00 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
const bootstrap = () => {
|
2020-04-10 10:34:49 +03:00
|
|
|
const renderer = new Renderer(PayPalCommerceGateway);
|
2020-04-09 12:56:05 +03:00
|
|
|
const context = PayPalCommerceGateway.context;
|
2020-04-08 13:33:12 +03:00
|
|
|
|
2020-04-09 14:55:04 +03:00
|
|
|
if (context === 'mini-cart' || context === 'product') {
|
2020-04-10 10:34:49 +03:00
|
|
|
const miniCartBootstrap = new MiniCartBootstap(
|
2020-04-09 12:56:05 +03:00
|
|
|
PayPalCommerceGateway,
|
2020-04-10 10:34:49 +03:00
|
|
|
renderer
|
2020-04-09 12:56:05 +03:00
|
|
|
);
|
2020-04-08 15:43:31 +03:00
|
|
|
|
2020-04-10 10:34:49 +03:00
|
|
|
miniCartBootstrap.init();
|
2020-04-08 13:33:12 +03:00
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2020-04-08 13:33:12 +03:00
|
|
|
if (context === 'product') {
|
2020-04-10 10:34:49 +03:00
|
|
|
const singleProductBootstrap = new SingleProductBootstap(
|
2020-04-09 12:56:05 +03:00
|
|
|
PayPalCommerceGateway,
|
|
|
|
renderer,
|
|
|
|
);
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2020-04-10 10:34:49 +03:00
|
|
|
singleProductBootstrap.init();
|
2020-04-08 13:33:12 +03:00
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2020-04-08 13:33:12 +03:00
|
|
|
if (context === 'cart') {
|
2020-04-09 12:56:05 +03:00
|
|
|
const cartBootstrap = new CartBootstrap(
|
|
|
|
PayPalCommerceGateway,
|
|
|
|
renderer,
|
|
|
|
);
|
2020-04-08 12:33:34 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
cartBootstrap.init();
|
2020-04-08 13:33:12 +03:00
|
|
|
}
|
2020-04-08 12:33:34 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
if (context === 'checkout') {
|
2020-04-09 12:56:05 +03:00
|
|
|
const checkoutBootstap = new CheckoutBootstap(
|
|
|
|
PayPalCommerceGateway,
|
2020-04-10 10:34:49 +03:00
|
|
|
renderer
|
2020-04-09 12:56:05 +03:00
|
|
|
);
|
2020-04-08 18:50:29 +03:00
|
|
|
|
|
|
|
checkoutBootstap.init();
|
|
|
|
}
|
|
|
|
};
|
2020-04-08 13:33:12 +03:00
|
|
|
document.addEventListener(
|
|
|
|
'DOMContentLoaded',
|
|
|
|
() => {
|
2020-04-08 18:50:29 +03:00
|
|
|
if (!typeof (PayPalCommerceGateway)) {
|
2020-04-08 13:33:12 +03:00
|
|
|
console.error('PayPal button could not be configured.');
|
2020-04-02 08:38:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-04-08 12:33:34 +03:00
|
|
|
|
2020-04-08 13:33:12 +03:00
|
|
|
const script = document.createElement('script');
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2020-04-08 13:33:12 +03:00
|
|
|
script.setAttribute('src', PayPalCommerceGateway.button.url);
|
|
|
|
script.addEventListener('load', (event) => {
|
|
|
|
bootstrap();
|
2020-04-08 18:50:29 +03:00
|
|
|
});
|
2020-04-08 13:33:12 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
document.body.append(script);
|
|
|
|
},
|
2020-04-02 08:38:00 +03:00
|
|
|
);
|