-
Notifications
You must be signed in to change notification settings - Fork 5
/
stripe_easy_inputs.js
58 lines (54 loc) · 1.47 KB
/
stripe_easy_inputs.js
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
var validInput = function(e, bool){
if(bool){
$(e.target).closest(".form-group").removeClass("has-error");
} else {
$(e.target).closest(".form-group").addClass("has-error");
}
};
Template.stripeEasyInputs.events({
'blur [name="number"]':function (e) {
var val = $(e.target).val();
var valid = Stripe.card.validateCardNumber(val);
validInput(e, valid);
},
'blur [name="expire"]': function(e){
var val = $(e.target).val().split("/");
if(val[1] && val[1].length === 2){
val[1] = "20" + val[1];
}
var valid = Stripe.card.validateExpiry(val[0], val[1]);
validInput(e, valid);
},
'keyup [name="cvc"]': function(e){
var val = $(e.target).val();
var valid = Stripe.card.validateCVC(val);
validInput(e, valid);
}
});
Template.stripeEasyInputs.helpers({
inputClasses: function () {
return StripeEasy.configurable.inputClasses;
},
errorClasses: function () {
return StripeEasy.configurable.errorClasses;
},
stripeEasyErrors: function () {
var error = Session.get('stripeEasyError');
if(error.reason){
return error.reason;
} else if(error.message){
return error.message;
} else if(error) {
return 'Something went wrong. Please double check your inputs';
}
},
hasError: function () {
var error = Session.get('stripeEasyError');
if(error){
return true;
}
},
});
Template.stripeEasyInputs.destroyed = function () {
Session.set('stripeEasyError', null);
};