【问题标题】:Custom params not saving with Stripe account, Rails自定义参数不使用 Stripe 帐户保存,Rails
【发布时间】:2016-07-20 12:29:22
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

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

    所以尝试像这样访问:

    params[:payment][:day] 而不是params[:day]

    params[:payment][:month] 而不是params[:month]

    params[:payment][:year] 而不是params[:year]

    ...对于表单的所有其他属性,依此类推。

    【讨论】:

      猜你喜欢
      • 2021-04-25
      • 2014-11-15
      • 1970-01-01
      • 2021-07-02
      • 2021-01-30
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2021-06-28
      相关资源
      最近更新 更多