2016-02-16 83 views
0

我搜索了一下,找不到我的答案。条纹未定义;请修复或添加/ *全球条纹*/

从CoderManual.com运行我的应用程序时,我遇到了以下错误:

.js文件说"stripe is not defined; please fix or add /*global Stripe*/"

当我通过C9运行应用程序,我得到

"Stripe::InvalidRequestError in Users::RegistrationsController#create"

不知道该怎么做。任何帮助表示赞赏。

.js文件上写着:

$(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; 
    }); 

registrations_controller.rb写着:

class Users::RegistrationsController < Devise::RegistrationsController 

    def create 
    super do |resource| 
     if params[:plan] 
     resource.plan_id = params[:plan] 
     if resource.plan_id == 2 
      resource.save_with_payment 
     else 
      resource.save 
     end 
     end 
    end 
    end 

end 

我装条纹作为表演@ GitHub上无济于事。

我有js.stripe.com在我的HTML中引用:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Dev Match</title> 
    <%= stylesheet_link_tag 'application', media: 'all' %> 
    <%= javascript_include_tag "https://js.stripe.com/v2/", type: 'text/javascript' %> 
    <%= javascript_include_tag 'application' %> 
    <%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %> 
    <%= csrf_meta_tags %> 
</head> 
+0

您是否导入了“条纹”代码? – csmckelvey

+0

这听起来像你不包括

1

最后设法弄清这一个。

错误是因为条带API不返回令牌。在脚本中忽略任何类型的错误处理使得很难看到,更不用说找出原因了。我将条纹API的响应添加到表单中的文本字段中,并将submit(在users.js中)注释掉了。然后,愚蠢的错误就会显现出来。该卡根本没有被视为有效。 codermanual使用4111111 ..作为试用号码,这不再被条带接受。

尝试42424242424242并且生活会很甜美。

+0

这不适合我。我引用了https://stripe.com/docs/testing,并确保我使用了其中一个测试卡号。没有运气。 –