gpt4 book ai didi

ruby-on-rails - 创建客户时 strip 错误 : You passed an empty string for 'card'

转载 作者:太空宇宙 更新时间:2023-11-03 16:59:18 25 4
gpt4 key购买 nike

Stripe 不接受付款,收费一直失败。我收到此错误:

Started POST "/charges" for 127.0.0.1 at 2014-06-09 06:30:58 -0700
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"√", "authenticity_token"=>"9bqk2Q6NEM1ehHDJPgncNQ3gnP0X1hQK6y6ENm3Yb1g=", "c
harge"=>{"contest_id"=>"36", "user_id"=>"", "amount"=>"12", "stripe_card_token"=>""}, "card_number"=
>"4242 4242 4242 4242", "card_code"=>"478", "button"=>""}
Stripe error while creating customer: You passed an empty string for 'card'. We assume empty values
are an attempt to unset a parameter; however 'card' cannot be unset. You should remove 'card' from y
our request or supply a non-empty value
Redirected to http://localhost:3000/
Completed 302 Found in 477ms (ActiveRecord: 0.0ms)

似乎它可能不会创建 strip token ?这是怎么回事?

这是我的表格:

 <% content_for :head do %>
<%= tag :meta, :name => "stripe-key", :content => STRIPE_PUBLIC_KEY %>
<% end %>
<%= form_for @charge, :html => { :class => 'form' } do |f| %>
<div class="form-inputs">
<div class="row">
<%= f.hidden_field :contest_id, value: @contest.id %>
<%= f.hidden_field :user_id %>
<%= f.hidden_field :amount %>
<!-- TODO CHANGE THIS ACCORDINGLY -->
<%= f.hidden_field :stripe_card_token %>
<div class="small-12 medium-6 large-2 columns">
<%= f.label "Amount:", class: "text-right" %>
</div>
<div class="small-12 medium-6 large-10 columns" style="margin-bottom: 0.5rem; margin-top: 0.5rem;">
<%= number_to_currency(@charge.amount, :unit => "$") %>
</div>
<% if @charge.stripe_card_token.present? %>
Credit card has been provided.
<% else %>
<div class="small-12 medium-6 large-2 columns">
<%= label_tag :card_number, "Credit Card Number:", class: "text-right" %>
</div>
<div class="small-12 medium-6 large-10 columns">
<%= text_field_tag :card_number %>
</div>
<div class="small-12 medium-6 large-2 columns">
<%= label_tag :card_code, "Security Code on Card (CVV):", class: "text-right" %>
</div>
<div class="small-12 medium-6 large-10 columns end">
<%= text_field_tag :card_code %>
</div>
<div class="small-12 medium-6 large-2 columns">
<%= label_tag :card_month, "Card Expiration:", class: "text-right" %>
</div>
<div class="small-6 medium-3 columns">
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
</div>
<div class="small-6 medium-3 columns">
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
</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>
<div class="row">
<div class="form-actions small-9 small-offset-2 columns">
<%= button_tag :type => "button", :class => "radius" do %>
<%= link_to "Back", @contest, :style => "color: white" %>
<% end %>
<%= f.button :Donate, :class => "radius" %>
</div>
</div>
</div>
<% end %>
<% content_for :js do %>
<%= javascript_include_tag "https://js.stripe.com/v1", "application" %>
<%= javascript_include_tag asset_path("stripe/stripe.js"), "application" %>
<% end %>

这是我的收费 Controller :

class ChargesController < ApplicationController

def new
@contest = Contest.find(params[:id])
@charge = Charge.new(amount: params[:amount])
end

def create
@charge = Charge.new(charges_params)
if @charge.save_with_payment(@charge)
redirect_to root_path, :notice => "Contribution was recorded succesfully!"
else
redirect_to root_path, :notice => "Transaction was not able to be recorded"
end
end

def charges_params
params.require(:charge).permit(:stripe_card_token, :contest_id, :user_id, :amount)
end

end

我的收费模型:

class Charge < ActiveRecord::Base

attr_accessor :stripe_card_token

belongs_to :contest
belongs_to :user

def save_with_payment(charge)
if valid?
Stripe::Charge.create(
:amount => (charge.amount.to_i)*100,
:currency => "usd",
:card => stripe_card_token);
save
end
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating customer: #{e.message}"
errors.add :base, "There was a problem with your credit card."
false
end

end

最佳答案

很可能看起来 stripe_card_token 是空白的

:card => stripe_card_token

试着把它改成

:card => charge.stripe_card_token

关于ruby-on-rails - 创建客户时 strip 错误 : You passed an empty string for 'card' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24121656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com