File tree 1 file changed +36
-0
lines changed
saasapp/app/assets/javascripts
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Tell the document jQuery and Stripe are defined somewhere else.
2
+ /* global $, Stripe */
3
+
4
+ // Document ready.
5
+ $ ( document ) . on ( 'turbolinks:load' , function ( ) {
6
+ var theForm = $ ( '#pro_form' ) ;
7
+ var submitBtn = $ ( 'form-submit-btn' ) ;
8
+
9
+ // Set Stripe public key.
10
+ Stripe . setPublishableKey ( $ ( 'meta[name="stripe-key"]' ) . attr ( 'content' ) ) ;
11
+
12
+ // When user clicks form submit btn,
13
+ submitBtn . click ( function ( event ) {
14
+ // prevent default submission behavior.
15
+ event . preventDefault ( ) ;
16
+
17
+ // Collect the credit card fields.
18
+ var ccNum = $ ( '#card_number' ) . val ( ) ,
19
+ cvcNum = $ ( '#card_code' ) . val ( ) ,
20
+ expMonth = $ ( '#card_month' ) . val ( ) ,
21
+ expYear = $ ( '#card_year' ) . val ( ) ;
22
+
23
+ // Send the card info to Stripe.
24
+ Stripe . createToken ( {
25
+ number : ccNum ,
26
+ cvc : cvcNum ,
27
+ exp_month : expMonth ,
28
+ exp_year : expYear
29
+ } , stripeResponseHandler ) ;
30
+ } ) ;
31
+
32
+
33
+ // Stripe will return a card token.
34
+ // Inject card token as hidden field into form.
35
+ // Submit form to our Rails app.
36
+ } ) ;
You can’t perform that action at this time.
0 commit comments