2020-04-30 15:28:48 +03:00
|
|
|
import MiniCartBootstap from './modules/ContextBootstrap/MiniCartBootstap';
|
|
|
|
import SingleProductBootstap from './modules/ContextBootstrap/SingleProductBootstap';
|
|
|
|
import CartBootstrap from './modules/ContextBootstrap/CartBootstap';
|
|
|
|
import CheckoutBootstap from './modules/ContextBootstrap/CheckoutBootstap';
|
2020-09-30 14:24:31 +03:00
|
|
|
import PayNowBootstrap from "./modules/ContextBootstrap/PayNowBootstrap";
|
2020-04-30 15:28:48 +03:00
|
|
|
import Renderer from './modules/Renderer/Renderer';
|
2020-07-22 14:12:49 +03:00
|
|
|
import ErrorHandler from './modules/ErrorHandler';
|
2020-04-30 15:28:48 +03:00
|
|
|
import CreditCardRenderer from "./modules/Renderer/CreditCardRenderer";
|
2020-08-13 14:20:47 +03:00
|
|
|
import dataClientIdAttributeHandler from "./modules/DataClientIdAttributeHandler";
|
2020-08-19 10:27:53 +03:00
|
|
|
import MessageRenderer from "./modules/Renderer/MessageRenderer";
|
2020-09-28 14:05:02 +03:00
|
|
|
import Spinner from "./modules/Helper/Spinner";
|
2020-04-02 08:38:00 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
const bootstrap = () => {
|
2020-07-28 08:05:18 +03:00
|
|
|
const errorHandler = new ErrorHandler(PayPalCommerceGateway.labels.error.generic);
|
2020-09-28 14:05:02 +03:00
|
|
|
const spinner = new Spinner();
|
|
|
|
const creditCardRenderer = new CreditCardRenderer(PayPalCommerceGateway, errorHandler, spinner);
|
2020-04-30 15:28:48 +03:00
|
|
|
const renderer = new Renderer(creditCardRenderer, PayPalCommerceGateway);
|
2020-08-19 10:27:53 +03:00
|
|
|
const messageRenderer = new MessageRenderer(PayPalCommerceGateway.messages);
|
2020-04-09 12:56:05 +03:00
|
|
|
const context = PayPalCommerceGateway.context;
|
2020-04-09 14:55:04 +03:00
|
|
|
if (context === 'mini-cart' || context === 'product') {
|
2021-07-13 09:43:30 +02:00
|
|
|
if (PayPalCommerceGateway.mini_cart_buttons_enabled === '1') {
|
2021-07-12 17:16:26 +02:00
|
|
|
const miniCartBootstrap = new MiniCartBootstap(
|
|
|
|
PayPalCommerceGateway,
|
|
|
|
renderer
|
|
|
|
);
|
2020-04-08 15:43:31 +03:00
|
|
|
|
2021-07-12 17:16:26 +02:00
|
|
|
miniCartBootstrap.init();
|
|
|
|
}
|
2020-04-08 13:33:12 +03:00
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2021-07-12 17:16:26 +02:00
|
|
|
if (context === 'product' && PayPalCommerceGateway.single_product_buttons_enabled === '1') {
|
2020-04-10 10:34:49 +03:00
|
|
|
const singleProductBootstrap = new SingleProductBootstap(
|
2020-04-09 12:56:05 +03:00
|
|
|
PayPalCommerceGateway,
|
|
|
|
renderer,
|
2020-08-19 13:40:29 +03:00
|
|
|
messageRenderer,
|
2020-04-09 12:56:05 +03:00
|
|
|
);
|
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-08-19 10:27:53 +03:00
|
|
|
renderer,
|
2020-09-28 14:05:02 +03:00
|
|
|
messageRenderer,
|
|
|
|
spinner
|
2020-04-09 12:56:05 +03:00
|
|
|
);
|
2020-04-08 18:50:29 +03:00
|
|
|
|
|
|
|
checkoutBootstap.init();
|
|
|
|
}
|
2020-08-19 10:27:53 +03:00
|
|
|
|
2020-09-30 14:24:31 +03:00
|
|
|
if (context === 'pay-now' ) {
|
|
|
|
const payNowBootstrap = new PayNowBootstrap(
|
|
|
|
PayPalCommerceGateway,
|
|
|
|
renderer,
|
2021-01-05 17:12:26 +01:00
|
|
|
messageRenderer,
|
|
|
|
spinner
|
2020-09-30 14:24:31 +03:00
|
|
|
);
|
|
|
|
payNowBootstrap.init();
|
|
|
|
}
|
|
|
|
|
2020-08-19 11:50:02 +03:00
|
|
|
if (context !== 'checkout') {
|
|
|
|
messageRenderer.render();
|
|
|
|
}
|
2020-04-08 18:50:29 +03:00
|
|
|
};
|
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 13:33:12 +03:00
|
|
|
const script = document.createElement('script');
|
2020-04-08 18:50:29 +03:00
|
|
|
|
2020-08-13 14:20:47 +03:00
|
|
|
script.addEventListener('load', (event) => {
|
|
|
|
bootstrap();
|
|
|
|
});
|
2020-04-08 13:33:12 +03:00
|
|
|
script.setAttribute('src', PayPalCommerceGateway.button.url);
|
2020-04-30 15:28:48 +03:00
|
|
|
Object.entries(PayPalCommerceGateway.script_attributes).forEach(
|
|
|
|
(keyValue) => {
|
|
|
|
script.setAttribute(keyValue[0], keyValue[1]);
|
|
|
|
}
|
|
|
|
);
|
2020-08-13 14:20:47 +03:00
|
|
|
|
2021-04-23 10:33:28 +02:00
|
|
|
if (PayPalCommerceGateway.data_client_id.set_attribute) {
|
2020-08-13 14:20:47 +03:00
|
|
|
dataClientIdAttributeHandler(script, PayPalCommerceGateway.data_client_id);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-08 13:33:12 +03:00
|
|
|
|
2020-04-08 18:50:29 +03:00
|
|
|
document.body.append(script);
|
|
|
|
},
|
2021-01-05 17:12:26 +01:00
|
|
|
);
|