Stripe 银行令牌的 Rails 4 表单语法 - [英] Rails 4 Form Syntax for Stripe Bank Token -

查看:26
本文介绍了Stripe 银行令牌的 Rails 4 表单语法 -的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个市场,并有一个表格来收集卖家的银行帐户详细信息,以便我们可以转移付款.

条带参数之一是卖家名称,它是表单上的输入.当我提交表单时,控制器仅读取已存储在数据库中的名称(即,如果我在 db 中手动输入名称,然后运行表单).如果名称尚不存在,它会给我一个错误,提示我需要输入一个名称来创建条带令牌.

如何更改表单/方法,以便在用户点击提交时名称可用于条带?

这是我的更新方法:错误与:name => current_user.bankaccname 一致.这是下面粘贴的表单中的输入.

def 更新Stripe.api_key = ENV["STRIPE_API_KEY"]令牌 = params[:stripeToken]收件人 = Stripe::Recipient.create(:名称 =>current_user.bankaccname,:类型 =>个人",:bank_account =>令牌)current_user.recipient = 收件人.idcurrent_user.saveresponse_to do |格式|如果@user.update(user_params)format.html { redirect_to edit_user_url, notice: '您的帐户已成功更新.'}别的format.html { 渲染动作:'编辑' }结尾结尾结尾

我的表格:

<%= form_for @user, url: user_path, html: { method: :put } do |f|%><div class="form-group"><%= f.label :name %><i>(显示在您的银行帐户中)</i><%= f.text_field :bankaccname, class:"form-control" %>

<div class="form-group"><%= label_tag :country %><%= text_field_tag :country, nil, { :name =>nil, :'data-stripe' =>国家",类别:表单控制"} %>

<div class="form-group"><%= label_tag :routing_number %><%= text_field_tag :routing_number, nil, { :name =>nil, :'data-stripe' =>"routingNumber", class: "form-control" } %>

<div class="form-group"><%= label_tag :account_number %><%= text_field_tag :account_number, nil, { :name =>nil, :'data-stripe' =>"accountNumber", class: "form-control" } %>

<div class="form-group"><%= f.submit "Submit", class:"btn btn-primary" %>

<%结束%>

解决方案

检查这个,它更优化,它只对 db 进行一次调用(我猜).它也将解决您的上述问题.

def 更新@user.attributes = user_paramsStripe.api_key = ENV["STRIPE_API_KEY"]令牌 = params[:stripeToken]收件人 = Stripe::Recipient.create(:名称 =>@user.bankaccname,:类型 =>个人",:bank_account =>令牌)@user.recipient = 收件人.idresponse_to do |格式|如果@user.saveformat.html { redirect_to edit_user_url, notice: '您的帐户已成功更新.'}别的format.html { 渲染动作:'编辑' }结尾结尾结尾

I'm building a marketplace and have a form to collect bank account details from sellers so we can transfer payments.

One of the stripe parameters is the sellers name, which is an input on the form. When I submit the form, the controller reads the name only if it is stored in the database already (i.e. if I manually enter name in db, then run form). If a name doesn't already exist, it gives me an error saying I need to enter a name to create the stripe token.

How do I change the form/method such that the name is available for stripe when the user hits submit?

Here is my update method: the error is in the line with :name => current_user.bankaccname. This is an input in the form pasted below.

def update

    Stripe.api_key = ENV["STRIPE_API_KEY"]
      token = params[:stripeToken]

      recipient = Stripe::Recipient.create(
        :name => current_user.bankaccname,
        :type => "individual",
        :bank_account => token
        )

      current_user.recipient = recipient.id
      current_user.save

    respond_to do |format|
      if @user.update(user_params)
        format.html { redirect_to edit_user_url, notice: 'Your account was successfully updated.' }
      else
        format.html { render action: 'edit' }
      end
    end
  end

my form:

<%= form_for @user, url: user_path, html: { method: :put } do |f| %>
     <div class="form-group">
      <%= f.label :name %><i> (as it appears in your bank account)</i>
      <%= f.text_field :bankaccname, class:"form-control" %>
     </div>

 <div class="form-group">
      <%= label_tag :country %>
      <%= text_field_tag :country, nil, { :name => nil, :'data-stripe' => "country", class: "form-control" } %>
    </div>
    <div class="form-group">
      <%= label_tag :routing_number %>
      <%= text_field_tag :routing_number, nil, { :name => nil, :'data-stripe' => "routingNumber", class: "form-control" } %>
    </div>
    <div class="form-group">
      <%= label_tag :account_number %>
      <%= text_field_tag :account_number, nil, { :name => nil, :'data-stripe' => "accountNumber", class: "form-control" } %>
    </div>

     <div class="form-group">
        <%= f.submit "Submit", class:"btn btn-primary" %>
     </div>

<% end %>

解决方案

check this, it is more optimized, it makes only one call to db (i guess). and it will solve your above problem too.

def update
    @user.attributes = user_params
    Stripe.api_key = ENV["STRIPE_API_KEY"]
      token = params[:stripeToken]

      recipient = Stripe::Recipient.create(
        :name => @user.bankaccname,
        :type => "individual",
        :bank_account => token
        )

     @user.recipient = recipient.id
     respond_to do |format|
      if @user.save
        format.html { redirect_to edit_user_url, notice: 'Your account was successfully updated.' }
      else
        format.html { render action: 'edit' }
      end
    end
  end

这篇关于Stripe 银行令牌的 Rails 4 表单语法 -的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