UNPKG

@tamara-solution/checkout

Version:

Script will be embedded in merchant's site to checkout. The merchant's don't need to redirect to tamara's site.

47 lines (35 loc) 954 B
import { FrameError } from '@/helpers/frame-error' import { isValidPlatform } from '@/helpers/platform' function createElement(tag) { if (isValidPlatform()) { return document.createElement(tag) } } function appendHTML(parentId, element) { if (!isValidPlatform()) { return } // Default: support append to body if (parentId === 'body') { if (document.body === null) { throw new FrameError( 'The script loaded incorrectly. Please check the documentation and try again!' ) } document.body.appendChild(element) return } // TODO: support append inside an element const parentElement = document.getElementById(parentId) parentElement.appendChild(element) } function removeElement(id) { if (!isValidPlatform()) { return } const frameElement = document.getElementById(id) if (frameElement) { frameElement.remove() } } export { appendHTML, createElement, removeElement }