-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
289 lines (263 loc) · 9.62 KB
/
index.html
File metadata and controls
289 lines (263 loc) · 9.62 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SimpleCheckout Playground</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
h1 {
color: #333;
text-align: center;
}
.subtitle {
text-align: center;
color: #666;
margin-bottom: 30px;
}
.instructions {
background-color: #f8f9fa;
border-left: 4px solid #007bff;
padding: 15px 20px;
margin-bottom: 30px;
border-radius: 4px;
}
.instructions h3 {
margin-top: 0;
}
.instructions ul {
margin: 10px 0 0 0;
padding-left: 20px;
}
.config-section {
margin-bottom: 30px;
padding: 20px;
background-color: #f8f9fa;
border-radius: 4px;
}
.config-section label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #333;
font-size: 14px;
}
.input-group {
margin-bottom: 15px;
}
.config-input {
width: 100%;
padding: 10px;
border: 1px solid #ced4da;
border-radius: 4px;
font-size: 14px;
font-family: monospace;
}
.config-input:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}
.init-button {
background-color: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
font-weight: 500;
width: 100%;
margin-top: 10px;
}
.init-button:hover {
background-color: #0056b3;
}
.init-button:disabled {
background-color: #6c757d;
cursor: not-allowed;
}
#checkout-container {
margin-top: 20px;
min-height: 200px;
border: 2px dashed #dee2e6;
border-radius: 4px;
padding: 20px;
align-items: center;
justify-content: center;
}
#checkout-container.active {
border: none;
padding: 0;
}
.placeholder-text {
color: #6c757d;
text-align: center;
}
.status {
margin-top: 20px;
padding: 15px;
border-radius: 4px;
font-weight: 500;
word-break: break-all;
font-family: monospace;
font-size: 14px;
}
.status.success {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.status.info {
background-color: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
</style>
</head>
<body>
<div class="container">
<nav style="margin-bottom: 20px; text-align: center; padding-bottom: 20px; border-bottom: 1px solid #eee;">
<a href="/" style="margin-right: 15px; font-weight: bold; text-decoration: none; color: #333;">Credit Card Tokenization</a>
<span style="color: #ccc;">|</span>
<a href="/account.html" style="margin-left: 15px; text-decoration: none; color: #007bff;">Account Connection</a>
</nav>
<h1>SimpleCheckout Playground</h1>
<p class="subtitle">Test the SimpleCheckout credit card tokenization flow</p>
<div class="instructions">
<h3>How to use:</h3>
<ul>
<li>Enter your Publishable Key and Customer ID below (or pass as URL params ?publishable_key=pk_sandbox_...&customer_id=customer_uuid)</li>
<li>Click "Initialize Form" to load the secure credit card form</li>
<li>Fill in the credit card details and email</li>
<li>Submit the form to receive a token representing the card</li>
<li>You can use this token to <a href="https://docs.simplecheckout.ai/">create checkouts with the users' CC</a></li>
</ul>
</div>
<div class="config-section">
<div class="input-group">
<label for="publishable-key">Publishable Key:</label>
<input
type="text"
id="publishable-key"
class="config-input"
placeholder="pk_sandbox_..."
/>
</div>
<div class="input-group">
<label for="customer-id">Customer ID:</label>
<input
type="text"
id="customer-id"
class="config-input"
placeholder="customer_uuid"
/>
</div>
<button id="init-btn" class="init-button">Initialize Form</button>
</div>
<div id="status" class="status info">
Ready to initialize...
</div>
<div id="checkout-container">
<div class="placeholder-text">
Enter your Publishable Key above and click "Initialize Form" to begin
</div>
</div>
</div>
<script type="module">
import SimpleCheckout from 'simplecheckout-sdk';
let simplecheckout = null;
let creditCardForm = null;
const statusEl = document.getElementById('status');
const publishableKeyInput = document.getElementById('publishable-key');
const customerIdInput = document.getElementById('customer-id');
const initBtn = document.getElementById('init-btn');
const checkoutContainer = document.getElementById('checkout-container');
function updateStatus(message, type = 'info') {
statusEl.textContent = message;
statusEl.className = `status ${type}`;
}
async function initializeForm(publishableKey, customerId) {
try {
updateStatus('Initializing SimpleCheckout...', 'info');
// Clear any existing form
checkoutContainer.innerHTML = '';
checkoutContainer.classList.add('active');
simplecheckout = new SimpleCheckout(publishableKey);
creditCardForm = await simplecheckout.initEmbeddedCreditCardForm({
customerId: customerId,
onSuccess: (result) => {
updateStatus(`Success! Token: ${result.token}`, 'success');
console.log('Card stored successfully:', result);
},
onError: (error) => {
updateStatus(`Error: ${error.message}`, 'error');
console.error('Error storing card:', error);
}
});
creditCardForm.mount('#checkout-container');
updateStatus('Form loaded successfully! Fill in your card details.', 'success');
} catch (error) {
updateStatus(`Initialization error: ${error.message}`, 'error');
console.error('Initialization error:', error);
checkoutContainer.innerHTML = '<div class="placeholder-text">Failed to load form. Please check your configuration.</div>';
checkoutContainer.classList.remove('active');
}
}
// Check URL parameters on load
window.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const urlPublishableKey = urlParams.get('publishable_key');
const urlCustomerId = urlParams.get('customer_id');
if (urlPublishableKey) {
publishableKeyInput.value = urlPublishableKey;
}
if (urlCustomerId) {
customerIdInput.value = urlCustomerId;
}
if (urlPublishableKey && urlCustomerId) {
updateStatus('Configuration loaded from URL. Click "Initialize Form" to begin.', 'info');
}
});
// Initialize button click handler
initBtn.addEventListener('click', () => {
const publishableKey = publishableKeyInput.value.trim();
const customerId = customerIdInput.value.trim();
if (!publishableKey) {
updateStatus('Please enter a Publishable Key', 'error');
return;
}
if (!customerId) {
updateStatus('Please enter a Customer ID', 'error');
return;
}
initializeForm(publishableKey, customerId);
});
// Allow Enter key to initialize form
[publishableKeyInput, customerIdInput].forEach(input => {
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
initBtn.click();
}
});
});
</script>
</body>
</html>