-
Notifications
You must be signed in to change notification settings - Fork 0
/
donate.html
694 lines (642 loc) · 30.8 KB
/
donate.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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Donate to Impact</title>
<meta name="description" content="Donate to support Impact Development" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js"></script>
<script type="text/javascript" src="min/modernizr-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.2/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/api.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
<script src="https://www.google.com/recaptcha/api.js" async></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-143397381-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-143397381-1');
var getOutboundLink = function(label) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': label,
'transport_type': 'beacon'
});
}
</script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" type="text/css" href="min/style-min.css" />
<style>
.fineprint {
font-family: serif;
font-size: 0.9em;
background: transparent;
}
.error {
color: #F44336;
padding-left: 8px;
}
/* Initial page load animation */
.fade-in {
opacity: 1;
-webkit-transition: opacity .33s ease;
transition: opacity .33s ease;
}
.invisible {
opacity: 0!important;
}
/* Hide the browser's up/down buttons on <input type=number> */
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] {
-moz-appearance: textfield;
}
</style>
</head>
<body>
<header>
<div class="navbar-fixed">
<nav role="navigation">
<div class="nav-wrapper container">
<a href="index.html" class="brand-logo"><h1>Impact</h1></a>
</div>
</nav>
</div>
</header>
<div id="initial-load" class="invisible fade-in">
<div class="container">
<div class="row">
<h4 class="col s12">
Donations of any size are greatly appreciated!
</h4>
<p class="col s12">
If you donate <i><span class="required-amount"></span> or more</i>, you can register an Impact Account. This enables you to receive certain perks, including
access to <i>nightly builds</i> and <i>in-game perks</i>.
</p>
<p class="col s12">
Please note: <b>nightly builds are not currently available</b>. Check out our list of <a href="alternatives.html">alternative clients</a> if you need support for a newer version.
</p>
<p class="col s12">
If you already have an Impact Account you can <a href="account.html">login here</a>.
<br />
If you'd like to donate again, you should probably <a href="donate.html#" onclick="if (api.isLoggedIn()) {api.logout(); alert('Logged out successfully')} else {alert('You are already logged out')} return false;">logout</a> first.
<br />
If you already have an Impact registration token, you can use it to <a href="register.html">register here</a>.
</p>
<p class="col s12 beta-warning">
This donation form is still relatively new, so feedback is appreciated! Please report any issues you find to
<a target="_blank" href="https://github.com/ImpactDevelopment/ImpactServer/issues">this bug tracker</a>.
<br />
Please avoid including any private information (including payment IDs, emails, etc) when reporting issues on the bug tracker.
</p>
</div>
</div>
<form id="amount-form" class="container">
<div class="row">
<div class="input-field col s3 m2">
<select name="currency" id="currency" required tabindex="0">
<option value="" disabled selected>Choose...</option>
</select>
<label for="currency">Currency</label>
<span class="helper-text" data-error="Invalid currency" data-success="">The currency to use</span>
</div>
<div class="input-field col s9 m3 l2">
<label for="amount" class="active">Amount</label>
<input id="amount" name="amount" type="number" data-type="currency" min="0.5" tabindex="1" required autofocus />
<span class="helper-text" data-error="Invalid amount" data-success="">The amount to donate</span>
</div>
<div class="input-field col s12 m5 l6">
<label for="email">Email</label>
<input type="email" id="email" name="email" required tabindex="2" />
<span class="helper-text" data-error="Invalid Email" data-success="">An email to send your receipt to</span>
</div>
<div class="input-field col s12 g-recaptcha" data-sitekey="6Lf19NcUAAAAADBY-60OxWuSMgr4XMH3aq1BZYRs"></div>
<div class="input-field col s12 m2">
<button type="submit" form="amount-form" class="btn waves-effect waves-light" disabled tabindex="3">
Next
</button>
<div class="preloader-wrapper small active hidden">
<div class="spinner-layer spinner-blue-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>
<p id="amount-error" class="input-field col s12 error" role="alert"></p>
</div>
</form>
<form id="payment-form" class="container hidden">
<div class="row">
<div class="input-field col s12 info">
<h4>Your donation of <span class="amount"></span> will be greatly appreciated!</h4>
<p class="hidden show-if-premium">As your donation is <span class="required-amount"></span> or more, you will be able to create an Impact Account to receive perks!</p>
<p class="hidden show-if-not-premium">If you wish to register an Impact Account to receive perks, please donate <span class="required-amount"></span> or more.</p>
<p>An email will be sent to <span class="email"></span> with confirmation of your payment.</p>
<p><a href="donate.html#" id="back-button">Click here to amend any of these details.</a></p>
</div>
<div id="payment-request-button" class="input-field col s12"></div>
<div id="card-element" class="input-field col s12 m10"></div>
<div class="input-field col s12 m2 center">
<button type="submit" form="payment-form" disabled class="btn waves-effect waves-light">
Donate
</button>
<div class="preloader-wrapper small active hidden">
<div class="spinner-layer spinner-blue-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>
<p id="card-error" class="input-field col s12 error" role="alert"></p>
</div>
</form>
<div class="container result-message hidden">
<div class="row">
<h4 class="col s12">Thank you for donating <span class="amount"></span> to Impact</h4>
<div class="col s12">
<p>Your payment ID is: <code id="payment-id"></code></p>
<div class="preloader-wrapper small active hidden">
<div class="spinner-layer spinner-blue-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="gap-patch">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<div class="premium-success">
<p>Your Impact Account registration token is: <code id="token"></code>.</p>
<p>
<strong>Register an Impact Account to receive your rewards</strong><br />
<a href="register.html" id="register">Click here to register</a>, or if you prefer you can gift your token to a friend.
</p>
</div>
<p class="small-success" role="alert">
Although your donation does not qualify for a premium Impact Account, we greatly appreciate any and all donations. Thanks for your support!
</p>
<p class="error" role="alert"></p>
</div>
</div>
</div>
<footer class="container fineprint">
<div class="row">
<p class="col s12">
Please note this is not a purchase. Any rewards we offer in return for your donation are at our sole discretion and can be revoked or changed at any time.
All rewards require you to setup an Impact Account. If your donation qualifies*, you will be able to register an Impact Account after donating.
In-game rewards (including <i>access to nightly builds</i>) require that you to link a genuine Minecraft Account.
They will only be available while you are logged into that specific Minecraft account.
Access to Discord related rewards require that you to link your Discord account and that you join our <a target="_blank" href="discord.html">Discord server</a>.
<br>
*All donations of <span class="required-amount-list"></span> (or more) currently qualify for an Impact Account.
</p>
</div>
</footer>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script type="text/javascript">
// Setup jQuery validation for compatibility with materializecss
$.validator.setDefaults({
errorClass: 'invalid',
validClass: "valid",
errorPlacement: function(error, element) {
$(element)
.parent()
.find('.helper-text')
.attr('data-error', error.text());
},
// By default, onkeyup uses lazy validation (validates only once some other validation is triggered)
// let's change it to eager validation (validates as soon as typing begins)
onkeyup: function (element, event) {
// Ignore events while the elementValue is empty and also
// events triggered by TAB (event.which=9), or specifically excluded keycodes such as SHIFT, HOME and NUMLOCK
var excludedKeys = [ 16, 17, 18, 20, 35, 36, 37, 38, 39, 40, 45, 144, 225 ]
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return
}
this.element(element);
},
// showErrors is called after validating the form, let's use it to inject our own done event; 'finishedHandler'
showErrors: function(errorMap, errorList) {
this.defaultShowErrors();
// Call our 'finished' event
if (typeof this.settings.finishedHnadler === 'function') {
this.settings.finishedHnadler.call(this, this.currentForm, errorMap, errorList)
}
}
});
// Keep track of the current payment so we know whether or not to create a new one;
// useful when the user goes back and forth between the amount form and the payment form
var currentPayment = null
var currencies = {}
api.stripeInfo()
.then(function (info) {
// We need to access this globally
currencies = info['currencies']
// Populate currency drop-down & a list of currency amounts for use in smallprint
var list = ''
$.each(info['currencies'], function (id, currency) {
// append to <select>
$('#currency').append('<option value="'+id+'">'+currency['display_name']+'</option>')
// append to the smallprint list string
list += list === '' ? '' : ', '
list += currency['symbol'] + currency['premium_amount'] / 100 + ' ' + id.toUpperCase()
})
// Replace last comma with "or"
var i = list.lastIndexOf(', ')
if (i > -1) {
list = list.substring(0, i) + ' or ' + list.substring(i + 1)
}
// TODO autodetect currency
var currencyId = info['default_currency']
var currency = info['currencies'][currencyId]
if (!currencyId || !currency) {
// WTF
console.error('WARNING default currency id or value is invalid', currencyId, currency)
return
}
// Populate dynamic values and update them when a new currency is selected
$('#amount').val(currency['premium_amount'] / 100)
$('.required-amount').text(currency['symbol'] + currency['premium_amount'] / 100)
$('.required-amount-list').text(list)
$('#currency')
.val(currencyId)
.change(function populateInfo() {
// update info whenever the currency is changed
var newId = $(this).val()
var newCurrency = info['currencies'][newId]
if (!newId || !newCurrency) {
// WTF
console.error('WARNING currency id or value is invalid', newId, newCurrency)
return
}
// Make the change
$('.required-amount').text(newCurrency['symbol'] + newCurrency['premium_amount'] / 100)
currencyId = newId
currency = newCurrency
// Update the helper text for too-low amounts
$('#amount').valid()
})
// Initialise stripe
var stripe = Stripe(info['stripe_public_key'], {
apiVersion: info['stripe_api_version'],
});
// Setup validation rules for the amount form
$("#amount-form").validate({
messages: {
currency: {
required: "Please specify the currency to use",
},
amount: {
required: "Please specify the amount to donate",
},
email: {
required: "We need your email address to provide you a receipt",
}
},
normalizer: function(value) {
return $.trim(value)
},
finishedHnadler: function(form, errorMap, errorList){
// After validating the form (or part of it), check to see if the submit button should be disabled or not
// Valid if no errors in list
var valid = errorList.length === 0
// If currentElements doesn't match the full elements list, we should manually check all elements
if (valid && this.elements().length !== this.currentElements.length) {
var that = this
valid = Array.prototype.every.call(this.elements(), function (element) {
return that.check(element)
})
}
// Disable submit button when the form is not valid
$(form).find('button[type=submit]').attr('disabled', !valid)
// We also want to check if amount qualifies for perks and update the data-success helper-text
if (Array.prototype.includes.call(this.currentElements, form['amount'])) {
var amount = this.elementValue(form['amount'])
var baseAmount = Math.floor(amount * 100)
$(form['amount'])
.parent().find('.helper-text')
.attr('data-success', baseAmount < currency['premium_amount'] ? 'Donate ' + currency['symbol'] + currency['premium_amount'] / 100 + ' or more for perks' : 'This amount qualifies for perks!')
}
},
submitHandler: function (form, event) {
// submitHandler is called on submit, if the form is valid
// preventDefault to stop the HTML form from actually submitting
event.preventDefault()
// Process the amount value
// It must be a valid number and be multiplied by 100
var amount = Math.floor(form['amount'].value.trim() * 100)
var email = form['email'].value.trim()
var currency = form['currency'].value.trim()
var captcha = $("#g-recaptcha-response").val()
if (!captcha) {
showError($(form), "Recaptcha is required")
return
}
// Show a spinner while creating payment
loading($(form), true)
// If the currentPayment object is identical to the new updated amount/email values,
// don't bother calling api.createPayment since we don't need a new PaymentIntent
if (currentPayment && !hasPaymentChanged(currentPayment, currency, amount, email)) {
setupPaymentForm(currentPayment)
return
}
api.createPayment(currency, amount, email, captcha)
.then(function (payment) {
return currentPayment = payment
})
.then(setupPaymentForm)
.catch(function (error) {
currentPayment = null
loading($(form), false)
showError($(form), error)
})
}
});
// Initialise materialize forms
if (window.M) {
window.M.updateTextFields()
$('select')
.formSelect()// init <select> elements with Materialize
.css({
// Hack to enable validation on <select> element:
// Materialize sets the actual <select> to display:none, however Validation won't
// validate display:none, so set it to visibility:hidden instead...
display: "block",
position: 'absolute',
visibility: 'hidden'
})
.change(function (event) {
// For some reason validation isn't triggered by <select>'s onchange :thinking_face:
$(this).valid()
})
}
var setupPaymentForm = function (payment) {
var currency = currencies[payment['currency']]
var symbol = '¤'
if (currency && currency.hasOwnProperty('symbol')) {
symbol = currency['symbol']
} else {
console.error('WARNING invalid currency setting up payment form', payment['currency'], currency)
}
// Display some info
$('#payment-form .amount').text(symbol + (Math.floor(payment['amount']) / 100).toFixed(2))
$('#payment-form .email').text(payment['email'])
if (payment['premium'] === true) {
$('#payment-form .show-if-premium').removeClass('hidden')
$('#payment-form .show-if-not-premium').addClass('hidden')
} else {
$('#payment-form .show-if-not-premium').removeClass('hidden')
$('#payment-form .show-if-premium').addClass('hidden')
}
// Stripe stuff
var elements = stripe.elements();
// Setup PaymentRequest button
var paymentRequest = stripe.paymentRequest({
country: 'US',
currency: payment['currency'],
total: {
label: 'Donation',
amount: payment['amount'],
},
requestPayerName: false,
requestPayerEmail: true, // Requesting name, email, or phone will automatically request billing address on Apple Pay which is useful for anti-fraud
requestShipping: false
});
var prButton = elements.create('paymentRequestButton', {
paymentRequest: paymentRequest,
style: {
type: 'donate', // can be 'default', 'book', 'buy' or 'donate'
}
});
// Check the availability of the Payment Request API first.
paymentRequest.canMakePayment().then(function(supported) {
if (supported) {
// Mount the button
// TODO use our own button?
// we'd need to check supported.applePay to know which logo to show
prButton.mount('#payment-request-button');
// Setup submit handler for PaymentRequest
paymentRequest.on('paymentmethod', function(event) {
payWithPaymentRequest(stripe, event, payment['client_secret'])
});
} else {
document.getElementById('payment-request-button').style.display = 'none';
}
});
// Setup card input, with vaguely material styles
var card = elements.create("card", {
iconStyle: 'solid',
style: {
base: {
iconColor: '#8898AA',
//color: 'white',
lineHeight: '36px',
fontWeight: 300,
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSize: '19px',
'::placeholder': {
color: '#8898AA',
},
},
invalid: {
iconColor: '#e85746',
color: '#e85746',
}
},
classes: {
focus: 'is-focused',
empty: 'is-empty',
},
});
card.mount("#card-element"); // Stripe injects an iframe into the DOM
card.on("change", function (event) {
// Disable the Pay button if there are no card details in the Element
$('#payment-form button[type=submit]').attr('disabled', event.empty)
$("#card-error").text(event.error ? event.error.message : "")
});
// Setup submit handler
$("#payment-form")
.off('submit') // Remove any other handlers - prevent duplicate handlers when re-initialising form
.on('submit', function(event) {
event.preventDefault();
// Complete payment when the submit button is clicked
payWithCard(stripe, card, payment['client_secret']);
});
// Hide the amount form and show the payment form
$('#amount-form').addClass('hidden')
$('#payment-form').removeClass('hidden')
loading($('#amount-form'), false)
}
// Calls stripe.confirmCardPayment
// If the card requires authentication Stripe shows a pop-up modal to
// prompt the user to enter authentication details without leaving your page.
var payWithPaymentRequest = function(stripe, event, clientSecret) {
// Confirm the PaymentIntent without handling potential next actions (yet).
stripe.confirmCardPayment(
clientSecret,
{
payment_method: event.paymentMethod.id
},
{
handleActions: false
}
).then(function(confirmResult) {
if (confirmResult.error) {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
event.complete('fail');
} else {
// Report to the browser that the confirmation was successful, prompting
// it to close the browser payment method collection interface.
event.complete('success');
// Check if the PaymentIntent requires any actions and if so let Stripe.js
// handle the flow. If using an API version older than "2019-02-11" instead
// instead check for: `paymentIntent.status === "requires_source_action"`.
if (confirmResult.paymentIntent.status === "requires_action") {
// Let Stripe.js handle the rest of the payment flow.
stripe.confirmCardPayment(clientSecret).then(function(newConfirmResult) {
if (newConfirmResult.error) {
// The payment failed -- TODO ask user for a new payment method?
showError($('#payment-form'), newConfirmResult.error.message);
} else {
// The payment has succeeded.
orderComplete(newConfirmResult.paymentIntent)
}
});
} else {
// The payment has succeeded.
orderComplete(confirmResult.paymentIntent)
}
}
});
};
// Calls stripe.confirmCardPayment
// If the card requires authentication Stripe shows a pop-up modal to
// prompt the user to enter authentication details without leaving your page.
var payWithCard = function(stripe, card, clientSecret) {
loading($('#payment-form'), true);
stripe.confirmCardPayment(
clientSecret,
{
payment_method: {
card: card
}
}
).then(function(confirmResult) {
if (confirmResult.error) {
// Show error to your customer
showError($('#payment-form'), confirmResult.error.message);
} else {
// The payment succeeded!
orderComplete(confirmResult.paymentIntent);
}
});
};
$('#initial-load').removeClass('invisible')
})
.catch(function (error) {
$('#initial-load').text(error).addClass('error').removeClass('invisible')
})
$('#back-button').click(function (event) {
event.preventDefault()
// Just show the amount form without resetting any state
// We will rely on the "next" button to handle any changes to state
var paymentf = $('#payment-form')
var amountf = $('#amount-form')
loading(paymentf, false)
loading(amountf, false)
paymentf.addClass('hidden')
amountf.removeClass('hidden')
amountf.find('#amount').focus()
})
// Check if the given payment matches the given amount and email
// TODO if we ever add more currencies, we should check that too
var hasPaymentChanged = function (payment, currency, amount, email) {
return !(payment.amount === amount && payment.email === email && payment.currency === currency);
}
// Shows a success message when the payment is complete
var orderComplete = function(paymentIntent) {
loading($('#payment-form'), false)
loading($('.result-message'), false)
$("button[type=submit]").attr('disabled', true)
$('#payment-form').addClass('hidden')
$('.result-message .small-success').addClass('hidden')
$('.result-message .premium-success').addClass('hidden')
$('.result-message .error').addClass('hidden')
$('#payment-id').text(paymentIntent['id'])
var currency = currencies[paymentIntent['currency']]
$('.result-message .amount').text(currency['symbol'] + (Math.floor(paymentIntent['amount']) / 100))
$('.result-message').removeClass('hidden')
// If the payment was premium, ask for a token
if (currentPayment && currentPayment['premium'] === true) {
loading($('.result-message'), true)
api.redeemPayment(paymentIntent['id'], currentPayment['email'])
.then(function (token) {
$('#token').text(token)
$('#register').attr('href', '/register?token='+encodeURIComponent(token))
loading($('.result-message'), false)
$('.result-message .small-success').addClass('hidden')
$('.result-message .premium-success').removeClass('hidden')
$('.result-message .error').addClass('hidden')
})
.catch(function (error) {
// TODO handle some errors gracefully?
loading($('.result-message'), false)
$('.result-message .small-success').addClass('hidden')
$('.result-message .premium-success').addClass('hidden')
$('.result-message .error')
.removeClass('hidden')
.text(error)
})
} else {
// If the payment wasn't premium, just say thanks
$('.result-message .small-success').removeClass('hidden')
$('.result-message .premium-success').addClass('hidden')
$('.result-message .error').addClass('hidden')
}
};
// Show the customer the error from Stripe if their card fails to charge
var showError = function(parent, errorMsgText) {
loading(parent, false);
var err = parent.find('.error')
err.text(errorMsgText)
};
// Show a spinner on form submission
// Expects a jQuery object and a boolean
var loading = function(form, isLoading) {
if (isLoading) {
// Disable the button and show a spinner
form.find("button[type=submit]").attr('disabled', true).addClass('hidden');
form.find(".preloader-wrapper").removeClass("hidden");
} else {
form.find("button[type=submit]").attr('disabled', false).removeClass('hidden');
form.find(".preloader-wrapper").addClass("hidden");
}
};
</script>
</body>
</html>