<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>StateSet ACP WASM Demo</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
pre {
background: #f5f5f5;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #0056b3;
}
#output {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>StateSet ACP WASM Demo</h1>
<div>
<button onclick="createSession()">Create Checkout Session</button>
<button onclick="completeSession()">Complete Checkout</button>
<button onclick="cancelSession()">Cancel Session</button>
</div>
<div id="output">
<h3>Output:</h3>
<pre id="result">Click a button to test the WASM bindings</pre>
</div>
<script type="module">
import init, { AcpClient, version } from './pkg/acp_wasm.js';
let client;
let currentSessionId;
async function initialize() {
await init();
client = new AcpClient('api_key_demo_123');
log(`Initialized ACP WASM v${version()}`);
}
function log(message) {
document.getElementById('result').textContent =
typeof message === 'object'
? JSON.stringify(message, null, 2)
: message;
}
window.createSession = async function() {
try {
const session = client.createCheckoutSession([
{ id: 'prod_laptop_001', quantity: 1 },
{ id: 'prod_mouse_002', quantity: 2 }
]);
currentSessionId = session.id;
log(session);
} catch (e) {
log(`Error: ${e}`);
}
};
window.completeSession = async function() {
if (!currentSessionId) {
log('Create a session first');
return;
}
try {
const result = client.completeCheckoutSession(currentSessionId, 'tok_demo_123');
log(result);
} catch (e) {
log(`Error: ${e}`);
}
};
window.cancelSession = async function() {
if (!currentSessionId) {
log('Create a session first');
return;
}
try {
const session = client.cancelCheckoutSession(currentSessionId);
log(session);
} catch (e) {
log(`Error: ${e}`);
}
};
initialize();
</script>
</body>
</html>