-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
483 lines (472 loc) · 20.5 KB
/
Copy pathindex.html
File metadata and controls
483 lines (472 loc) · 20.5 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
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://pay.sandbox.datatrans.com/upp/payment/js/payment-button-3.1.0.js"></script>
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-exp.min.css">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-icons.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="css/wallet-js.css" />
<link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="icons/favicon-16x16.png">
<link rel="mask-icon" href="icons/safari-pinned-tab.svg" color="#213d62">
<link rel="shortcut icon" href="icons/favicon.ico">
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
crossorigin="anonymous">
</script>
<title>Payment Button Showcase</title>
</head>
<body class="p-2">
<div class="container" style="max-width: 2160px; margin: 0 auto;">
<div class="columns my-2">
<header class="navbar">
<section class="navbar-section">
<a href="#intro" class="btn btn-link">Introduction</a>
<a href="#howto" class="btn btn-link">How it works</a>
<a href="#reference" class="btn btn-link">Reference</a>
</section>
</header>
</div>
<div class="columns">
<div class="col-md-6 col-xs-12 column" id="intro">
<h2>Datatrans Payment Button </h2>
<p>
Use this JavaScript library to render an Apple Pay or Google Pay button. It uses the Payment Request API
<a href="https://www.w3.org/TR/payment-request/">specified</a> by W3C when available. If not, it falls back to
the corresponding vendor implementation. This library gives you a single integration for rendering payment
buttons. It can automatically detect which button should be displayed depending on the browser and device
combination that is supported and used. In the demo below, depending on your device you will see either an
Apple Pay or Google Pay button.
Please note that for Apple Pay this library only works with a Datatrans merchantId which has been enabled for
Apple Pay processing via Datatrans.
</p>
</div>
<div class="col-12 column divider"></div>
<div class="col-12 column" id="demo">
<h3>Configure and test the example </h3>
<div class="columns">
<div class="col-3 col-xl-6 col-md-12 column">
<form class="form-horizontal" id="configForm">
<div class="columns" style="flex-direction: column">
<div class="col-md-6 col-xs-12 column mb-2">
<div class="form-group">
<label class="form-switch form-inline">
<input type="checkbox" id="useApplePay">
<i class="form-icon"></i> Use Apple Pay only
</label>
<label class="form-switch form-inline">
<input type="checkbox" id="useGooglePay">
<i class="form-icon"></i> Use Google Pay only
</label>
</div>
</div>
<div class="col-md-6 col-xs-12 column mb-2">
<div class="form-group">
<label class="form-switch form-inline">
<input type="checkbox" id="requestPayerEmail">
<i class="form-icon"></i> Request Payer Email
</label>
<label class="form-switch form-inline">
<input type="checkbox" id="requestPayerName">
<i class="form-icon"></i> Request Payer Name
</label>
<label class="form-switch form-inline">
<input type="checkbox" id="requestPayerPhone">
<i class="form-icon"></i> Request Payer Phone
</label>
</div>
</div>
<div class="col-md-6 col-xs-12 column">
<div class="form-group">
<label class="form-switch form-inline">
<input type="checkbox" id="createAlias">
<i class="form-icon"></i> Create Alias
</label>
<label class="form-switch form-inline">
<input type="checkbox" id="tokenOnly">
<i class="form-icon"></i> Output Token Data
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="form-label" for="merchantName">Merchant Name</label>
<input class="form-input" type="text" id="merchantName" placeholder="Merchant Name">
</div>
<div class="form-group">
<label class="form-label" for="amount">Amount</label>
<input class="form-input" type="text" pattern="[0-9]*" id="amount" placeholder="Amount">
</div>
<div class="form-group">
<label class="form-label" for="currency">Currency</label>
<select class="form-select" id="currency">
<option value="CHF">CHF</option>
<option value="USD" selected>USD</option>
<option value="EUR">EUR</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="version">Transaction API version</label>
<select class="form-select" id="version">
<option value="1" selected>1</option>
<option value="2">2</option>
</select>
</div>
</form>
</div>
<div class="column col-md-12 mb-2 pb-2">
<h4>Events output</h4>
<div class="console p-relative bg-gray mb-2" style="min-height: 70px;">
<div class="console-content p-2"></div>
<i id="clearButton" class="p-absolute icon icon-2x icon-delete" style="bottom: 20px; right: 20px;"></i>
</div>
<div id="paybutton" class="p-relative mb-2 pb-2"></div>
</div>
</div>
</div>
<div class="col-12 column divider"></div>
<div class="col-12 column" id="howto">
<h2>How it works</h2>
<div class="columns">
<div class="col-12 column">
<h4>1) The payment request</h4>
The library expects a payment request when a button is created. The payment request is
an object which conforms with the <a
href="https://www.w3.org/TR/payment-request/#paymentrequest-interface">W3C payment
request interface description</a>.
The object is extended with a transaction property, which contains Datatrans-specific
values such as "countryCode", "refno", etc.
<pre data-lang="JSON"><code class="language-javascript">
const payment = {
// W3C spec
details: {
total: {
label: 'My Merchant',
amount: { value: '4', currency: 'USD' },
},
displayItems: [
{
label: 'Tax',
amount: { value: '2.50', currency: 'USD' },
},
],
},
// W3C spec
options: {
requestPayerEmail: false,
requestPayerName: false,
requestPayerPhone: false,
},
// Datatrans specific
transaction: {
countryCode: 'CH',
refno: '3e23dasdasd1123',
version: 1,
},
};</code></pre>
</div>
<div class="col-12 column">
<h4>2) Initialize the library</h4>
<pre><code class="language-markup"><script src="https://pay.sandbox.datatrans.com/upp/payment/js/payment-button-3.1.0.js" type="text/javascript"></script></code></pre>
<pre><code class="language-javascript">
const paymentButton = new PaymentButton();
paymentButton.init({
merchantId: '1000011011',
merchantName: 'Test',
tokenOnly: false,
autoSettle: false,
allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
googlePayConfiguration: {
buttonType: 'long',
buttonStyle: 'black',
merchantId: '01234567890123456789'
},
applePayConfiguration: {
buttonType: 'plain',
buttonStyle: 'black'
},
});</code></pre>
</div>
<div class="col-12 column">
<h4>3) Listen for the init event and create the button</h4>
<pre><code class="language-javascript">paymentButton.on("init", function () {
paymentButton.create(document.getElementById('paybutton'), payment)
});</code></pre>
</div>
<div class="col-12 column">
<h4>4) Listen for the authorization event and continue</h4>
<pre><code class="language-javascript">paymentButton.on("authorization", function (response) {
// handle transaction result
});</code></pre>
</div>
</div>
<div class="divider"></div>
<div>
<h2>Reference</h2>
<div class="columns reference" id="reference">
<div class="col-3 col-xl-12 column mb-2">
<h4>Events</h4>
The following events are emitted by the library:
<ul>
<li><b>init</b> - emitted when the library is initialized and ready to use</li>
<li><b>create</b> - emitted when payment button is rendered</li>
<li><b>authorization</b> - emitted when an authorization response has been received - <b>payload:</b>
authorization response</li>
<li><b>abort</b> - emitted when the payment request has been cancelled by the user</li>
<li><b>unsupported</b> - emitted when no payment method is supported</li>
<li><b>error</b> - emitted when an error occurs - <b><optional>payload:</b> error message</li>
</ul>
</div>
<div class="col-9 col-xl-12 column">
<h4>Init parameters</h4>
<table class="table">
<thead><tr>
<th>Option</th>
<th>Description</th>
<th class="nowrap">Data type</th>
</tr></thead>
<tbody>
<tr>
<th>
merchantId
<div class="text-error text-small">required</div>
</th>
<td>Your Datatrans merchantId</td>
<td>String</td>
</tr>
<tr>
<th>
merchantName
<div class="text-error text-small">required</div>
</th>
<td>Your merchant name</td>
<td>String</td>
</tr>
<tr>
<th>
allowedCardNetworks
<div class="text-error text-small">required</div>
</th>
<td>Which card networks to accept</td>
<td class="nowrap">String array</td>
</tr>
<tr>
<th>useGooglePay</th>
<td>Use this property to disable Google Pay. Note: By default Google Pay is enabled if
supported by the browser</td>
<td>Boolean</td>
</tr>
<tr>
<th>useApplePay</th>
<td>Use this property to disable Apple Pay. Note: Apple Pay can only be displayed in
Safari browsers. Note: By default Apple Pay is enabled if supported by the browser</td>
<td>Boolean</td>
</tr>
<tr>
<th>tokenOnly</th>
<td>Whether to output token data only. Default is false.</td>
<td>Boolean</td>
</tr>
<tr>
<th>autoSettle</th>
<td>Whether the transaction will be settled automatically. Default is false.</td>
<td>Boolean</td>
</tr>
<tr>
<th>googlePayConfiguration</th>
<td></td>
<td>Object</td>
</tr>
<tr>
<th class="indent-1">buttonType</th>
<td>The type of button, described <a
href="https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions">here</a>
</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">buttonStyle</th>
<td>The style of button, described <a
href="https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions">here</a>
</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">merchantId</th>
<td>Your Google Pay merchantId. Can be found in the Google Pay <a
href="https://pay.google.com/business/console">merchant console</a>
</td>
<td>String</td>
</tr>
<tr>
<th>applePayConfiguration</th>
<td></td>
<td>Object</td>
</tr>
<tr>
<th class="indent-1">buttonType</th>
<td>The type of button, described <a
href="https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons">here</a>
</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">buttonStyle</th>
<td>The style of the button, described <a
href="https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons">here</a>
</td>
<td>String</td>
</tr>
</table>
<br/>
<h4>Transaction parameters</h4>
<table class="table">
<thead>
<tr>
<th>Option</th>
<th>Since</th>
<th>Description</th>
<th class="nowrap">Data type</th>
</tr>
</thead>
<tbody>
<tr>
<th>
refno
<div class="text-error text-small">required</div>
</th>
<td>v1.0</td>
<td>
Your reference number. Find out more
<a href="https://api-reference.datatrans.ch/#mandatory-parameters">here</a>
</td>
<td>String</td>
</tr>
<tr>
<th>
countryCode
<div class="text-error text-small">required</div>
</th>
<td>v1.0</td>
<td>
<div>ISO 3166-1 alpha-2 country code where the transaction is processed.</div>
<div>This is required for merchants based in European Economic Area (EEA) countries.</div>
<div><b>Mandatory</b> for payment-button v2 and v3 libraries.</div>
</td>
<td>String</td>
</tr>
<tr>
<th>createAlias</th>
<td>v1.0</td>
<td>
<div>Whether to create an alias.</div>
<div>
The alias will be sent on the <a href="https://api-reference.datatrans.ch/#section/Webhook">webhook</a>
and is also returned through a <a href="https://api-reference.datatrans.ch/#operation/status">status call</a>.
</div>
</td>
<td>Boolean</td>
</tr>
<tr>
<th>authenticationOnly</th>
<td>v1.0</td>
<td>Only authenticate the transaction (used for deferred authorization)</td>
<td>Boolean</td>
</tr>
<tr>
<th>version</th>
<td>v3.1</td>
<td>
<div>Transaction API version. Default: 1</div>
<div>Allowed values: 1 | 2</div>
</td>
<td>Number</td>
</tr>
<tr>
<th>mcp</th>
<td>v3.0</td>
<td>Configuration of Multi-Currency Pricing. Find out more <a href="https://docs.datatrans.ch/docs/multi-currency-pricing">here</a>.</td>
<td>Object</td>
</tr>
<tr>
<th class="indent-1">amount</th>
<td>v3.0</td>
<td></td>
<td>Object</td>
</tr>
<tr>
<th class="indent-2">value</th>
<td>v3.0</td>
<td>
<div>Amount the customer will pay in their currency.</div>
<div>
If you want to include fractional monetary units (pennies, cents, Rappen), you will have to
separate the amount using a decimal point (e.g. 5.10 instead of 510).
</div>
</td>
<td>String</td>
</tr>
<tr>
<th class="indent-2">currency</th>
<td>v3.0</td>
<td>ISO 4217 currency code of the amount the customer will pay.</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">provider</th>
<td>v3.0</td>
<td>Identify the MCP provider used.</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">reasonIndicator</th>
<td>v3.0</td>
<td>If received from acquirer the reason indicator can be set</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">conversionRate</th>
<td>v3.0</td>
<td>
<div>Rate used to calculate MCP amount.</div>
<div>Note: Only used in dynamic MCP</div>
</td>
<td class="nowrap">String | Number</td>
</tr>
<tr>
<th class="indent-1">transactionDate</th>
<td>v3.0</td>
<td>
<div>Date when the rate was fetched from the MCP provider.</div>
<div>Note: Only used in dynamic MCP</div>
</td>
<td>String</td>
</tr>
<tr>
<th class="indent-1">retrievalReferenceNumber</th>
<td>v3.0</td>
<td>
<div>Reference number of the MCP provider response.</div>
<div>Note: Only used in dynamic MCP</div>
</td>
<td>String</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="./index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/prism.min.js" integrity="sha512-UOoJElONeUNzQbbKQbjldDf9MwOHqxNz49NNJJ1d90yp+X9edsHyJoAs6O4K19CZGaIdjI5ohK+O2y5lBTW6uQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
window.Prism = window.Prism || {};
window.Prism.manual = true;
</script>
</body>