[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 /** 2 * @provides javelin-behavior-stripe-payment-form 3 * @requires javelin-behavior 4 * javelin-dom 5 * phortune-credit-card-form 6 */ 7 8 JX.behavior('stripe-payment-form', function(config) { 9 Stripe.setPublishableKey(config.stripePublishableKey); 10 11 var ccform = new JX.PhortuneCreditCardForm(JX.$(config.formID), onsubmit); 12 13 function onsubmit(card_data) { 14 var errors = []; 15 16 if (!Stripe.validateCardNumber(card_data.number)) { 17 errors.push('cc:invalid:number'); 18 } 19 20 if (!Stripe.validateCVC(card_data.cvc)) { 21 errors.push('cc:invalid:cvc'); 22 } 23 24 if (!Stripe.validateExpiry(card_data.month, card_data.year)) { 25 errors.push('cc:invalid:expiry'); 26 } 27 28 if (errors.length) { 29 ccform.submitForm(errors); 30 return; 31 } 32 33 var data = { 34 number: card_data.number, 35 cvc: card_data.cvc, 36 exp_month: card_data.month, 37 exp_year: card_data.year 38 }; 39 40 Stripe.createToken(data, onresponse); 41 } 42 43 function onresponse(status, response) { 44 var errors = []; 45 var token = null; 46 if (status != 200) { 47 errors.push('cc:stripe:http:' + status); 48 } else if (response.error) { 49 errors.push('cc:stripe:error:' + response.error.type); 50 } else { 51 token = response.id; 52 } 53 54 ccform.submitForm(errors, {stripeCardToken: token}); 55 } 56 57 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |