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>
您是否導入了「條紋」代碼? – csmckelvey
這聽起來像你不包括
最後設法弄清這一個。
錯誤是因爲條帶API不返回令牌。在腳本中忽略任何類型的錯誤處理使得很難看到,更不用說找出原因了。我將條紋API的響應添加到表單中的文本字段中,並將submit(在users.js中)註釋掉了。然後,愚蠢的錯誤就會顯現出來。該卡根本沒有被視爲有效。 codermanual使用4111111 ..作爲試用號碼,這不再被條帶接受。
嘗試42424242424242並且生活會很甜美。
來源
2016-02-19 08:36:12 MrRipley
這不適合我。我引用了https://stripe.com/docs/testing,並確保我使用了其中一個測試卡號。沒有運氣。 –