1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import process from "node:process";
import { basicAuthorization } from "https://esm.town/v/stevekrouse/basicAuthorization";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
/*
This val is a demonstration of Modern Treasury's Embedded Integration for KYC
https://docs.moderntreasury.com/docs/embedded-integation
To run this val and see the resulting HTML page, go to:
https://stevekrouse-mt.express.val.run
*/
export const mt = async (req, res) => {
const r = await fetchJSON(
"https://app.moderntreasury.com/api/user_onboardings",
{
method: "POST",
body: JSON.stringify({
flow_alias: "default-individual",
}),
headers: await basicAuthorization(
process.env.mtOrganizationId,
process.env.mtApiKey,
),
},
);
res.send(`<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.moderntreasury.com/compliance/v1/mt-onboarding.js"></script>
<script type="application/ecmascript">
function openIframe() {
const onSuccess = function (event) {
// handle success event (e.g. move user to the next step of your flow following KYC)
};
const onError = function (event) {
// handle error event (e.g. open the iframe again)
};
const onCancel = function (event) {
// handle cancel event (e.g. email the user later to try and reactivate them)
// note: this event will not be triggered if the user closes their browser.
};
const userOnboardingId = document.getElementById('userOnboardingId').value;
window.onboardingInstance = MTOnboarding.open({
userOnboardingId: userOnboardingId, // required
onSuccess: onSuccess, // optional
onError: onError, // optional
onClose: onCancel, // optional
});
}
</script>
</head>
<body>
<label for="userOnboardingId">User Onboarding ID:</label>
<input type="text" value="${r.id}" name="userOnboardingId" id="userOnboardingId">
<br/>
<button onclick="openIframe()">
Open
</button>
</body>
</html>`);
};