@@ -6,6 +6,10 @@ var PayolaOnestepSubscriptionForm = {
66 } ,
77
88 handleSubmit : function ( form ) {
9+ if ( ! PayolaOnestepSubscriptionForm . validateForm ( form ) ) {
10+ return false ;
11+ }
12+
913 $ ( form ) . find ( ':submit' ) . prop ( 'disabled' , true ) ;
1014 $ ( '.payola-spinner' ) . show ( ) ;
1115 Stripe . card . createToken ( form , function ( status , response ) {
@@ -14,6 +18,29 @@ var PayolaOnestepSubscriptionForm = {
1418 return false ;
1519 } ,
1620
21+ validateForm : function ( form ) {
22+ var cardNumber = $ ( "input[data-stripe='number']" ) . val ( ) ;
23+ if ( ! Stripe . card . validateCardNumber ( cardNumber ) ) {
24+ PayolaOnestepSubscriptionForm . showError ( form , 'The card number is not a valid credit card number.' ) ;
25+ return false ;
26+ }
27+
28+ var expMonth = $ ( "select[data-stripe='exp_month']" ) . val ( ) ;
29+ var expYear = $ ( "select[data-stripe='exp_year']" ) . val ( ) ;
30+ if ( ! Stripe . card . validateExpiry ( expMonth , expYear ) ) {
31+ PayolaOnestepSubscriptionForm . showError ( form , "Your card's expiration month/year is invalid." ) ;
32+ return false ;
33+ }
34+
35+ var cvc = $ ( "input[data-stripe='cvc']" ) . val ( ) ;
36+ if ( ! Stripe . card . validateCVC ( cvc ) ) {
37+ PayolaOnestepSubscriptionForm . showError ( form , "Your card's security code is invalid." ) ;
38+ return false ;
39+ }
40+
41+ return true ;
42+ } ,
43+
1744 stripeResponseHandler : function ( form , status , response ) {
1845 if ( response . error ) {
1946 PayolaOnestepSubscriptionForm . showError ( form , response . error . message ) ;
0 commit comments