3

I have an app that has some basic ecommerce activity. I tried it with a test authorize.net account, and it works fine. I entered in the APIs for production mode though, and I keep getting redirected to the failure screen when I try to purchase anything. I'm not getting any errors, nothing in the logs on heroku, and I don't even know where to start debugging. I am connecting to Authorize.net successfully, transactions are successful in development mode - I based it heavily off of Ryan Bate's RailsCast episode 145 (http://railscasts.com/episodes/145-integrating-active-merchant), but here are some highlights of my code (since I'm testing ti, I'm forcing it to do 1 cent transactions despite what I order)

in enviroments/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
4

2 回答 2

1

我需要问一下以确保 - 您是否已完成所有操作以使用 Authorize.net 和您的银行设置您的商家帐户以供生产使用,并且您已与他们协调以在资金开始时开始将资金存入您的银行帐户进来?

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

http://developer.authorize.net/guides/AIM/5_TestTrans.html

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

于 2013-03-01T19:08:46.710 回答
1

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

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

于 2013-02-26T06:11:59.710 回答