/
trial-page2.html
457 lines (382 loc) · 18.2 KB
/
trial-page2.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>(Page 2) Two Page Trial Checkout</title>
<link rel="stylesheet" href="build/style.min.css">
<!--suppress JSUnusedLocalSymbols -->
<script type="text/javascript">
// these variables are used by main.js
if (!window.uc) {
window.uc = {};
}
// See https://ultracart.atlassian.net/wiki/spaces/ucdoc/pages/419364865/Creating+a+Browser+Key+for+a+JavaScript+checkout
uc.browserKey = "d7f38666b17e60016306f071d41e3700";
uc.cookieName = 'UltraCartShoppingCartID'; // if you don't have a good reason to change this, leave it alone.
uc.storeFront = "demo.ultracartstore.com"; // this should be your StoreFront. It's needed to show the proper look and feel on the receipt.
</script>
<script type="text/javascript" src="scripts/json3.min.js"></script>
<script type="text/javascript" src="scripts/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
<script type="text/javascript" src="https://token.ultracart.com/checkout/checkout-hosted-fields-1.0.js"></script>
<script type="text/javascript" src="build/bundle.js"></script>
<!-- =============================================================================== -->
<!-- BEGIN PCI 3.0 compliance code -->
<!-- What you might need to change: -->
<!-- the selector properties point to the two credit card fields. If you change the -->
<!-- ids of the fields, you need to re-point those selectors at the fields properly. -->
<!-- See also: -->
<!-- http://docs.ultracart.com/display/ucdoc/UltraCart+PCI+Compliance -->
<!-- =============================================================================== -->
<style type="text/css">
/* it is important to set the border of the credit card fields explicitly (especially for google chrome) so
the PCI fields can mimic them correctly when overlaying them. */
select, input {
border: 1px solid rgb(169, 169, 169);
}
</style>
<script type="text/javascript">
var hostedFields = null;
// setup should be called each time the UI updates.
function setupSecureCreditCardFields() {
window.ultraCartHostedFieldsDebugMode = false; // set this to true to see verbose debugging. usually only UltraCart support will use this.
hostedFields = UltraCartHostedFields.setup(jQuery, JSON3, {
'sessionCredentials': {
'merchantId': uc.cart.merchant_id, 'shoppingCartId': uc.cart.cart_id
},
// 'cssUrls':[
// 'https://www.mysite.com/styles.css'
// ],
// 'form': '#myForm',
'hostedFields': {
'creditCardNumber': {
'selector': '#cardNumber'
/* ,'tokenSelector': '#cardNumberToken' */
},
'creditCardCvv2': {
'selector': '#cvv2'
/* ,'tokenSelector': '#cvv2Token' */
}
}
});
}
// teardown should be called each time a UI needs destroying.
function teardownSecureCreditCardFields() {
if (hostedFields !== null) {
hostedFields.destroy();
hostedFields = null;
}
}
</script>
<!-- =============================================================================== -->
<!-- // END PCI 3.0 compliance code -->
<!-- // ========================================================================== -->
<script type="text/javascript">
function clientSideValidate() {
var errors = [];
if (!document.getElementById('certify').checked) {
errors.push("Please agree to terms and conditions.");
}
var payment = new uc.sdk.CartPayment();
if (uc.cart && uc.cart.payment && uc.cart.payment) {
payment = uc.cart.payment;
} else {
uc.cart.payment = payment;
}
var cc = new uc.sdk.CartPaymentCreditCard();
if (payment.credit_card) {
cc = payment.credit_card
} else {
payment.credit_card = cc;
}
if (!cc.card_type) {
errors.push('Please select your card type.');
}
if (!cc.card_number) {
errors.push('Please provide your card number');
}
if (!cc.card_verification_number) {
errors.push('Please provide your cvv2 number');
}
if (!cc.card_expiration_month) {
errors.push('Please select your expiration month');
}
if (!cc.card_expiration_year) {
errors.push('Please select your expiration year');
}
if (errors.length) {
uc.displayCheckoutErrors(errors);
return false;
} else {
return true;
}
}
function cartToFields(cart) {
var payment = null;
if (cart.payment) {
payment = cart.payment;
} else {
payment = cart.payment = new uc.sdk.CartPayment();
}
var cc = null;
if (payment.credit_card) {
cc = payment.credit_card;
} else {
cc = payment.credit_card = new uc.sdk.CartPaymentCreditCard();
}
payment.payment_method = 'Credit Card';
jQuery('#cardNumber').val(cc.card_number || '');
jQuery('#cardType').val(cc.card_type || '');
jQuery('#expirationMonth').val(cc.card_expiration_month);
jQuery('#expirationYear').val(cc.card_expiration_year);
jQuery('#cvv2').val(cc.card_verification_number || '');
}
function fieldsToCart(cart) {
var payment = null;
if (cart.payment) {
payment = cart.payment;
} else {
payment = cart.payment = new uc.sdk.CartPayment();
}
var cc = null;
if (payment.credit_card) {
cc = payment.credit_card;
} else {
cc = payment.credit_card = new uc.sdk.CartPaymentCreditCard();
}
cc.card_number = jQuery.trim(jQuery('#cardNumber').val());
cc.card_type = jQuery.trim(jQuery('#cardType').val());
cc.card_expiration_month = parseInt(jQuery.trim(jQuery('#expirationMonth').val()));
cc.card_expiration_year = parseInt(jQuery.trim(jQuery('#expirationYear').val()));
cc.card_verification_number = jQuery.trim(jQuery('#cvv2').val());
return cart;
}
function displayContents(cart) {
var summary = cart.summary || new uc.sdk.CartSummary();
var discount = 0;
if (summary.subtotal_discount && summary.subtotal_discount.localized) {
discount += summary.subtotal_discount.localized;
}
if (summary.shipping_handling_discount && summary.shipping_handling_discount.localized) {
discount += summary.shipping_handling_discount.localized;
}
var subtotal = summary.subtotal ? (summary.subtotal.localized_formatted || '') : "";
var shippingHandling = summary.shipping_handling ? (summary.shipping_handling.localized_formatted || '') : "";
var total = summary.total ? (summary.total.localized_formatted || '') : "";
jQuery('#subtotal').text(subtotal);
jQuery('#shipping').text(shippingHandling);
jQuery('#discount').text(uc.formatMoney(discount, cart.currency_code));
jQuery('#total').text(total);
if (cart.items && cart.items.length) {
var html = '';
for (var i = 0; i < cart.items.length; i++) {
var item = cart.items[i];
var description = item.description;
if (item.default_thumbnail_url) {
description += "<br><img src='" + item.default_thumbnail_url + "'>";
}
html += '<tr><td class="product">' + description + '</td><td class="summary-description"> </td><td class="price">' + item.unit_cost.localized_formatted + '</td></tr>';
}
jQuery('.cart-contents-table tbody').html(html);
}
jQuery('.cart-contents').removeClass('hidden');
}
function runOnSuccessfulLoadCart() {
teardownSecureCreditCardFields(); // won't do anything the first time called.
cartToFields(uc.cart);
displayContents(uc.cart);
setupSecureCreditCardFields();
}
function saveFieldsAndContinue() {
uc.clearCheckoutErrors();
// this should NOT happen.
if (!uc.cart) {
uc.cart = new uc.sdk.Cart();
}
uc.cart = fieldsToCart(uc.cart);
var button = jQuery('#orderButton');
if (clientSideValidate()) {
var handoffRequest = new uc.sdk.CheckoutHandoffRequest();
handoffRequest.cart = uc.cart;
handoffRequest.error_parameter_name = "error"; // any errors will be returned to this page as this http parameter
handoffRequest.error_return_url = document.URL; // any errors should return to this same page.
handoffRequest.secure_host_name = uc.storeFront; // needed to show the correct branding on the receipt and manage upsells
handoffRequest.operation = 'checkout';
// server side validation. let's be sure.
// if you like, implement a call to /rest/cart/validate.
// use the following checks: "Shipping Address Provided", "Shipping Validate City State Zip"
// see: http://docs.ultracart.com/display/ucdoc/UltraCart+REST+Checkout+API#UltraCartRESTCheckoutAPI-/rest/cart/validate
button.attr('disabled', true);
var callback = function (error, data, response) {
button.attr('disabled', false);
// check for http errors (communication, authorization)
if (error) {
if (response && response.text) {
uc.displayServerErrors(response.text);
} else {
console.error(error);
}
} else if (data && data.redirect_to_url) {
// This is our success condition. A redirect url means that everything validated properly
// and the handoff has taken place.
location.href = data.redirect_to_url;
} else if (data.errors) {
uc.displayCheckoutErrors(data.errors);
}
};
uc.checkoutApi.handoffCart(handoffRequest, {expand: uc.expansion}, callback);
}
}
jQuery(document).ready(function () {
jQuery('#orderButton').on('click', saveFieldsAndContinue);
// check for any errors that might be parameters to this page. They will be there if the checkout had errors
// during the second stage (i.e. credit card declined. The parameter name here is specified in the checkoutRequest object abvoe.
var errors = [];
var searchString = window.location.search.substring(1), params = searchString.split("&");
for (var i = 0; i < params.length; i++) {
var val = params[i].split("=");
if (val[0] === 'error') {
errors.push(decodeURIComponent(val[1]));
}
}
if (errors.length) {
uc.displayCheckoutErrors();
}
uc.loadCart(runOnSuccessfulLoadCart);
});
</script>
</head>
<body id="home">
<div id="content">
<div class='title-bar'>
<h1>Site Title</h1>
<div>
Product description, background image, testimonials fill in the rest of the page.
<div class='cart-contents hidden'>
<table class='cart-contents-table'>
<thead>
<tr>
<th class='product'>Product</th>
<th class='summary-description'> </th>
<th class='price'>Price</th>
</tr>
</thead>
<tfoot>
<tr>
<td class='product'> </td>
<td class='summary-description'>Subtotal:</td>
<td class='price' id="subtotal"></td>
</tr>
<tr>
<td class='product'> </td>
<td class='summary-description'>Shipping:</td>
<td class='price' id="shipping"></td>
</tr>
<tr>
<td class='product'> </td>
<td class='summary-description'>Discount:</td>
<td class='price' id="discount"></td>
</tr>
<tr>
<td class='product'> </td>
<td class='summary-description'>Total:</td>
<td class='price' id="total"></td>
</tr>
</tfoot>
<tbody>
<!-- this will be replaced with cart contents on load. -->
</tbody>
</table>
</div>
</div>
</div>
<div class='form-panel'>
<div class='form-header'>
<h4>Please Add Your Billing Information</h4>
</div>
<table>
<tr>
<td><label for="cardNumber">Card Number:</label></td>
<td><input class='form-field' id="cardNumber" maxlength="30"/></td>
</tr>
<tr>
<td><label for="cardType">Card Type:</label></td>
<td>
<select class='form-field' id="cardType">
<option value="AMEX">AMEX</option>
<option value="Discover">Discover</option>
<option value="MasterCard">MasterCard</option>
<option value="Visa">Visa</option>
</select>
</td>
</tr>
<tr>
<td><label for="expirationMonth">Expiration:</label></td>
<td>
<select id="expirationMonth">
<option value='1'>Jan</option>
<option value='2'>Feb</option>
<option value='3'>Mar</option>
<option value='4'>Apr</option>
<option value='5'>May</option>
<option value='6'>Jun</option>
<option value='7'>Jul</option>
<option value='8'>Aug</option>
<option value='9'>Sep</option>
<option value='10'>Oct</option>
<option value='11'>Nov</option>
<option value='12'>Dec</option>
</select>
<!--suppress HtmlFormInputWithoutLabel -->
<select id="expirationYear">
<option value='2018'>2018</option>
<option value='2019'>2019</option>
<option value='2020'>2020</option>
<option value='2021'>2021</option>
<option value='2022'>2022</option>
<option value='2023'>2023</option>
<option value='2024'>2024</option>
<option value='2025'>2025</option>
<option value='2026'>2026</option>
<option value='2027'>2027</option>
<option value='2028'>2028</option>
<option value='2029'>2029</option>
<option value='2030'>2030</option>
<option value='2031'>2031</option>
<option value='2032'>2032</option>
<option value='2033'>2033</option>
<option value='2034'>2034</option>
<option value='2035'>2035</option>
<option value='2036'>2036</option>
<option value='2037'>2037</option>
<option value='2038'>2038</option>
<option value='2039'>2039</option>
</select>
</td>
</tr>
<tr>
<td><label for="cvv2">CVV2 Number:</label></td>
<td><input id="cvv2" class='cvv-field' maxlength="30"/></td>
</tr>
</table>
<div class='form-row certify-row'>
<input type="checkbox" id="certify" value='true'/> <label for="certify">
I certify that I am 18 years of age or older and agree to the
<!--suppress HtmlUnknownTarget -->
<a href='#add_link_here'>terms and conditions</a>
of this purchase.</label>
</div>
<div id="checkoutError" class="form-row errorContainer" style="display:none">
<p>Checkout Errors</p>
<div class="errorContent"></div>
</div>
<div class='form-button-row'>
<button id="orderButton">Place Order</button>
</div>
<div class='trust-seals'>
<em>Security and Trust Seals here</em>
</div>
</div>
</div>
</body>
</html>