-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostrelease-testbed.html
More file actions
150 lines (140 loc) · 4.26 KB
/
Copy pathpostrelease-testbed.html
File metadata and controls
150 lines (140 loc) · 4.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Xendit Components Postrelease Testbed</title>
<!--
This file should be deployed to https://assets.xendit.co/components/postrelease-testbed.html
Access it from there, it will not work if opened locally.
-->
<style>
body {
display: flex;
flex-direction: column;
gap: 16px;
font-family: Arial, sans-serif;
margin: 20px;
}
#config-form {
display: flex;
flex-direction: column;
border: 1px solid #ccc;
padding: 12px;
width: 350px;
gap: 8px;
}
#config-form label {
display: block;
}
#config-form input,
#config-form select {
height: 28px;
box-sizing: border-box;
padding: 4px;
}
#config-form button {
align-self: flex-start;
padding: 4px 12px;
}
#config-form ::placeholder {
color: #aaa;
}
#container {
border: 1px solid #ccc;
padding: 12px;
width: 350px;
}
#controls {
border: 1px solid #ccc;
padding: 12px;
width: 350px;
}
</style>
</head>
<body>
<form id="config-form">
<label for="script-src">Load SDK from:</label>
<select id="script-src" name="script-src">
<option value="https://assets.xendit.co/components/%s/index.umd.js">
Prod
</option>
<option
value="https://assets.stg.tidnex.dev/components/%s/index.umd.js"
>
Staging
</option>
</select>
<label for="version">Version (with v prefix)</label>
<input id="version" name="version" placeholder="v1.2.3" />
<label for="key">Components SDK Key</label>
<input id="key" name="key" />
<button id="load-button" type="submit">Load</button>
</form>
<div id="container"></div>
<div id="controls">
<button id="submit-button" type="button">Submit</button>
<button id="abort-button" type="button">Abort</button>
</div>
<script>
const $ = (id) => document.querySelector(id);
$("#config-form").addEventListener(
"submit",
(e) => {
e.preventDefault();
$("#load-button").remove();
const formData = new FormData(e.target);
const scriptSrcTemplate = formData.get("script-src");
const version = formData.get("version").trim();
const key = formData.get("key").trim();
const scriptSrc = scriptSrcTemplate.replace("%s", version);
const script = document.createElement("script");
script.src = scriptSrc;
script.onload = function () {
try {
init(key);
} catch (e) {
alert("Failed to initialize components: " + e.message);
console.error(e);
}
};
script.onerror = (err) => {
alert("Failed to load script: " + err.message);
console.error(err);
};
document.body.appendChild(script);
},
{ once: true },
);
function init(key) {
const XenditComponents = key
? window.Xendit.XenditComponents
: window.Xendit.XenditComponentsTest;
const container = $("#container");
container.replaceChildren();
const components = new XenditComponents({
componentsSdkKey: key,
});
const channelPicker = components.createChannelPickerComponent();
container.appendChild(channelPicker);
components.addEventListener("fatal-error", (evt) => {
alert("Fatal error: " + evt.message);
console.error(evt);
});
components.addEventListener("session-complete", (evt) => {
alert("Session complete");
console.log(err);
});
components.addEventListener("session-expired-or-canceled", (evt) => {
alert("Session expired or canceled");
console.log(err);
});
$("#submit-button").addEventListener("click", async () => {
components.submit();
});
$("#abort-button").addEventListener("click", async () => {
components.abortSubmission();
});
}
</script>
</body>
</html>