-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtrial-page1.html
351 lines (299 loc) · 14.1 KB
/
trial-page1.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>(Page 1) 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.
var nextPage = "trial-page2.html";
var myItemId = 'Baseball'; // a baseball. what are you selling?
var country = 'US'; // we're hard coding the country since this is usually a US only cart.
var shippingMethod = 'USPS: Priority Mail'; // set the shipping method on the first page so the total is complete on the next page.
var shippingCost = 5.99; // the shipping cost is calculated during the final processing, but you may set it to whatever you like here for display purposes.
// almost all trial checkouts have a set shipping price, so this works well. for normal checkouts, we would
// query the shipping estimates and use the prices returned back from the server. That's not needed here. This is fast.
// don't worry about someone changing this. The final value is calculated server side.
</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="build/bundle.js"></script>
<script type="text/javascript">
function clientSideValidate() {
var errors = [];
var shipping = uc.cart.shipping || new uc.sdk.CartShipping();
var billing = uc.cart.billing || new uc.sdk.CartBilling();
if (!shipping.first_name) {
errors.push('Please provide your First Name');
}
if (!shipping.last_name) {
errors.push('Please provide your Last Name');
}
if (!billing.email) {
errors.push('Please provide your email');
}
if (!shipping.day_phone) {
errors.push('Please provide your Day Phone');
}
if (!shipping.address1) {
errors.push('Please provide your Address');
}
if (!shipping.postal_code) {
errors.push('Please provide your Zip Code');
}
if (!shipping.city) {
errors.push('Please provide your City');
}
if (!shipping.state_region) {
errors.push('Please select your State');
}
if (errors.length) {
uc.displayCheckoutErrors(errors);
return false;
} else {
return true;
}
}
function cartToFields(cart) {
if (!cart.shipping) {
cart.shipping = new uc.sdk.CartShipping();
}
var shipping = cart.shipping;
if (!cart.billing) {
cart.billing = new uc.sdk.CartBilling();
}
var billing = cart.billing;
jQuery('#firstName').val(shipping.first_name || '');
jQuery('#lastName').val(shipping.last_name || '');
jQuery('#email').val(billing.email || '');
jQuery('#phone').val(shipping.day_phone || '');
jQuery('#address1').val(shipping.address1 || '');
jQuery('#address2').val(shipping.address2 || '');
jQuery('#postalCode').val(shipping.postal_code || '');
jQuery('#city').val(shipping.city || '');
jQuery('#state').val(shipping.state_region || '');
}
function fieldsToCart(cart) {
if (!cart.shipping) {
cart.shipping = new uc.sdk.CartShipping();
}
var shipping = cart.shipping;
if (!cart.billing) {
cart.billing = new uc.sdk.CartBilling();
}
var billing = cart.billing;
shipping.first_name = billing.first_name = jQuery.trim(jQuery('#firstName').val());
shipping.last_name = billing.last_name = jQuery.trim(jQuery('#lastName').val());
billing.email_confirm = billing.email = jQuery.trim(jQuery('#email').val());
shipping.day_phone = billing.day_phone = billing.evening_phone = shipping.evening_phone = jQuery.trim(jQuery('#phone').val());
shipping.address1 = billing.address1 = jQuery.trim(jQuery('#address1').val());
shipping.address2 = billing.address2 = jQuery.trim(jQuery('#address2').val());
shipping.postal_code = billing.postal_code = jQuery.trim(jQuery('#postalCode').val());
shipping.city = billing.city = jQuery.trim(jQuery('#city').val());
shipping.state_region = billing.state_region = jQuery.trim(jQuery('#state').val());
shipping.country_code = billing.country_code = country;
return cart;
}
function saveFieldsAndContinue() {
uc.clearCheckoutErrors();
if (!uc.cart) {
uc.cart = new uc.sdk.Cart();
}
uc.cart = fieldsToCart(uc.cart);
uc.cart.shipping.shipping_method = shippingMethod;
if (!uc.cart.summary) {
uc.cart.summary = new uc.sdk.CartSummary();
}
if (!uc.cart.summary.shipping_handling) {
uc.cart.summary.shipping_handling = new uc.sdk.Currency();
}
uc.cart.summary.shipping_handling.value = shippingCost;
// this will overwrite any items in the cart, so if the customer
// backs into this page, they won't receive duplicate items in the cart.
uc.cart.items = [
{item_id: myItemId, quantity: 1}
];
var button = jQuery('#orderButton');
if (clientSideValidate()) {
// 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);
if (error) {
if (response && response.text) {
uc.displayServerErrors(response.text);
} else {
console.error(error);
}
} else {
if (data.errors) {
uc.displayCheckoutErrors(data.errors);
} else {
location.href = nextPage;
}
}
};
uc.checkoutApi.updateCart(uc.cart, {expand: uc.expansion}, callback);
}
}
function cityState() {
var postalCodeField = jQuery('#postalCode');
if (!postalCodeField) {
return;
}
var postalCode = postalCodeField.val();
if (uc.cart) {
var shipping = uc.cart.shipping;
if (!shipping) {
shipping = uc.cart.shipping = new uc.sdk.CartShipping();
}
uc.cart.shipping.postal_code = postalCode;
var callback = function (error, data /*, response*/) {
// do not worry about checking for errors. this call either works or fails silently.
// data is a CityStateZip object
if (data && data.validZip) {
shipping.city = data.city;
shipping.state_region = data.state;
jQuery('#city').val(shipping.city);
jQuery('#state').val(shipping.state_region);
}
};
uc.checkoutApi.cityState(uc.cart, callback);
}
}
jQuery(document).ready(function () {
jQuery('#postalCode').on('blur', cityState);
jQuery('#orderButton').on('click', saveFieldsAndContinue);
uc.loadCart(cartToFields);
});
</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>
</div>
<div class='form-panel'>
<div class='form-header'>
<h4>Tell us where to send your package</h4>
</div>
<div class='form-row'>
<span class='label-span'><label for="firstName">First Name:</label></span>
<span class='field-span'><input class='form-field' id="firstName" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="lastName">Last Name:</label></span>
<span class='field-span'><input class='form-field' id="lastName" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="email">Email:</label></span>
<span class='field-span'><input class='form-field' id="email" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="phone">Phone:</label></span>
<span class='field-span'><input class='form-field' id="phone" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="address1">Address 1:</label></span>
<span class='field-span'><input class='form-field' id="address1" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="address2">Address 2:</label></span>
<span class='field-span'><input class='form-field' id="address2" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="postalCode">Zip:</label></span>
<span class='field-span'><input class='form-field' id="postalCode" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="city">City:</label></span>
<span class='field-span'><input class='form-field' id="city" maxlength="30"/></span>
</div>
<div class='form-row'>
<span class='label-span'><label for="state">State:</label></span>
<span class='field-span'>
<select class='form-field' id="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="PR">Puerto Rico</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</span>
</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">Order Now</button>
</div>
<div class='trust-seals'>
<em>Security and Trust Seals here</em>
</div>
</div>
</div>
</body>
</html>