ruby-on-rails - Active Merchant 和 Authorize.net 在生产中返回失败

标签 ruby-on-rails ruby ruby-on-rails-3 authorize.net activemerchant

我有一个具有一些基本电子商务事件的应用程序。我用一个测试 authorize.net 帐户试过了,它工作正常。虽然我进入了生产模式的 API,但当我尝试购买任何东西时,我总是被重定向到失败屏幕。我没有收到任何错误,heroku 的日志中也没有任何错误,我什至不知道从哪里开始调试。我成功连接到 Authorize.net,交易在开发模式下成功 - 我主要基于 Ryan Bate 的 RailsCast 第 145 集(http://railscasts.com/episodes/145-integrating-active-merchant),但这里是我的代码的一些亮点(因为我正在测试 ti,我'尽管我订购了,但它还是强制它进行 1 美分的交易)

在 enviroments/production.rb 中

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

订单 Controller .rb

 def create
    @order = Order.new(params[:order])
    @order.cart = current_cart
    if @order.save
      if @order.purchase
        @order.state = 'paid'
        @order.save
        render :action => "success"
        end
      else
        render :action => "failure"
      end
    else
      redirect_to home_page_path, notice: "The order failed to save"
    end
  end

def purchase
    response = GATEWAY.purchase(1, credit_card, purchase_options)
    transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
    #cart.update_attribute(:purchased_at, Time.now) if response.success?
    response.success?
  end

订单.rb

  def purchase
    response = GATEWAY.purchase(1, credit_card, purchase_options)
    transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
    #cart.update_attribute(:purchased_at, Time.now) if response.success?
    response.success?
  end

private

  def purchase_options
    {
      :ip => ip_address,
      :billing_address => {
        :first_name   => first_name,
        :last_name    => last_name,
        :address1     => address_line_1,
        :address2     => address_line_2,
        :city         => city,
        :state        => billing_state,
        :country      => "US",
        :zip          => zip_code,
        :phone        => phone_number,
        :company      => company
      },
      :shipping_address => {
        :first_name   => sfirst_name,
        :last_name    => slast_name,
        :address1     => saddress_line_1,
        :address2     => saddress_line_2,
        :city         => scity,
        :state        => sbilling_state,
        :country      => "US",
        :zip          => szip_code,
        :phone        => sphone_number,
        :company      => scompany
      }
    }
  end

  def validate_card
    unless credit_card.valid?
      credit_card.errors.full_messages.each do |message|
        errors.add :base, message
      end
    end
  end

  def credit_card
    @credit_card ||= ActiveMerchant::Billing::CreditCard.new(
      :brand              => card_type,
      :number             => card_number,
      :verification_value => card_verification,
      :month              => card_expires_on.month,
      :year               => card_expires_on.year,
      :first_name         => first_name,
      :last_name          => last_name
    )
  end

最佳答案

我没有亲自处理过 authorize.net,但我使用过类似的 Web 服务,该服务也需要 PCI 合规性。在我的例子中,这意味着我需要一个有效的 SSL 证书来使交易在生产中工作。事实上,如果我没记错的话,交易失败的方式非常相似,而且原因并不明显。

看起来 authorize.net 需要某种类型的安全性,具体取决于您使用的 API。 http://developer.authorize.net/integration/

关于ruby-on-rails - Active Merchant 和 Authorize.net 在生产中返回失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14995618/

相关文章:

ruby-on-rails - 使用 Rails 的 form_for 但在 <form> 元素上设置自定义类、属性?

ruby-on-rails - 如何在 Rails 3 项目中包含 SSL 证书

ruby-on-rails - 如何使用 Pundit 处理分页?

ruby-on-rails - 按日期(或任何其他列)对 ActiveRecord 返回的数组进行排序

ruby-on-rails - 在这种情况下我如何模拟一个对象?没有明显的方法可以用模拟替换对象

jquery - 验证检查带有单独提交按钮的动态文本框

javascript - 使用 ember-rails 收集输入字段中提交的文本

ruby-on-rails - 为什么 Date.yesterday 也算作 Date.today?

ruby-on-rails - 升级到 Rails 4 时批量分配失败

ruby - jruby 1.6.7/1.7.0 1.9 模式下的 OpenSSL::SSL::SSLError