@dintero/checkout-web-sdk
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -9,3 +9,3 @@ 'use strict'; | ||
name: "@dintero/checkout-web-sdk", | ||
version: "0.5.0", | ||
version: "0.5.1", | ||
description: "Dintero Checkout SDK for web frontends", | ||
@@ -50,3 +50,3 @@ main: "dist/dintero-checkout-web-sdk.cjs.js", | ||
prettier: "^2.6.2", | ||
puppeteer: "^18.0.5", | ||
puppeteer: "^19.0.0", | ||
"semantic-release": "^19.0.2", | ||
@@ -62,3 +62,2 @@ sinon: "^14.0.0", | ||
let CheckoutEvents; | ||
(function (CheckoutEvents) { | ||
@@ -77,5 +76,3 @@ CheckoutEvents["SessionNotFound"] = "SessionNotFound"; | ||
})(CheckoutEvents || (CheckoutEvents = {})); | ||
let InternalCheckoutEvents; | ||
(function (InternalCheckoutEvents) { | ||
@@ -90,6 +87,6 @@ InternalCheckoutEvents["HeightChanged"] = "HeightChanged"; | ||
*/ | ||
const windowLocationAssign = url => { | ||
window.location.assign(url); | ||
}; | ||
/** | ||
@@ -108,8 +105,7 @@ * Get the url for the session./yarn-error.log | ||
} = options; | ||
if (!endpoint) { | ||
throw new Error("Invalid endpoint"); | ||
} // Compose url for view session endpoint with optional language parameter. | ||
} | ||
// Compose url for view session endpoint with optional language parameter. | ||
let languageParam = language ? `language=${language}` : ""; | ||
@@ -133,8 +129,10 @@ let uiParam = ui ? `ui=${ui}` : ""; | ||
} | ||
const iframe = document.createElement("iframe"); | ||
const iframe = document.createElement("iframe"); // No border, transparent and stretch to 100% of the container width. | ||
// No border, transparent and stretch to 100% of the container width. | ||
iframe.setAttribute("frameborder", "0"); | ||
iframe.setAttribute("allowTransparency", "true"); | ||
iframe.setAttribute("style", "width:100%; height:0;"); // TODO: Get this to work as expected, might be tricky with current | ||
iframe.setAttribute("style", "width:100%; height:0;"); | ||
// TODO: Get this to work as expected, might be tricky with current | ||
// tests since they will require the csp to be "unsafe-inline". | ||
@@ -147,13 +145,17 @@ // The server needs to add the same property in the Content Security | ||
// iframe.setAttribute("csp", `default-src ${endpoint}`); | ||
// Apply extra restrictions to the content in the iframe. | ||
// allow popups is needed to open terms in new window | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); // The download priority of the resource in the <iframe>'s src attribute. | ||
// The download priority of the resource in the <iframe>'s src attribute. | ||
iframe.setAttribute("importance", "high"); | ||
iframe.setAttribute("importance", "high"); // Set the iframe source to the url. | ||
// Set the iframe source to the url. | ||
iframe.setAttribute("src", url); | ||
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads. | ||
// Resolve or reject promise when iframe loads. | ||
// // Add iframe to the container. | ||
// container.appendChild(iframe); | ||
return { | ||
@@ -164,5 +166,3 @@ iframe, | ||
iframe.onload = () => resolve(); | ||
iframe.onerror = () => reject(); | ||
container.appendChild(iframe); | ||
@@ -188,7 +188,6 @@ }); | ||
}; | ||
/** | ||
* Post a SessionLock-event to the checkout iframe. | ||
*/ | ||
const postSessionLock = (iframe, sid) => { | ||
@@ -202,6 +201,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post the validation result to the checkout iframe | ||
*/ | ||
const postValidationResult = (iframe, sid, result) => { | ||
@@ -216,6 +215,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post RefreshSession-event to the checkout iframe. | ||
*/ | ||
const postSessionRefresh = (iframe, sid) => { | ||
@@ -229,6 +228,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post setActivePaymentProductType-event to the checkout iframe. | ||
*/ | ||
const postActivePaymentProductType = (iframe, sid, paymentProductType) => { | ||
@@ -243,2 +242,3 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
@@ -248,3 +248,2 @@ * Subscribe to events from an iframe given a handler and a set | ||
*/ | ||
const subscribe = options => { | ||
@@ -257,5 +256,6 @@ const { | ||
checkout | ||
} = options; // Wrap event handler in a function that checks for correct origin and | ||
} = options; | ||
// Wrap event handler in a function that checks for correct origin and | ||
// filters on event type(s) in the event data. | ||
const wrappedHandler = event => { | ||
@@ -266,3 +266,2 @@ const correctOrigin = event.origin === endpoint; | ||
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1; | ||
if (correctOrigin && correctWindow && correctSid && correctMessageType) { | ||
@@ -272,12 +271,13 @@ postAck(checkout.iframe, event); | ||
} | ||
}; // Add event listener to the iframe. | ||
}; | ||
// Add event listener to the iframe. | ||
window.addEventListener("message", wrappedHandler, false); | ||
window.addEventListener("message", wrappedHandler, false); // Function to remove the event listener from the iframe. | ||
// Function to remove the event listener from the iframe. | ||
const unsubscribe = () => { | ||
window.removeEventListener("message", wrappedHandler, false); | ||
}; // Return object with unsubscribe function. | ||
}; | ||
// Return object with unsubscribe function. | ||
return { | ||
@@ -296,7 +296,6 @@ unsubscribe | ||
}; | ||
/** | ||
* An event handler that sets height of the iframe. | ||
*/ | ||
const setIframeHeight = (event, checkout) => { | ||
@@ -307,2 +306,3 @@ if (event.height || event.height === 0) { | ||
}; | ||
/** | ||
@@ -312,4 +312,2 @@ * An event handler that scrolls to the top of the iframe. This is useful when the user | ||
*/ | ||
const scrollToIframeTop = (event, checkout) => { | ||
@@ -326,7 +324,6 @@ try { | ||
}; | ||
/** | ||
* An event handler that sets language in the iframe. | ||
*/ | ||
const setLanguage = (event, checkout) => { | ||
@@ -337,3 +334,2 @@ if (event.language) { | ||
}; | ||
const handleWithResult = (sid, endpoint, handler) => { | ||
@@ -343,7 +339,5 @@ return (event, checkout) => { | ||
const pairs = eventKeys.map(key => [key, event[key]]); | ||
if (event.type === CheckoutEvents.SessionCancel && !event.error) { | ||
pairs.push(["error", "cancelled"]); | ||
} | ||
pairs.push(["language", checkout.language]); | ||
@@ -356,7 +350,6 @@ pairs.push(["sdk", pkg.version]); | ||
}; | ||
/** | ||
* Show a dintero payment session in an embedded iframe. | ||
*/ | ||
const embed = async options => { | ||
@@ -380,4 +373,5 @@ const { | ||
let checkout; | ||
const subscriptions = []; // Create iframe | ||
const subscriptions = []; | ||
// Create iframe | ||
const { | ||
@@ -393,10 +387,9 @@ iframe, | ||
})); | ||
/** | ||
* Function that removes the iframe and all event listeners. | ||
*/ | ||
const destroy = () => { | ||
if (iframe) { | ||
subscriptions.forEach(sub => sub.unsubscribe()); | ||
if (iframe.parentElement) { | ||
@@ -407,2 +400,3 @@ container.removeChild(iframe); | ||
}; | ||
/** | ||
@@ -412,4 +406,2 @@ * Turn an action into a promise by specifying resolve and | ||
*/ | ||
const promisifyAction = (action, resolveEvent, rejectEvent) => { | ||
@@ -419,3 +411,2 @@ if (!checkout) { | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -446,3 +437,2 @@ const eventSubscriptions = []; | ||
}; | ||
const lockSession = () => { | ||
@@ -453,3 +443,2 @@ return promisifyAction(() => { | ||
}; | ||
const refreshSession = () => { | ||
@@ -460,11 +449,8 @@ return promisifyAction(() => { | ||
}; | ||
const setActivePaymentProductType = paymentProductType => { | ||
postActivePaymentProductType(iframe, sid, paymentProductType); | ||
}; | ||
const submitValidationResult = result => { | ||
postValidationResult(iframe, sid, result); | ||
}; | ||
const wrappedOnValidateSession = (event, checkout) => { | ||
@@ -475,3 +461,2 @@ if (onValidateSession) { | ||
}; | ||
const wrappedOnSessionLocked = (event, checkout) => { | ||
@@ -481,5 +466,5 @@ if (onSessionLocked) { | ||
} | ||
}; // Create checkout object that wraps the destroy function. | ||
}; | ||
// Create checkout object that wraps the destroy function. | ||
checkout = { | ||
@@ -493,4 +478,5 @@ destroy, | ||
submitValidationResult | ||
}; // Add event handlers (or in some cases add a fallback href handler). | ||
}; | ||
// Add event handlers (or in some cases add a fallback href handler). | ||
[{ | ||
@@ -551,12 +537,13 @@ handler: setLanguage, | ||
} | ||
}); // Add iframe to DOM | ||
}); | ||
await initiate(); // Return object with function to destroy the checkout. | ||
// Add iframe to DOM | ||
await initiate(); | ||
// Return object with function to destroy the checkout. | ||
return checkout; | ||
}; | ||
/** | ||
* Redirect the customer to a payment session in the Dintero Checkout. | ||
*/ | ||
const redirect = options => { | ||
@@ -567,4 +554,4 @@ const { | ||
endpoint = "https://checkout.dintero.com" | ||
} = options; // Redirect the current browser window to the checkout session url. | ||
} = options; | ||
// Redirect the current browser window to the checkout session url. | ||
windowLocationAssign(getSessionUrl({ | ||
@@ -571,0 +558,0 @@ sid, |
@@ -9,3 +9,3 @@ 'use strict'; | ||
name: "@dintero/checkout-web-sdk", | ||
version: "0.5.0", | ||
version: "0.5.1", | ||
description: "Dintero Checkout SDK for web frontends", | ||
@@ -50,3 +50,3 @@ main: "dist/dintero-checkout-web-sdk.cjs.js", | ||
prettier: "^2.6.2", | ||
puppeteer: "^18.0.5", | ||
puppeteer: "^19.0.0", | ||
"semantic-release": "^19.0.2", | ||
@@ -62,3 +62,2 @@ sinon: "^14.0.0", | ||
let CheckoutEvents; | ||
(function (CheckoutEvents) { | ||
@@ -77,5 +76,3 @@ CheckoutEvents["SessionNotFound"] = "SessionNotFound"; | ||
})(CheckoutEvents || (CheckoutEvents = {})); | ||
let InternalCheckoutEvents; | ||
(function (InternalCheckoutEvents) { | ||
@@ -90,6 +87,6 @@ InternalCheckoutEvents["HeightChanged"] = "HeightChanged"; | ||
*/ | ||
const windowLocationAssign = url => { | ||
window.location.assign(url); | ||
}; | ||
/** | ||
@@ -108,8 +105,7 @@ * Get the url for the session./yarn-error.log | ||
} = options; | ||
if (!endpoint) { | ||
throw new Error("Invalid endpoint"); | ||
} // Compose url for view session endpoint with optional language parameter. | ||
} | ||
// Compose url for view session endpoint with optional language parameter. | ||
let languageParam = language ? `language=${language}` : ""; | ||
@@ -133,8 +129,10 @@ let uiParam = ui ? `ui=${ui}` : ""; | ||
} | ||
const iframe = document.createElement("iframe"); | ||
const iframe = document.createElement("iframe"); // No border, transparent and stretch to 100% of the container width. | ||
// No border, transparent and stretch to 100% of the container width. | ||
iframe.setAttribute("frameborder", "0"); | ||
iframe.setAttribute("allowTransparency", "true"); | ||
iframe.setAttribute("style", "width:100%; height:0;"); // TODO: Get this to work as expected, might be tricky with current | ||
iframe.setAttribute("style", "width:100%; height:0;"); | ||
// TODO: Get this to work as expected, might be tricky with current | ||
// tests since they will require the csp to be "unsafe-inline". | ||
@@ -147,13 +145,17 @@ // The server needs to add the same property in the Content Security | ||
// iframe.setAttribute("csp", `default-src ${endpoint}`); | ||
// Apply extra restrictions to the content in the iframe. | ||
// allow popups is needed to open terms in new window | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); // The download priority of the resource in the <iframe>'s src attribute. | ||
// The download priority of the resource in the <iframe>'s src attribute. | ||
iframe.setAttribute("importance", "high"); | ||
iframe.setAttribute("importance", "high"); // Set the iframe source to the url. | ||
// Set the iframe source to the url. | ||
iframe.setAttribute("src", url); | ||
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads. | ||
// Resolve or reject promise when iframe loads. | ||
// // Add iframe to the container. | ||
// container.appendChild(iframe); | ||
return { | ||
@@ -164,5 +166,3 @@ iframe, | ||
iframe.onload = () => resolve(); | ||
iframe.onerror = () => reject(); | ||
container.appendChild(iframe); | ||
@@ -188,7 +188,6 @@ }); | ||
}; | ||
/** | ||
* Post a SessionLock-event to the checkout iframe. | ||
*/ | ||
const postSessionLock = (iframe, sid) => { | ||
@@ -202,6 +201,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post the validation result to the checkout iframe | ||
*/ | ||
const postValidationResult = (iframe, sid, result) => { | ||
@@ -216,6 +215,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post RefreshSession-event to the checkout iframe. | ||
*/ | ||
const postSessionRefresh = (iframe, sid) => { | ||
@@ -229,6 +228,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post setActivePaymentProductType-event to the checkout iframe. | ||
*/ | ||
const postActivePaymentProductType = (iframe, sid, paymentProductType) => { | ||
@@ -243,2 +242,3 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
@@ -248,3 +248,2 @@ * Subscribe to events from an iframe given a handler and a set | ||
*/ | ||
const subscribe = options => { | ||
@@ -257,5 +256,6 @@ const { | ||
checkout | ||
} = options; // Wrap event handler in a function that checks for correct origin and | ||
} = options; | ||
// Wrap event handler in a function that checks for correct origin and | ||
// filters on event type(s) in the event data. | ||
const wrappedHandler = event => { | ||
@@ -266,3 +266,2 @@ const correctOrigin = event.origin === endpoint; | ||
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1; | ||
if (correctOrigin && correctWindow && correctSid && correctMessageType) { | ||
@@ -272,12 +271,13 @@ postAck(checkout.iframe, event); | ||
} | ||
}; // Add event listener to the iframe. | ||
}; | ||
// Add event listener to the iframe. | ||
window.addEventListener("message", wrappedHandler, false); | ||
window.addEventListener("message", wrappedHandler, false); // Function to remove the event listener from the iframe. | ||
// Function to remove the event listener from the iframe. | ||
const unsubscribe = () => { | ||
window.removeEventListener("message", wrappedHandler, false); | ||
}; // Return object with unsubscribe function. | ||
}; | ||
// Return object with unsubscribe function. | ||
return { | ||
@@ -296,7 +296,6 @@ unsubscribe | ||
}; | ||
/** | ||
* An event handler that sets height of the iframe. | ||
*/ | ||
const setIframeHeight = (event, checkout) => { | ||
@@ -307,2 +306,3 @@ if (event.height || event.height === 0) { | ||
}; | ||
/** | ||
@@ -312,4 +312,2 @@ * An event handler that scrolls to the top of the iframe. This is useful when the user | ||
*/ | ||
const scrollToIframeTop = (event, checkout) => { | ||
@@ -326,7 +324,6 @@ try { | ||
}; | ||
/** | ||
* An event handler that sets language in the iframe. | ||
*/ | ||
const setLanguage = (event, checkout) => { | ||
@@ -337,3 +334,2 @@ if (event.language) { | ||
}; | ||
const handleWithResult = (sid, endpoint, handler) => { | ||
@@ -343,7 +339,5 @@ return (event, checkout) => { | ||
const pairs = eventKeys.map(key => [key, event[key]]); | ||
if (event.type === CheckoutEvents.SessionCancel && !event.error) { | ||
pairs.push(["error", "cancelled"]); | ||
} | ||
pairs.push(["language", checkout.language]); | ||
@@ -356,7 +350,6 @@ pairs.push(["sdk", pkg.version]); | ||
}; | ||
/** | ||
* Show a dintero payment session in an embedded iframe. | ||
*/ | ||
const embed = async options => { | ||
@@ -380,4 +373,5 @@ const { | ||
let checkout; | ||
const subscriptions = []; // Create iframe | ||
const subscriptions = []; | ||
// Create iframe | ||
const { | ||
@@ -393,10 +387,9 @@ iframe, | ||
})); | ||
/** | ||
* Function that removes the iframe and all event listeners. | ||
*/ | ||
const destroy = () => { | ||
if (iframe) { | ||
subscriptions.forEach(sub => sub.unsubscribe()); | ||
if (iframe.parentElement) { | ||
@@ -407,2 +400,3 @@ container.removeChild(iframe); | ||
}; | ||
/** | ||
@@ -412,4 +406,2 @@ * Turn an action into a promise by specifying resolve and | ||
*/ | ||
const promisifyAction = (action, resolveEvent, rejectEvent) => { | ||
@@ -419,3 +411,2 @@ if (!checkout) { | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -446,3 +437,2 @@ const eventSubscriptions = []; | ||
}; | ||
const lockSession = () => { | ||
@@ -453,3 +443,2 @@ return promisifyAction(() => { | ||
}; | ||
const refreshSession = () => { | ||
@@ -460,11 +449,8 @@ return promisifyAction(() => { | ||
}; | ||
const setActivePaymentProductType = paymentProductType => { | ||
postActivePaymentProductType(iframe, sid, paymentProductType); | ||
}; | ||
const submitValidationResult = result => { | ||
postValidationResult(iframe, sid, result); | ||
}; | ||
const wrappedOnValidateSession = (event, checkout) => { | ||
@@ -475,3 +461,2 @@ if (onValidateSession) { | ||
}; | ||
const wrappedOnSessionLocked = (event, checkout) => { | ||
@@ -481,5 +466,5 @@ if (onSessionLocked) { | ||
} | ||
}; // Create checkout object that wraps the destroy function. | ||
}; | ||
// Create checkout object that wraps the destroy function. | ||
checkout = { | ||
@@ -493,4 +478,5 @@ destroy, | ||
submitValidationResult | ||
}; // Add event handlers (or in some cases add a fallback href handler). | ||
}; | ||
// Add event handlers (or in some cases add a fallback href handler). | ||
[{ | ||
@@ -551,12 +537,13 @@ handler: setLanguage, | ||
} | ||
}); // Add iframe to DOM | ||
}); | ||
await initiate(); // Return object with function to destroy the checkout. | ||
// Add iframe to DOM | ||
await initiate(); | ||
// Return object with function to destroy the checkout. | ||
return checkout; | ||
}; | ||
/** | ||
* Redirect the customer to a payment session in the Dintero Checkout. | ||
*/ | ||
const redirect = options => { | ||
@@ -567,4 +554,4 @@ const { | ||
endpoint = "https://checkout.dintero.com" | ||
} = options; // Redirect the current browser window to the checkout session url. | ||
} = options; | ||
// Redirect the current browser window to the checkout session url. | ||
windowLocationAssign(getSessionUrl({ | ||
@@ -571,0 +558,0 @@ sid, |
@@ -5,3 +5,3 @@ import 'native-promise-only'; | ||
name: "@dintero/checkout-web-sdk", | ||
version: "0.5.0", | ||
version: "0.5.1", | ||
description: "Dintero Checkout SDK for web frontends", | ||
@@ -46,3 +46,3 @@ main: "dist/dintero-checkout-web-sdk.cjs.js", | ||
prettier: "^2.6.2", | ||
puppeteer: "^18.0.5", | ||
puppeteer: "^19.0.0", | ||
"semantic-release": "^19.0.2", | ||
@@ -58,3 +58,2 @@ sinon: "^14.0.0", | ||
let CheckoutEvents; | ||
(function (CheckoutEvents) { | ||
@@ -73,5 +72,3 @@ CheckoutEvents["SessionNotFound"] = "SessionNotFound"; | ||
})(CheckoutEvents || (CheckoutEvents = {})); | ||
let InternalCheckoutEvents; | ||
(function (InternalCheckoutEvents) { | ||
@@ -86,6 +83,6 @@ InternalCheckoutEvents["HeightChanged"] = "HeightChanged"; | ||
*/ | ||
const windowLocationAssign = url => { | ||
window.location.assign(url); | ||
}; | ||
/** | ||
@@ -104,8 +101,7 @@ * Get the url for the session./yarn-error.log | ||
} = options; | ||
if (!endpoint) { | ||
throw new Error("Invalid endpoint"); | ||
} // Compose url for view session endpoint with optional language parameter. | ||
} | ||
// Compose url for view session endpoint with optional language parameter. | ||
let languageParam = language ? `language=${language}` : ""; | ||
@@ -129,8 +125,10 @@ let uiParam = ui ? `ui=${ui}` : ""; | ||
} | ||
const iframe = document.createElement("iframe"); | ||
const iframe = document.createElement("iframe"); // No border, transparent and stretch to 100% of the container width. | ||
// No border, transparent and stretch to 100% of the container width. | ||
iframe.setAttribute("frameborder", "0"); | ||
iframe.setAttribute("allowTransparency", "true"); | ||
iframe.setAttribute("style", "width:100%; height:0;"); // TODO: Get this to work as expected, might be tricky with current | ||
iframe.setAttribute("style", "width:100%; height:0;"); | ||
// TODO: Get this to work as expected, might be tricky with current | ||
// tests since they will require the csp to be "unsafe-inline". | ||
@@ -143,13 +141,17 @@ // The server needs to add the same property in the Content Security | ||
// iframe.setAttribute("csp", `default-src ${endpoint}`); | ||
// Apply extra restrictions to the content in the iframe. | ||
// allow popups is needed to open terms in new window | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); | ||
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"); // The download priority of the resource in the <iframe>'s src attribute. | ||
// The download priority of the resource in the <iframe>'s src attribute. | ||
iframe.setAttribute("importance", "high"); | ||
iframe.setAttribute("importance", "high"); // Set the iframe source to the url. | ||
// Set the iframe source to the url. | ||
iframe.setAttribute("src", url); | ||
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads. | ||
// Resolve or reject promise when iframe loads. | ||
// // Add iframe to the container. | ||
// container.appendChild(iframe); | ||
return { | ||
@@ -160,5 +162,3 @@ iframe, | ||
iframe.onload = () => resolve(); | ||
iframe.onerror = () => reject(); | ||
container.appendChild(iframe); | ||
@@ -184,7 +184,6 @@ }); | ||
}; | ||
/** | ||
* Post a SessionLock-event to the checkout iframe. | ||
*/ | ||
const postSessionLock = (iframe, sid) => { | ||
@@ -198,6 +197,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post the validation result to the checkout iframe | ||
*/ | ||
const postValidationResult = (iframe, sid, result) => { | ||
@@ -212,6 +211,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post RefreshSession-event to the checkout iframe. | ||
*/ | ||
const postSessionRefresh = (iframe, sid) => { | ||
@@ -225,6 +224,6 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
* Post setActivePaymentProductType-event to the checkout iframe. | ||
*/ | ||
const postActivePaymentProductType = (iframe, sid, paymentProductType) => { | ||
@@ -239,2 +238,3 @@ if (iframe.contentWindow) { | ||
}; | ||
/** | ||
@@ -244,3 +244,2 @@ * Subscribe to events from an iframe given a handler and a set | ||
*/ | ||
const subscribe = options => { | ||
@@ -253,5 +252,6 @@ const { | ||
checkout | ||
} = options; // Wrap event handler in a function that checks for correct origin and | ||
} = options; | ||
// Wrap event handler in a function that checks for correct origin and | ||
// filters on event type(s) in the event data. | ||
const wrappedHandler = event => { | ||
@@ -262,3 +262,2 @@ const correctOrigin = event.origin === endpoint; | ||
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1; | ||
if (correctOrigin && correctWindow && correctSid && correctMessageType) { | ||
@@ -268,12 +267,13 @@ postAck(checkout.iframe, event); | ||
} | ||
}; // Add event listener to the iframe. | ||
}; | ||
// Add event listener to the iframe. | ||
window.addEventListener("message", wrappedHandler, false); | ||
window.addEventListener("message", wrappedHandler, false); // Function to remove the event listener from the iframe. | ||
// Function to remove the event listener from the iframe. | ||
const unsubscribe = () => { | ||
window.removeEventListener("message", wrappedHandler, false); | ||
}; // Return object with unsubscribe function. | ||
}; | ||
// Return object with unsubscribe function. | ||
return { | ||
@@ -292,7 +292,6 @@ unsubscribe | ||
}; | ||
/** | ||
* An event handler that sets height of the iframe. | ||
*/ | ||
const setIframeHeight = (event, checkout) => { | ||
@@ -303,2 +302,3 @@ if (event.height || event.height === 0) { | ||
}; | ||
/** | ||
@@ -308,4 +308,2 @@ * An event handler that scrolls to the top of the iframe. This is useful when the user | ||
*/ | ||
const scrollToIframeTop = (event, checkout) => { | ||
@@ -322,7 +320,6 @@ try { | ||
}; | ||
/** | ||
* An event handler that sets language in the iframe. | ||
*/ | ||
const setLanguage = (event, checkout) => { | ||
@@ -333,3 +330,2 @@ if (event.language) { | ||
}; | ||
const handleWithResult = (sid, endpoint, handler) => { | ||
@@ -339,7 +335,5 @@ return (event, checkout) => { | ||
const pairs = eventKeys.map(key => [key, event[key]]); | ||
if (event.type === CheckoutEvents.SessionCancel && !event.error) { | ||
pairs.push(["error", "cancelled"]); | ||
} | ||
pairs.push(["language", checkout.language]); | ||
@@ -352,7 +346,6 @@ pairs.push(["sdk", pkg.version]); | ||
}; | ||
/** | ||
* Show a dintero payment session in an embedded iframe. | ||
*/ | ||
const embed = async options => { | ||
@@ -376,4 +369,5 @@ const { | ||
let checkout; | ||
const subscriptions = []; // Create iframe | ||
const subscriptions = []; | ||
// Create iframe | ||
const { | ||
@@ -389,10 +383,9 @@ iframe, | ||
})); | ||
/** | ||
* Function that removes the iframe and all event listeners. | ||
*/ | ||
const destroy = () => { | ||
if (iframe) { | ||
subscriptions.forEach(sub => sub.unsubscribe()); | ||
if (iframe.parentElement) { | ||
@@ -403,2 +396,3 @@ container.removeChild(iframe); | ||
}; | ||
/** | ||
@@ -408,4 +402,2 @@ * Turn an action into a promise by specifying resolve and | ||
*/ | ||
const promisifyAction = (action, resolveEvent, rejectEvent) => { | ||
@@ -415,3 +407,2 @@ if (!checkout) { | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -442,3 +433,2 @@ const eventSubscriptions = []; | ||
}; | ||
const lockSession = () => { | ||
@@ -449,3 +439,2 @@ return promisifyAction(() => { | ||
}; | ||
const refreshSession = () => { | ||
@@ -456,11 +445,8 @@ return promisifyAction(() => { | ||
}; | ||
const setActivePaymentProductType = paymentProductType => { | ||
postActivePaymentProductType(iframe, sid, paymentProductType); | ||
}; | ||
const submitValidationResult = result => { | ||
postValidationResult(iframe, sid, result); | ||
}; | ||
const wrappedOnValidateSession = (event, checkout) => { | ||
@@ -471,3 +457,2 @@ if (onValidateSession) { | ||
}; | ||
const wrappedOnSessionLocked = (event, checkout) => { | ||
@@ -477,5 +462,5 @@ if (onSessionLocked) { | ||
} | ||
}; // Create checkout object that wraps the destroy function. | ||
}; | ||
// Create checkout object that wraps the destroy function. | ||
checkout = { | ||
@@ -489,4 +474,5 @@ destroy, | ||
submitValidationResult | ||
}; // Add event handlers (or in some cases add a fallback href handler). | ||
}; | ||
// Add event handlers (or in some cases add a fallback href handler). | ||
[{ | ||
@@ -547,12 +533,13 @@ handler: setLanguage, | ||
} | ||
}); // Add iframe to DOM | ||
}); | ||
await initiate(); // Return object with function to destroy the checkout. | ||
// Add iframe to DOM | ||
await initiate(); | ||
// Return object with function to destroy the checkout. | ||
return checkout; | ||
}; | ||
/** | ||
* Redirect the customer to a payment session in the Dintero Checkout. | ||
*/ | ||
const redirect = options => { | ||
@@ -563,4 +550,4 @@ const { | ||
endpoint = "https://checkout.dintero.com" | ||
} = options; // Redirect the current browser window to the checkout session url. | ||
} = options; | ||
// Redirect the current browser window to the checkout session url. | ||
windowLocationAssign(getSessionUrl({ | ||
@@ -567,0 +554,0 @@ sid, |
@@ -6,3 +6,3 @@ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).dintero={})}(this,(function(e){"use strict";var n="undefined"!=typeof globalThis?globalThis:"undefined"!="object"?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};!function(e,n,t){e(t={path:n,exports:{},require:function(e,n){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==n&&t.path)}},t.exports),t.exports}((function(e){ | ||
*/ | ||
var t,o,i;i=function(){var e,n,t,o=Object.prototype.toString,i="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),e=function(e,n,t,o){return Object.defineProperty(e,n,{value:t,writable:!0,configurable:!1!==o})}}catch(n){e=function(e,n,t){return e[n]=t,e}}function r(e,o){t.add(e,o),n||(n=i(t.drain))}function s(e){var n,t=typeof e;return null==e||"object"!=t&&"function"!=t||(n=e.then),"function"==typeof n&&n}function a(){for(var e=0;e<this.chain.length;e++)c(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function c(e,n,t){var o,i;try{!1===n?t.reject(e.msg):(o=!0===n?e.msg:n.call(void 0,e.msg))===t.promise?t.reject(TypeError("Promise-chain cycle")):(i=s(o))?i.call(o,t.resolve,t.reject):t.resolve(o)}catch(e){t.reject(e)}}function d(e){var n,t=this;if(!t.triggered){t.triggered=!0,t.def&&(t=t.def);try{(n=s(e))?r((function(){var o=new f(t);try{n.call(e,(function(){d.apply(o,arguments)}),(function(){u.apply(o,arguments)}))}catch(e){u.call(o,e)}})):(t.msg=e,t.state=1,t.chain.length>0&&r(a,t))}catch(e){u.call(new f(t),e)}}}function u(e){var n=this;n.triggered||(n.triggered=!0,n.def&&(n=n.def),n.msg=e,n.state=2,n.chain.length>0&&r(a,n))}function l(e,n,t,o){for(var i=0;i<n.length;i++)!function(i){e.resolve(n[i]).then((function(e){t(i,e)}),o)}(i)}function f(e){this.def=e,this.triggered=!1}function h(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function p(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var n=new h(this);this.then=function(e,t){var o={success:"function"!=typeof e||e,failure:"function"==typeof t&&t};return o.promise=new this.constructor((function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");o.resolve=e,o.reject=n})),n.chain.push(o),0!==n.state&&r(a,n),o.promise},this.catch=function(e){return this.then(void 0,e)};try{e.call(void 0,(function(e){d.call(n,e)}),(function(e){u.call(n,e)}))}catch(e){u.call(n,e)}}t=function(){var e,t,o;function i(e,n){this.fn=e,this.self=n,this.next=void 0}return{add:function(n,r){o=new i(n,r),t?t.next=o:e=o,t=o,o=void 0},drain:function(){var o=e;for(e=t=n=void 0;o;)o.fn.call(o.self),o=o.next}}}();var y=e({},"constructor",p,!1);return p.prototype=y,e(y,"__NPO__",0,!1),e(p,"resolve",(function(e){return e&&"object"==typeof e&&1===e.__NPO__?e:new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");n(e)}))})),e(p,"reject",(function(e){return new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");t(e)}))})),e(p,"all",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):0===e.length?n.resolve([]):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");var i=e.length,r=Array(i),s=0;l(n,e,(function(e,n){r[e]=n,++s===i&&t(r)}),o)}))})),e(p,"race",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");l(n,e,(function(e,n){t(n)}),o)}))})),p},(o=n)[t="Promise"]=o[t]||i(),e.exports&&(e.exports=o[t])}));var t="0.5.0";let o,i;!function(e){e.SessionNotFound="SessionNotFound",e.SessionLoaded="SessionLoaded",e.SessionUpdated="SessionUpdated",e.SessionCancel="SessionCancel",e.SessionPaymentOnHold="SessionPaymentOnHold",e.SessionPaymentAuthorized="SessionPaymentAuthorized",e.SessionPaymentError="SessionPaymentError",e.SessionLocked="SessionLocked",e.SessionLockFailed="SessionLockFailed",e.ActivePaymentProductType="ActivePaymentProductType",e.ValidateSession="ValidateSession"}(o||(o={})),function(e){e.HeightChanged="HeightChanged",e.LanguageChanged="LanguageChanged",e.ScrollToTop="ScrollToTop"}(i||(i={}));const r=e=>{window.location.assign(e)},s=e=>{const{sid:n,endpoint:o,language:i,ui:r,shouldCallValidateSession:s}=e;if(!o)throw new Error("Invalid endpoint");const a=[i?`language=${i}`:"",r?`ui=${r}`:"",`sdk=${t}`,s?"client_side_validation=true":void 0].filter((e=>e)).join("&");return`${o}/v1/view/${n}${a?"?"+a:""}`},a=e=>{const{sid:n,endpoint:t,handler:o,eventTypes:i,checkout:r}=e,s=e=>{const s=e.origin===t,a=e.source===r.iframe.contentWindow,c=e.data&&e.data.sid===n,d=-1!==i.indexOf(e.data&&e.data.type);s&&a&&c&&d&&(((e,n)=>{n.data.mid&&e.contentWindow&&e.contentWindow.postMessage({ack:n.data.mid},n.origin||"*")})(r.iframe,e),o(e.data,r))};window.addEventListener("message",s,!1);return{unsubscribe:()=>{window.removeEventListener("message",s,!1)}}},c=e=>{e.href&&r(e.href)},d=(e,n)=>{(e.height||0===e.height)&&n.iframe.setAttribute("style",`width:100%; height:${e.height}px;`)},u=(e,n)=>{try{n.iframe.scrollIntoView({block:"start",behavior:"smooth"})}catch(e){console.error(e)}},l=(e,n)=>{e.language&&(n.language=e.language)},f=(e,n,i)=>(e,r)=>{const s=["sid","merchant_reference","transaction_id","error"].map((n=>[n,e[n]]));e.type!==o.SessionCancel||e.error||s.push(["error","cancelled"]),s.push(["language",r.language]),s.push(["sdk",t]);const a=s.filter((([e,n])=>n)).map((([e,n])=>`${e}=${n}`)).join("&");r.iframe.setAttribute("src",`${n}/embedResult/?${a}`),i(e,r)};e.embed=async e=>{const{container:n,sid:t,language:r,endpoint:h="https://checkout.dintero.com",onSession:p,onSessionCancel:y,onPayment:g,onPaymentAuthorized:m,onPaymentError:v,onSessionNotFound:w,onSessionLocked:S,onSessionLockFailed:T,onActivePaymentType:b,onValidateSession:P}=e;let E;const _=[],{iframe:k,initiate:A}=((e,n,t)=>{if(!e||!e.appendChild)throw new Error("Invalid container");const o=document.createElement("iframe");return o.setAttribute("frameborder","0"),o.setAttribute("allowTransparency","true"),o.setAttribute("style","width:100%; height:0;"),o.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"),o.setAttribute("importance","high"),o.setAttribute("src",t),{iframe:o,initiate:async()=>new Promise(((n,t)=>{o.onload=()=>n(),o.onerror=()=>t(),e.appendChild(o)}))}})(n,0,s({sid:t,endpoint:h,language:r,ui:"inline",shouldCallValidateSession:void 0!==P})),j=(e,n,o)=>{if(!E)throw new Error("Unable to create action promise: checkout is undefined");return new Promise(((i,r)=>{const s=[];s.push(a({sid:t,endpoint:h,handler:e=>{s.forEach((e=>e.unsubscribe())),i(e)},eventTypes:[n],checkout:E})),s.push(a({sid:t,endpoint:h,handler:()=>{s.forEach((e=>e.unsubscribe())),r(`Received unexpected event: ${o}`)},eventTypes:[o],checkout:E})),e()}))},L=()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"RefreshSession",sid:n},"*")})(k,t)}),o.SessionUpdated,o.SessionNotFound),N=e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"ValidationResult",sid:n,...t},"*")})(k,t,e)};return E={destroy:()=>{k&&(_.forEach((e=>e.unsubscribe())),k.parentElement&&n.removeChild(k))},iframe:k,language:r,lockSession:()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"LockSession",sid:n},"*")})(k,t)}),o.SessionLocked,o.SessionLockFailed),refreshSession:L,setActivePaymentProductType:e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"SetActivePaymentProductType",sid:n,payment_product_type:t},"*")})(k,t,e)},submitValidationResult:N},[{handler:l,eventTypes:[i.LanguageChanged]},{handler:d,eventTypes:[i.HeightChanged]},{handler:u,eventTypes:[i.ScrollToTop]},{handler:p,eventTypes:[o.SessionLoaded,o.SessionUpdated]},{eventTypes:[o.SessionPaymentOnHold],handler:g?f(0,h,g):c},{eventTypes:[o.SessionPaymentAuthorized],handler:m||g?f(0,h,m||g):c},{handler:y?f(0,h,y):c,eventTypes:[o.SessionCancel]},{handler:v?f(0,h,v):c,eventTypes:[o.SessionPaymentError]},{handler:w,eventTypes:[o.SessionNotFound]},{handler:(e,n)=>{S&&S(e,n,L)},eventTypes:[o.SessionLocked]},{handler:T,eventTypes:[o.SessionLockFailed]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:(e,n)=>{P&&P(e,n,N)},eventTypes:[o.ValidateSession]}].forEach((({handler:e,eventTypes:n})=>{e&&_.push(a({sid:t,endpoint:h,handler:e,eventTypes:n,checkout:E}))})),await A(),E},e.redirect=e=>{const{sid:n,language:t,endpoint:o="https://checkout.dintero.com"}=e;r(s({sid:n,endpoint:o,language:t,shouldCallValidateSession:!1}))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
var t,o,i;i=function(){var e,n,t,o=Object.prototype.toString,i="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),e=function(e,n,t,o){return Object.defineProperty(e,n,{value:t,writable:!0,configurable:!1!==o})}}catch(n){e=function(e,n,t){return e[n]=t,e}}function r(e,o){t.add(e,o),n||(n=i(t.drain))}function s(e){var n,t=typeof e;return null==e||"object"!=t&&"function"!=t||(n=e.then),"function"==typeof n&&n}function a(){for(var e=0;e<this.chain.length;e++)c(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function c(e,n,t){var o,i;try{!1===n?t.reject(e.msg):(o=!0===n?e.msg:n.call(void 0,e.msg))===t.promise?t.reject(TypeError("Promise-chain cycle")):(i=s(o))?i.call(o,t.resolve,t.reject):t.resolve(o)}catch(e){t.reject(e)}}function d(e){var n,t=this;if(!t.triggered){t.triggered=!0,t.def&&(t=t.def);try{(n=s(e))?r((function(){var o=new f(t);try{n.call(e,(function(){d.apply(o,arguments)}),(function(){u.apply(o,arguments)}))}catch(e){u.call(o,e)}})):(t.msg=e,t.state=1,t.chain.length>0&&r(a,t))}catch(e){u.call(new f(t),e)}}}function u(e){var n=this;n.triggered||(n.triggered=!0,n.def&&(n=n.def),n.msg=e,n.state=2,n.chain.length>0&&r(a,n))}function l(e,n,t,o){for(var i=0;i<n.length;i++)!function(i){e.resolve(n[i]).then((function(e){t(i,e)}),o)}(i)}function f(e){this.def=e,this.triggered=!1}function h(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function p(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var n=new h(this);this.then=function(e,t){var o={success:"function"!=typeof e||e,failure:"function"==typeof t&&t};return o.promise=new this.constructor((function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");o.resolve=e,o.reject=n})),n.chain.push(o),0!==n.state&&r(a,n),o.promise},this.catch=function(e){return this.then(void 0,e)};try{e.call(void 0,(function(e){d.call(n,e)}),(function(e){u.call(n,e)}))}catch(e){u.call(n,e)}}t=function(){var e,t,o;function i(e,n){this.fn=e,this.self=n,this.next=void 0}return{add:function(n,r){o=new i(n,r),t?t.next=o:e=o,t=o,o=void 0},drain:function(){var o=e;for(e=t=n=void 0;o;)o.fn.call(o.self),o=o.next}}}();var y=e({},"constructor",p,!1);return p.prototype=y,e(y,"__NPO__",0,!1),e(p,"resolve",(function(e){return e&&"object"==typeof e&&1===e.__NPO__?e:new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");n(e)}))})),e(p,"reject",(function(e){return new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");t(e)}))})),e(p,"all",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):0===e.length?n.resolve([]):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");var i=e.length,r=Array(i),s=0;l(n,e,(function(e,n){r[e]=n,++s===i&&t(r)}),o)}))})),e(p,"race",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");l(n,e,(function(e,n){t(n)}),o)}))})),p},(o=n)[t="Promise"]=o[t]||i(),e.exports&&(e.exports=o[t])}));var t="0.5.1";let o,i;!function(e){e.SessionNotFound="SessionNotFound",e.SessionLoaded="SessionLoaded",e.SessionUpdated="SessionUpdated",e.SessionCancel="SessionCancel",e.SessionPaymentOnHold="SessionPaymentOnHold",e.SessionPaymentAuthorized="SessionPaymentAuthorized",e.SessionPaymentError="SessionPaymentError",e.SessionLocked="SessionLocked",e.SessionLockFailed="SessionLockFailed",e.ActivePaymentProductType="ActivePaymentProductType",e.ValidateSession="ValidateSession"}(o||(o={})),function(e){e.HeightChanged="HeightChanged",e.LanguageChanged="LanguageChanged",e.ScrollToTop="ScrollToTop"}(i||(i={}));const r=e=>{window.location.assign(e)},s=e=>{const{sid:n,endpoint:o,language:i,ui:r,shouldCallValidateSession:s}=e;if(!o)throw new Error("Invalid endpoint");const a=[i?`language=${i}`:"",r?`ui=${r}`:"",`sdk=${t}`,s?"client_side_validation=true":void 0].filter((e=>e)).join("&");return`${o}/v1/view/${n}${a?"?"+a:""}`},a=e=>{const{sid:n,endpoint:t,handler:o,eventTypes:i,checkout:r}=e,s=e=>{const s=e.origin===t,a=e.source===r.iframe.contentWindow,c=e.data&&e.data.sid===n,d=-1!==i.indexOf(e.data&&e.data.type);s&&a&&c&&d&&(((e,n)=>{n.data.mid&&e.contentWindow&&e.contentWindow.postMessage({ack:n.data.mid},n.origin||"*")})(r.iframe,e),o(e.data,r))};window.addEventListener("message",s,!1);return{unsubscribe:()=>{window.removeEventListener("message",s,!1)}}},c=e=>{e.href&&r(e.href)},d=(e,n)=>{(e.height||0===e.height)&&n.iframe.setAttribute("style",`width:100%; height:${e.height}px;`)},u=(e,n)=>{try{n.iframe.scrollIntoView({block:"start",behavior:"smooth"})}catch(e){console.error(e)}},l=(e,n)=>{e.language&&(n.language=e.language)},f=(e,n,i)=>(e,r)=>{const s=["sid","merchant_reference","transaction_id","error"].map((n=>[n,e[n]]));e.type!==o.SessionCancel||e.error||s.push(["error","cancelled"]),s.push(["language",r.language]),s.push(["sdk",t]);const a=s.filter((([e,n])=>n)).map((([e,n])=>`${e}=${n}`)).join("&");r.iframe.setAttribute("src",`${n}/embedResult/?${a}`),i(e,r)};e.embed=async e=>{const{container:n,sid:t,language:r,endpoint:h="https://checkout.dintero.com",onSession:p,onSessionCancel:y,onPayment:g,onPaymentAuthorized:m,onPaymentError:v,onSessionNotFound:w,onSessionLocked:S,onSessionLockFailed:T,onActivePaymentType:b,onValidateSession:P}=e;let E;const _=[],{iframe:k,initiate:A}=((e,n,t)=>{if(!e||!e.appendChild)throw new Error("Invalid container");const o=document.createElement("iframe");return o.setAttribute("frameborder","0"),o.setAttribute("allowTransparency","true"),o.setAttribute("style","width:100%; height:0;"),o.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"),o.setAttribute("importance","high"),o.setAttribute("src",t),{iframe:o,initiate:async()=>new Promise(((n,t)=>{o.onload=()=>n(),o.onerror=()=>t(),e.appendChild(o)}))}})(n,0,s({sid:t,endpoint:h,language:r,ui:"inline",shouldCallValidateSession:void 0!==P})),j=(e,n,o)=>{if(!E)throw new Error("Unable to create action promise: checkout is undefined");return new Promise(((i,r)=>{const s=[];s.push(a({sid:t,endpoint:h,handler:e=>{s.forEach((e=>e.unsubscribe())),i(e)},eventTypes:[n],checkout:E})),s.push(a({sid:t,endpoint:h,handler:()=>{s.forEach((e=>e.unsubscribe())),r(`Received unexpected event: ${o}`)},eventTypes:[o],checkout:E})),e()}))},L=()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"RefreshSession",sid:n},"*")})(k,t)}),o.SessionUpdated,o.SessionNotFound),N=e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"ValidationResult",sid:n,...t},"*")})(k,t,e)};return E={destroy:()=>{k&&(_.forEach((e=>e.unsubscribe())),k.parentElement&&n.removeChild(k))},iframe:k,language:r,lockSession:()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"LockSession",sid:n},"*")})(k,t)}),o.SessionLocked,o.SessionLockFailed),refreshSession:L,setActivePaymentProductType:e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"SetActivePaymentProductType",sid:n,payment_product_type:t},"*")})(k,t,e)},submitValidationResult:N},[{handler:l,eventTypes:[i.LanguageChanged]},{handler:d,eventTypes:[i.HeightChanged]},{handler:u,eventTypes:[i.ScrollToTop]},{handler:p,eventTypes:[o.SessionLoaded,o.SessionUpdated]},{eventTypes:[o.SessionPaymentOnHold],handler:g?f(0,h,g):c},{eventTypes:[o.SessionPaymentAuthorized],handler:m||g?f(0,h,m||g):c},{handler:y?f(0,h,y):c,eventTypes:[o.SessionCancel]},{handler:v?f(0,h,v):c,eventTypes:[o.SessionPaymentError]},{handler:w,eventTypes:[o.SessionNotFound]},{handler:(e,n)=>{S&&S(e,n,L)},eventTypes:[o.SessionLocked]},{handler:T,eventTypes:[o.SessionLockFailed]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:(e,n)=>{P&&P(e,n,N)},eventTypes:[o.ValidateSession]}].forEach((({handler:e,eventTypes:n})=>{e&&_.push(a({sid:t,endpoint:h,handler:e,eventTypes:n,checkout:E}))})),await A(),E},e.redirect=e=>{const{sid:n,language:t,endpoint:o="https://checkout.dintero.com"}=e;r(s({sid:n,endpoint:o,language:t,shouldCallValidateSession:!1}))},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=dintero-checkout-web-sdk.umd.min.js.map |
{ | ||
"name": "@dintero/checkout-web-sdk", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Dintero Checkout SDK for web frontends", | ||
@@ -43,3 +43,3 @@ "main": "dist/dintero-checkout-web-sdk.cjs.js", | ||
"prettier": "^2.6.2", | ||
"puppeteer": "^18.0.5", | ||
"puppeteer": "^19.0.0", | ||
"semantic-release": "^19.0.2", | ||
@@ -46,0 +46,0 @@ "sinon": "^14.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
323422
3198