2016-05-05 29 views
0

Stripe.js 試圖在項目中實現條紋,我不斷收到此錯誤 任何想法我該怎麼辦?STRIPE.JS錯誤

條紋沒有定義修補程序或添加/全局$/

-----> 「stripe_card_token」=> 「未定義」}} < ------

$(document).ready(function() { 
    Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content')); 
    // Watch for a form submission: 
    $("#form-submit-btn").click(function(event) { 
    event.preventDefault(); 
    $('input[type=submit]').prop('disabled', true); 
    var error = false; 
    var ccNum = $('#card_number').val(), 
     cvcNum = $('#card_code').val(), 
     expMonth = $('#card_month').val(), 
     expYear = $('#card_year').val(); 

    if (!error) { 
     // Get the Stripe token: 
     Stripe.createToken({ 
     number: ccNum, 
     cvc: cvcNum, 
     exp_month: expMonth, 
     exp_year: expYear 
     }, stripeResponseHandler); 
    } 
    return false; 
    }); // form submission 

    function stripeResponseHandler(status, response) { 
    // Get a reference to the form: 
    var f = $("#new_user"); 

    // Get the token from the response: 
    var token = response.id; 

    // Add the token to the form: 
    f.append('<input type="hidden" name="user[stripe_card_token]" value="' + token + '" />'); 

    // Submit the form: 
    f.get(0).submit(); 
    } 
}); 
+1

你是如何包含stripe.js的? 你的代碼在哪裏拋出這個錯誤?哪條線? 你明白了什麼,當你'的console.log(條帶化)' –

回答

1

我認爲你的第一個錯誤來自你正在使用的linter。您可以添加/* global Stripe */作爲第一行(取決於您使用的棉絨)。

+0

已經修復,現在即時得到和錯誤|此客戶沒有附加付款來源| ------ | customer = Stripe :: Customer.create(email:email,plan:plan_id,source:stripe_card_token)| –

+0

你應該CONSOLE.LOG(response.error),看看是否令牌實際創建或者失敗。 – geekonaut