/** * WidgetRenderer Renders the Sezzle widget */ class WidgetRenderer { /** * WidgetRenderer constructor * @param {JSON|null} options */ constructor(options) { this.shop = options.shop; this.merchantUUID = options.merchantUUID; this.blockType = options.blockType; } /** * @description Initializes the widget rendering process */ init() { this.attachScript(); } /** * @description Creates a script tag and attaches it to document head which gets sezzle-js * and theme config from widget-server via shopify proxy. */ attachScript() { if (this.merchantUUID.length <= 0) { return; } const theme_store_id = Shopify.theme.theme_store_id const theme_name = Shopify.theme.name const script = document.createElement('script'); script.type = 'text/javascript'; script.src = `${this.shop}/apps/sezzle/v1/javascript/price-widget?uuid=${this.merchantUUID}&theme_store_id=${theme_store_id}&theme_name=${theme_name}&block_type=${this.blockType}`; document.head.appendChild(script); } }