-
Notifications
You must be signed in to change notification settings - Fork 48
/
multiplexing.html
343 lines (318 loc) · 10.7 KB
/
multiplexing.html
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>VGS Collect + Multiplexing</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<script
type="text/javascript"
src="https://js.verygoodvault.com/vgs-collect/2.14.0/vgs-collect.js"
></script>
<style>
body {
padding: 25px;
}
pre {
font-size: 12px;
}
p {
margin-bottom: 10px;
}
label {
font-weight: 600;
color: #526570;
font-size: 14px;
margin-bottom: 5px;
}
.btn {
width: 100%;
background-color: #07193a;
border-color: #07193a;
color: #fff;
}
form {
max-width: 600px;
margin: 0 auto;
}
iframe {
height: 100%;
width: 100%;
border: 0 none transparent;
}
.form-field {
display: block;
width: 100%;
padding-top: 0;
padding-bottom: 0;
box-shadow: 0px 0px 6px rgb(23 31 39 / 30%);
border: 1px solid transparent;
height: 2.5rem;
border-radius: 0.25rem;
padding: 0 12px;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.form-group {
position: relative;
margin-bottom: 2rem;
}
.error-message {
position: absolute;
left: 0;
margin-top: 4px;
color: #dc3545;
font-size: 12px;
line-height: 1.5rem;
}
.vgs-collect-container__focused {
border: 1px solid #145ff5;
box-shadow: 0px 0px 6px rgba(87, 158, 255, 0.4);
}
.vgs-collect-container__invalid.vgs-collect-container__dirty:not(.vgs-collect-container__focused) {
border: 1px solid #ff0000;
box-shadow: 0px 0px 6px rgba(255, 0, 0, 0.4);
}
</style>
</head>
<body>
<main>
<h2 class="text-center mb-5">Collect.js + Multiplexing Integration</h2>
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
<h3 class="text-center">Collect.js Secure Form</h3>
<form id="cc-form">
<div class="form-group">
<label for="cc-first-name">*First Name</label>
<span id="cc-first-name" class="form-field">
<!--VGS Collect iframe for card name field will be here!-->
</span>
<span class="error-message"></span>
</div>
<div class="form-group">
<label for="cc-second-name">*Last Name</label>
<span id="cc-second-name" class="form-field">
<!--VGS Collect iframe for card name field will be here!-->
</span>
<span class="error-message"></span>
</div>
<div class="form-group">
<label for="cc-number">*Card number</label>
<span id="cc-number" class="form-field">
<!--VGS Collect iframe for card number field will be here!-->
</span>
<span class="error-message"></span>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-group">
<label for="cc-expiration-date">*Expiration date</label>
<span id="cc-expiration-date" class="form-field">
<!--VGS Collect iframe for expiration date field will be here!-->
</span>
<span class="error-message"></span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="cc-cvc">*CVC</label>
<span id="cc-cvc" class="form-field">
<!--VGS Collect iframe for CVC field will be here!-->
</span>
<span class="error-message"></span>
</div>
</div>
</div>
<!--Submit credit card form button-->
<button type="submit" class="btn">Submit</button>
</form>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-3">
<div class="card-body">
<h5 class="text-center">Instruction:</h5>
<ol>
<li class="mb-3">
Replace placeholder with your own vault id and environment in
order to initialize Collect.js form:
<code
>VGSCollect.create('tntXXXXXXXX', 'sandbox', function(state)
{})</code
>
</li>
<li class="mb-3">
Make sure you have an
<a
href="https://github.com/verygoodsecurity/vgs-collect-examples/tree/collect-multiplexing-demo/examples/v2/multiplexing#3-setup-inbound-routee"
target="_blank"
>Inbound Route</a
>
configured properly for this vault with valid Upstream Host
(host of the multiplexer application). Please use
<code>inbound.yaml</code> as a template if you don't have one.
</li>
<li class="mb-3">
Fill in and submit the form with the
<a
href="https://www.verygoodsecurity.com/docs/vgs-collect/test-data"
targfet="_blank"
>test data</a
>. Form submit action will perform POST request to the
<code>/api/v1/financial_instruments</code> endpoint with
needed payload structure.
</li>
<li class="mb-3">
Check <b>Response</b> section below for aliased data. See how
card number in the response was successfully secured:
<code>"number": "XXXX-XXXX-XXXX-1111"</code>
</li>
<li class="mb-3">
Check <b>Financial Instruments List</b> under Financial
Instruments tab in the Multiplexing application. Make sure the
record you've just created appears in the list:
<img
src="https://i.ibb.co/xSn5Ssr/Screen-Shot-2021-04-09-at-1-02-41-PM.png"
alt=""
width="100%"
/>
</li>
</ol>
</div>
</div>
<div class="alert alert-primary">
<h5 class="text-center">Response (aliased Payment Instrument)</h5>
<pre id="result">
Submit a form to see result.
</pre
>
</div>
</div>
</div>
</main>
<!--Include script with VGS Collect form initialization-->
<script>
// VGS Collect form initialization
const form = VGSCollect.create(
"<vault-id>",
"<environment>",
function (state) {}
);
const css = {
"&::placeholder": {
color: "#C8D0DB",
},
"&::-webkit-input-placeholder": {
"line-height": "normal!important",
},
"font-family": '"Segoe UI", sans-serif',
"font-size": "16px",
};
// Create VGS Collect field for first name
form.field("#cc-first-name", {
type: "text",
name: "data.attributes.details.first_name",
placeholder: "Joe",
validations: ["required"],
css,
});
// Create VGS Collect field for last name
form.field("#cc-second-name", {
type: "text",
name: "data.attributes.details.last_name",
placeholder: "Business",
validations: ["required"],
css,
});
// Create VGS Collect field for credit card number
form.field("#cc-number", {
type: "card-number",
name: "data.attributes.details.number",
placeholder: "4111 1111 1111 1111",
validations: ["required", "validCardNumber"],
showCardIcon: true,
autoComplete: "cc-number",
css,
});
// Create VGS Collect field for CVC
form.field("#cc-cvc", {
type: "card-security-code",
name: "data.attributes.details.verification_value",
placeholder: "CVC",
validations: ["required", "validCardSecurityCode"],
showCardIcon: true,
css,
});
// Create VGS Collect field for credit card expiration date
form.field("#cc-expiration-date", {
type: "card-expiration-date",
name: "data.attributes.details",
placeholder: "MM / YYYY",
validations: ["required", "validCardExpirationDate"],
autoComplete: "cc-exp",
serializers: [
{
name: "separate",
options: { monthName: "month", yearName: "year" },
},
],
css,
});
// Trigger form submit on Enter press
form.on("enterPress", function () {
submitCollectForm();
});
// Show error message
form.fields.forEach(function (field) {
field.on("update", function (state) {
if (!state.isValid && state.isDirty && !state.isFocused) {
field.container.nextElementSibling.innerHTML =
state.errorMessages[0];
} else {
field.container.nextElementSibling.innerHTML = "";
}
});
});
const submitCollectForm = () => {
form.submit(
"/api/v1/financial_instruments",
{
mapDotToObject: "merge",
data: {
data: {
type: "financial_instruments",
attributes: {
instrument_type: "card",
},
},
},
},
function (status, data) {
document.getElementById("result").innerHTML = JSON.stringify(
data,
null,
4
);
}
);
};
// Submits all of the form fields by executing a POST request.
document.getElementById("cc-form").addEventListener(
"submit",
function (e) {
e.preventDefault();
submitCollectForm();
},
function (errors) {
document.getElementById("result").innerHTML = errors;
}
);
</script>
</body>
</html>