-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change iframes to use middleware pages (#10)
- Loading branch information
Showing
8 changed files
with
232 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Basis Theory 3DS Challenge</title> | ||
<style> | ||
/* remove default margins/padding and hide any overflow */ | ||
html, body { | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
/* style for the iframe so it takes the full available space */ | ||
#acsChallengeIframe { | ||
display: block; | ||
margin: 0; | ||
padding: 0; | ||
border: none; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
</body> | ||
|
||
<script> | ||
let acsURL = ''; | ||
let creq = ''; | ||
|
||
window.addEventListener('message', (event) => { | ||
if (event.data.type === 'startChallenge') { | ||
acsURL = event.data.acsURL; | ||
creq = event.data.creq; | ||
|
||
if (!acsURL || !creq) { | ||
window.parent?.postMessage({ | ||
type: 'error', | ||
details: 'acsURL or creq missing in the message' | ||
}, '*'); | ||
} | ||
|
||
// iframe | ||
const iframe = document.createElement('iframe'); | ||
iframe.name = 'acsChallengeIframe'; | ||
iframe.id = 'acsChallengeIframe'; | ||
iframe.width = '100%'; // fill parent iframe | ||
iframe.height = '100%'; // fill parent iframe | ||
document.body.appendChild(iframe); | ||
|
||
const html = document.createElement('html'); | ||
const body = document.createElement('body'); | ||
|
||
// challenge form | ||
const form = document.createElement('form'); | ||
form.name = 'threeDSCReqForm'; | ||
form.action = acsURL; | ||
form.method = 'POST'; | ||
form.target = iframe.name; | ||
|
||
const input = document.createElement('input'); | ||
input.name = 'creq'; | ||
input.value = creq; | ||
form.appendChild(input); | ||
body.appendChild(form); | ||
html.appendChild(body); | ||
|
||
// add form to iframe | ||
iframe.appendChild(html); | ||
form.submit(); | ||
|
||
// submit and catch event | ||
// form.submit(); | ||
} else if (event.data.type === 'challenge') { | ||
// message coming from api notification, post back to parent | ||
window.parent?.postMessage(event.data, '*'); | ||
} | ||
|
||
// ignore other messages | ||
}); | ||
</script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Basis Theory 3DS Method Request</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Collecting Browser Data...</h1> | ||
<p>If you are not redirected automatically, please click <a href="#" onclick="document.threeDSMethodForm.submit(); return false;">here</a>.</p> | ||
</body> | ||
|
||
<script> | ||
let threeDSMethodURL = ''; | ||
let threeDSMethodData = ''; | ||
|
||
window.addEventListener('message', (event) => { | ||
if (event.data.type === 'startMethod') { | ||
threeDSMethodURL = event.data.threeDSMethodURL; | ||
threeDSMethodData = event.data.threeDSMethodData; | ||
|
||
if (!threeDSMethodURL || !threeDSMethodData) { | ||
window.parent?.postMessage({ | ||
type: 'error', | ||
details: 'threeDSMethodURL or threeDSMethodData missing in the message' | ||
}, '*'); | ||
} | ||
|
||
// iframe | ||
const iframe = document.createElement('iframe'); | ||
iframe.name = 'acsMethodIframe'; | ||
iframe.id = 'acsSMethodIframe'; | ||
iframe.style.display = 'none'; | ||
iframe.width = '0'; | ||
iframe.height = '0'; | ||
iframe.frameBorder = '0'; | ||
iframe.style.border = '0'; | ||
document.body.appendChild(iframe); | ||
|
||
// method form | ||
const form = document.createElement('form'); | ||
form.name = 'threeDSMethodForm'; | ||
form.action = threeDSMethodURL; | ||
form.method = 'POST'; | ||
form.target = iframe.name; | ||
|
||
const input = document.createElement('input'); | ||
input.type = 'hidden'; | ||
input.name = 'threeDSMethodData'; | ||
input.value = threeDSMethodData; | ||
form.appendChild(input); | ||
document.body.appendChild(form); | ||
|
||
// submit and catch event | ||
form.submit(); | ||
} else if (event.data.type === 'method') { | ||
// message coming from api notification, post back to parent | ||
window.parent?.postMessage(event.data, '*'); | ||
} | ||
|
||
// ignore other messages | ||
}); | ||
</script> | ||
|
||
</html> |
Oops, something went wrong.