Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将与活跃商户链接的正常表单更改为Braintree dropin ui?_Ruby On Rails_Braintree_Activemerchant - Fatal编程技术网

Ruby on rails 如何将与活跃商户链接的正常表单更改为Braintree dropin ui?

Ruby on rails 如何将与活跃商户链接的正常表单更改为Braintree dropin ui?,ruby-on-rails,braintree,activemerchant,Ruby On Rails,Braintree,Activemerchant,我有一个注册页面,用户将输入个人信息和信用卡信息。 此信用卡信息与activemerchant集成,并存储在数据库中 这是我的表格: <%= semantic_form_for(@account, :url => account_create_path, :html => { :multipart => true, :class => 'billing'}) do |f| %> <div class="section section-first"

我有一个注册页面,用户将输入个人信息和信用卡信息。 此信用卡信息与activemerchant集成,并存储在数据库中

这是我的表格:

<%= semantic_form_for(@account, :url => account_create_path, :html => { :multipart => true, :class => 'billing'}) do |f| %>

   <div class="section section-first">
      <%= f.inputs :for => :user do |u| %>
        <h3>Account Information</h3>

        <%= u.input :name, :input_html => {:placeholder => "Name", :value => @account.user.name} %>
        <%= u.input :email, :input_html => {:placeholder => "Email", :value => @account.user.email} %>
      <% end %>
    </div>
        <div class="section">
            <%= f.inputs :for => :creditcard do |c| %>
            <h3>Credit Card Information</h3>
            <%= c.input :brand, :selected => @creditcard.brand.nil? ? "visa" : @creditcard.brand, :label => "Credit Card", :as => :select, :class => 'dropkick', :include_blank => false, :collection => Saas::Config.gateway == "bogus" ? [['Bogus', 'bogus']] : [['Visa', 'visa'], ['MasterCard', 'master'], ['American Express', 'american_express'], ['Discover', 'discover']] %>
            <%= c.input :number, :input_html => { :placeholder => "Card Number"}, :label => "Card Number", :as => :numeric %>

            <li class="select required" id="account_creditcard_expiration_input">
                <label for="account_creditcard_expiration">Card Expires On<abbr title="required">*</abbr></label>
              <%= c.select :year, (Time.now.year .. 10.years.from_now.year), :selected => @creditcard.year.nil? ? Time.now.year : @creditcard.year, :class => 'dropkick dd-small' %>
              <%= c.select :month, [['1 - January', 1], ['2 - February', 2], ['3 - March', 3], ['4 - April', 4], ['5 - May', 5], ['6 - June', 6], ['7 - July', 7], ['8 - August', 8], ['9 - September', 9], ['10 - October', 10], ['11 - November', 11], ['12 - December', 12]], :selected => @creditcard.month.nil? ? "1" : @creditcard.month, :class => 'dropkick' %>
            </li>

            <%= c.input :verification_value, :label => "CVV Code", :input_html => { :placeholder => "CVV Code", :value => @creditcard.verification_value,
                :type => "password",
                :class => 'short' } %>

          <% end %>

<% end %>
财务主任:

class AccountsController < ApplicationController

  before_filter :build_account, :only => [:new, :create]
  before_filter :build_user, :only => [:new, :create]
  before_filter :load_billing, :only => [:new, :create, :billing]
  def create
    @address.first_name = @creditcard.first_name
    @address.last_name = @creditcard.last_name
    @account.address = @address
    @account.creditcard = @creditcard
    if @account.new_record?
      if @account.save
        flash[:notice] = 'Account was created.'
        bypass_sign_in(@user)
        redirect_to session[:previous_url] || user_reports_path(@user)
      else
        render :action => 'new'
      end
    else
      @user.account_id = @account.id
      if @user.save
        flash[:notice] = 'User was created.'
        bypass_sign_in(@user)
        redirect_to session[:previous_url] || user_reports_path(@user)
      else
        render :action => 'new'
      end
    end
  end

  def billing
    @user = current_user
    @account = Account.find(params[:id])
    if request.put?
      @address.first_name = @creditcard.first_name
      @address.last_name = @creditcard.last_name
      puts @address.first_name
      if @creditcard.valid? & @address.valid?
       if @subscription.store_card(@creditcard, :billing_address => @address.to_activemerchant, :ip => request.remote_ip)
         flash[:notice] = "Your billing information has been updated."
         redirect_to settings_path(@user)
       end
      end
    end
  end
  protected

  def resource
    @account ||= current_account
  end

  def build_account
    @account = params[:account_name].blank? ? Account.new : Account.find_by_name(params[:account_name])
  end

  def build_user
    @account.user = @user = User.new(params[:account].blank? ? nil : params[:account][:user])
  end

  def load_billing
    @creditcard = ActiveMerchant::Billing::CreditCard.new(params[:account].blank? ? {} : params[:account][:creditcard])
    @address = SubscriptionAddress.new(params[:account].blank? ? {} : params[:account][:address])
  end

end
免责声明:我在Braintree工作

简单回答:你不能。这个插件是为了安全地替换您托管的信用卡表单。要使用Drop-in,您应该取出表单和帐户模型的整个信用卡部分,不要期望处理和存储信用卡数据,而是接收Drop-in返回的数据,并通过Braintree交易或支付方法API使用它

详细回答:该插件是一个由Braintree托管的预构建表单,我们将通过iframe将其插入页面上的表单中。当表单提交时,来自Drop-in的信用卡(或PayPal等)信息被发送到Braintree,支付方法nonce被返回到页面(通过JavaScript回调或插入表单中的隐藏字段)。nonce是一个随机生成的字符串,代表支付信息,并且可以在没有安全风险的情况下通过应用程序。查看Braintree开发者文档,了解更多详细信息和示例代码

