我已经在此railscast教程http://railscasts.com/episodes/288-billing-with-stripe之后成功地将条带信用卡处理(Stripe api v2)应用到我的rails应用程序中。在设置表单样式后,我开始收到以下错误:
您的信用卡出现问题。无效的源对象:必须是字典或非空字符串。请参阅https://stripe.com/docs'
上的API文档在我的控制台中,我可以看到stripe_card_token被提交为任何空值
Parameters: {"utf8"=>"✓", "authenticity_token"=>"zCP+nFHj3JC0ZyceWOf9D+Vx6wZRfKA0LmZqL7faGzaM1E/k7GgKHCygCktH6mqe3oFNG1tqRpJpjKB728KE0g==", "subscription"=>{"stripe_card_token"=>"", "email"=>"test@outlook.com"}, "commit"=>"Create
我以前遇到过这个错误,并通过从application.js中删除require_tree解决了这个错误,但错误仍然重现
我还尝试禁用某些其他线程中建议的turbolink。
这是我的提交表格:
<div ng-app="app" class="creditcontainer">
<div ng-controller="PaymentFormCtrl" class="payment-form" name="paymentForm">
<div class="notification">
<span class="notification__text">
We use secure 256 bit encryption and PCI compliant credit card processing, you data is save with us.
</span>
</div>
<center><h2>12$/month</h2></center>
<div class="card-type clearfix">
<div class="card-type__label">
Supported Cards
</div>
<div class="card-type__icons">
</div><br>
</div>
<%= form_for(@subscription) do |f| %>
<% if @subscription.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@subscription.errors.count, "error") %> prohibited this subscription from being saved:</h2>
<ul>
<% @subscription.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :stripe_card_token %>
<% if @subscription.stripe_card_token.present? %>
Credit card has been provided.
<% else %>
<div>
<%= f.text_field :email, class: "email-input card-input--full",placeholder: "Email" %>
</div>
<div>
<%= text_field_tag :card_number, nil, name: nil, class: "card-input card-input--full",placeholder: "Credit card number", :ng => { :model => "card.number" } %>
</div>
<div class="card-info clearfix">
<div class = "card-input--alldate" ng-model="card.date" card-date required >
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month", class: "card-input--monthdatedrop"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year", class: "card-input--yeardatedrop"} %>
</div>
<div ng-model="card.cvv" card-cvv required>
<%= text_field_tag :card_code, nil, name: nil, class: "card-input card-input--cvv", placeholder: "CVV" %>
</div>
<% end %>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<div ng-disabled="paymentForm.$invalid">
<%= f.submit class: "payment-form__button" %>
</div>
<div class="payment-form__agreement">
We directly pass your data on to our payment processor and never store your credit card details. All our connections are encrypted to the highest standards. Your credit card information is safe with us. Upon paying your agree to our TOS.
</div>
</div>
</div>
<% end %>
这是我的subscription.coffee文件,用于处理处理:
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()
subscription =
setupForm: ->
$('#new_subscription').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
{number: $('#card_number').val(),
cvc: $('#card_code').val(),
expMonth: $('#card_month').val(),
expYear: $('#card_year').val()}
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#subscription_stripe_card_token').val(response.id)
$('#new_subscription')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
任何人都知道为什么stripe_card_token为空?
更新
似乎不知何时subscriptions.coffee文件似乎没有自动加载(因为删除了application.js中的require_tree。行)。当我强制加载时,我收到错误
SyntaxError:[stdin]:26:46:意外的换行符
在application.html.erb中,但对于样式表标记很奇怪:
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
将文件更改为.js文件没有带来任何变化。我监管的subscription.coffee文件中是否有错误?
答案 0 :(得分:0)
如果订阅从df1 = df_so.set_index('Title')
df2 = df1.eq('P').dot(df1.columns + ',').str.rstrip(',').reset_index(name='new')
print (df2)
Title new
0 A Name1,Name4
1 B Name2
2 C Name2,Name3,Name4
3 D Name1,Name4
更新为Trial
,则需要先创建客户付款来源
Paid
然后更新“条带订阅”
def update_subscription(params = {})
if subscription.trial?
stripe_customer = Stripe::Customer.retrieve(stripe_customer_token)
stripe_card_token = params['subscription']['stripe_card_token']
stripe_customer.sources.create(source: stripe_card_token)
end
end