-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
361 lines (351 loc) · 15.7 KB
/
index.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!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-2.0.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.4.1.slim.min.js"
integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" 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 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 ApplePay or GooglePay button.
Please note that for ApplePay this library only works with a Datatrans merchantId which has been enabled for
ApplePay 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 E-mail
</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>
</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 wich contains Datatrans specific
values, which currently are "currencyCode" and "refno".
<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',
},
};</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-2.0.0.js" type="text/javascript"></script></code></pre>
<pre><code class="language-javascript">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>
Following events will be emmited 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>Options and parameters</h4>
<table class="table">
<thead><tr>
<th>Option</th>
<th colspan="2">Description</th>
<th style="white-space: nowrap;">Data type</th>
</tr></thead>
<tbody>
<tr>
<th>merchantId</th>
<td colspan="2">Your datatrans merchantId</td>
<td>String</td>
</tr>
<tr>
<th>merchantName</th>
<td colspan="2">Your merchant name</td>
<td>String</td>
</tr>
<tr>
<th>useGooglePay</th>
<td colspan="2">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 colspan="2">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>autoSettle</th>
<td colspan="2">Wether the transaction will be settled automatically. Default is false.</td>
<td>boolean</td>
</tr>
<tr>
<th>allowedCardNetworks</th>
<td colspan="2">Which cardnetworks to accept</td>
<td style="white-space: nowrap;">String array</td>
</tr>
<tr>
<th rowspan="4">googlePayConfiguration</th>
<th>Option</th>
<th>Description</th>
<th>Type</th>
</tr>
<tr>
<th>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>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>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 rowspan="3">applePayConfiguration</th>
<th>Option</th>
<th>Description</th>
<th>Type</th>
</tr>
<tr>
<th>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>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>
<tr>
<th rowspan="5">Payment Request - transaction</th>
<th>Option</th>
<th>Description</th>
<th>Type</th>
</tr>
<tr>
<th>refno</th>
<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>createAlias</th>
<td>Whether to create an alias. 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>
</td>
<td>boolean</td>
</tr>
<tr>
<th>authenticationOnly</th>
<td>Only authenticate the transaction (used for deferred authorization)
</td>
<td>boolean</td>
</tr>
<tr>
<th>countryCode</th>
<td>ISO 3166-1 alpha-2 country code where the transaction is processed. This is required for merchants
based in European Economic Area (EEA) countries. <b>Mandatory </b> for payment-button-v2 library.
</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>