自定义参数不使用Stripe帐户保存,Rails

时间:2016-03-31 21:07:44

标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments

这是我第一次使用API​​,我正在尝试使用Stripe Connect创建一个托管帐户。我创建帐户没有问题,但是我似乎无法从表单中获取要在创建时发送到Stripe的参数。

条纹/ new.html.erb

<%= form_for(@payment) do |f| %>
  <%= f.text_field :first_name %>
  <%= f.text_field :last_name %>
  <%= f.select :country, options_for_select(country_select)%>
  <%= f.text_field :month %>
  <%= f.text_field :day %>
  <%= f.text_field :year %>
  <%= f.submit "create merchant account" %>
<% end %>

stripe_controller.rb

def create
  @artist = current_artist

  Stripe.api_key = Rails.configuration.stripe[:secret_key]
  @account = Stripe::Account.create(
    managed: true,
    country: params[:country],
    email: @artist.email,
    tos_acceptance: {
      ip: request.remote_ip,
      date: Time.now.to_i
    },
    legal_entity: {
      dob: {
        day: params[:day],
        month: params[:month],
        year: params[:year]
      },
      first_name: params[:first_name],
      last_name: params[:last_name],
      type: 'individual',
    }
  )

  if @account.save
    @payment = @artist.create_artist_payment_setting(
        currency: @account.default_currency,
        country: @account.country,
        stripe_id: @account.id,
        stripe_secret_key: @account.keys.secret,
        stripe_publishable_key: @account.keys.publishable
      )
  end

  redirect_to artist_path(@artist)
end

1 个答案:

答案 0 :(得分:1)

params中,所有属性都嵌套在哈希payment

所以尝试像这样访问:

params[:payment][:day]代替params[:day]

params[:payment][:month]代替params[:month]

params[:payment][:year]代替params[:year]

...等等表单的所有其他属性。