这一切的主要原因是安全。在不安全的环境中存储信用卡信息违反了行业法规(称为PCI安全标准),存储信用卡的CVV/安全代码也违反了PCI法规。该插件(或我们的托管字段集成)使您更容易满足PCI标准,并减轻您保护站点的负担

总而言之:您应该从ActiveMerchant中删除客户信用卡的集成,而不将其包含在您的架构中。相反,在表单中包含一个空白div,以便插入插入插入,并在模型/控制器中插入插入返回时使用付款方法。如何将nonce、服务器端Braintree API调用及其结果集成到rails模型中取决于您。我们有一个完整的rails应用程序示例,它使用了下拉菜单:请随意查看braintree\u rails\u示例在braintree github页面上的repo以获取想法。

免责声明:我在braintree工作

简单回答:你不能。这个插件是为了安全地替换您托管的信用卡表单。要使用Drop-in,您应该取出表单和帐户模型的整个信用卡部分,不要期望处理和存储信用卡数据,而是接收Drop-in返回的数据,并通过Braintree交易或支付方法API使用它

详细回答:该插件是一个由Braintree托管的预构建表单,我们将通过iframe将其插入页面上的表单中。当表单提交时,来自Drop-in的信用卡(或PayPal等)信息被发送到Braintree,支付方法nonce被返回到页面(通过JavaScript回调或插入表单中的隐藏字段)。nonce是一个随机生成的字符串,代表支付信息,并且可以在没有安全风险的情况下通过应用程序。查看Braintree开发者文档,了解更多详细信息和示例代码

这一切的主要原因是安全。在不安全的环境中存储信用卡信息违反了行业法规(称为PCI安全标准),存储信用卡的CVV/安全代码也违反了PCI法规。该插件(或我们的托管字段集成)使您更容易满足PCI标准,并减轻您保护站点的负担


总而言之:您应该从ActiveMerchant中删除客户信用卡的集成,而不将其包含在您的架构中。相反,在表单中包含一个空白div,以便插入插入插入,并在模型/控制器中插入插入返回时使用付款方法。如何将nonce、服务器端Braintree API调用及其结果集成到rails模型中取决于您。我们有一个完整的rails应用程序示例,它使用了下拉列表:请随意查看braintree github页面上的braintree\u rails\u示例repo以获取想法。

您是否尝试添加下拉列表?他们有一个沙箱和他们的文档:添加插件非常好。到目前为止,什么还不起作用?您是否尝试添加了临时登录?他们有一个沙箱和他们的文档:添加插件非常好。到目前为止什么还不起作用?
class AccountsController < ApplicationController

  before_filter :build_account, :only => [:new, :create]
  before_filter :build_user, :only => [:new, :create]
  before_filter :load_billing, :only => [:new, :create, :billing]
  def create
    @address.first_name = @creditcard.first_name
    @address.last_name = @creditcard.last_name
    @account.address = @address
    @account.creditcard = @creditcard
    if @account.new_record?
      if @account.save
        flash[:notice] = 'Account was created.'
        bypass_sign_in(@user)
        redirect_to session[:previous_url] || user_reports_path(@user)
      else
        render :action => 'new'
      end
    else
      @user.account_id = @account.id
      if @user.save
        flash[:notice] = 'User was created.'
        bypass_sign_in(@user)
        redirect_to session[:previous_url] || user_reports_path(@user)
      else
        render :action => 'new'
      end
    end
  end

  def billing
    @user = current_user
    @account = Account.find(params[:id])
    if request.put?
      @address.first_name = @creditcard.first_name
      @address.last_name = @creditcard.last_name
      puts @address.first_name
      if @creditcard.valid? & @address.valid?
       if @subscription.store_card(@creditcard, :billing_address => @address.to_activemerchant, :ip => request.remote_ip)
         flash[:notice] = "Your billing information has been updated."
         redirect_to settings_path(@user)
       end
      end
    end
  end
  protected

  def resource
    @account ||= current_account
  end

  def build_account
    @account = params[:account_name].blank? ? Account.new : Account.find_by_name(params[:account_name])
  end

  def build_user
    @account.user = @user = User.new(params[:account].blank? ? nil : params[:account][:user])
  end

  def load_billing
    @creditcard = ActiveMerchant::Billing::CreditCard.new(params[:account].blank? ? {} : params[:account][:creditcard])
    @address = SubscriptionAddress.new(params[:account].blank? ? {} : params[:account][:address])
  end

end
class Subscription < ActiveRecord::Base

  attr_accessor :creditcard, :address
  def store_card(creditcard, gw_options = {})
    # Clear out payment info if switching to CC from PayPal
    destroy_gateway_record(paypal) if paypal?

    @response = if billing_id.blank?
      gateway.store(creditcard, gw_options)
    else
      gateway.update(billing_id, creditcard, gw_options)
    end

    if @response.success?
      if active_card = @response.params['active_card']
        # Stripe token-based response
        self.card_number = "XXXX-XXXX-XXXX-#{active_card['last4']}"
        self.card_expiration = "%02d-%d" % [active_card['exp_month'], active_card['exp_year']]
      else
        self.card_number = creditcard.display_number
        self.card_expiration = "%02d-%d" % [creditcard.expiry_date.month, creditcard.expiry_date.year]
      end
      set_billing
    else
      errors.add(:base, @response.message)
      false
    end
  end

  def card_storage
      self.store_card(@creditcard, :billing_address => @address.to_activemerchant) if @creditcard && @address && card_number.blank?
    end

  def set_billing
      self.billing_id = @response.token
    end

end
 config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :production
    ::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
      :login => "xxxxxxx",
      :password => "xxxxxxxxxxxxxx"    )
  end