Ruby on rails 活动商户和Authorize.net在生产中返回失败

Ruby on rails 活动商户和Authorize.net在生产中返回失败,ruby-on-rails,ruby,ruby-on-rails-3,authorize.net,activemerchant,Ruby On Rails,Ruby,Ruby On Rails 3,Authorize.net,Activemerchant,我有一个应用程序,有一些基本的电子商务活动。我用一个test authorize.net帐户试用过,效果很好。不过,我进入了生产模式的API,当我尝试购买任何东西时,我总是被重定向到失败屏幕。我没有收到任何错误,heroku上的日志中没有任何内容,我甚至不知道从哪里开始调试。我成功地连接到Authorize.net,在开发模式下事务处理是成功的-我大量基于Ryan Bate的RailsCast第145集(),但这里是我代码的一些亮点(因为我在测试ti,我强迫它做1美分的事务,不管我点了什么) 在

我有一个应用程序,有一些基本的电子商务活动。我用一个test authorize.net帐户试用过,效果很好。不过,我进入了生产模式的API,当我尝试购买任何东西时,我总是被重定向到失败屏幕。我没有收到任何错误,heroku上的日志中没有任何内容,我甚至不知道从哪里开始调试。我成功地连接到Authorize.net,在开发模式下事务处理是成功的-我大量基于Ryan Bate的RailsCast第145集(),但这里是我代码的一些亮点(因为我在测试ti,我强迫它做1美分的事务,不管我点了什么)

在Environments/production.rb中

config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :production
  ::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
    :login => "scrubbed",
    :password => "scrubbed",
    :test => false
  )
  end
orders_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
order.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。

我需要问一下,只是想确定一下-您是否已经尽了一切努力在Authorize.net和您的银行中设置了用于生产的商户帐户,并且您已经与他们协调,在资金开始流入时开始将资金过账到您的银行帐户

如果是这样,请查看此处的开发人员文档页面,了解测试事务和生产事务之间的差异


在网关端正确配置所有内容后,在测试模式下工作的事务应该在生产模式下工作。我将联系authorize.net,您的帐户可能需要最终确定一些技术或管理细节以处理实时交易。

首先,您的订单控制器的最后6行和订单模型的前6行是相同的(
def purchase
)-是否正确?你在Authorize.net的日志中看到什么了吗?失败的交易?我的第一步是将
Rails.logger.debug response添加到我的代码中。检查
以查看响应对象。除此之外,Heroku不符合PCI标准,因此当您的商户的季度QSA出现时,您将遇到一系列问题。如果您在不符合时标记为符合,则可能会有法律问题,如果您标记为不符合,则他们通常会进行审核。祝你好运