使用ActiveMerchant的Authorize.Net在生产模式下不起作用

时间:2012-07-31 20:09:12

标签: authorize.net activemerchant

在开发模式下一切正常!虚假交易成功,我收到了Authorize.Net的收据。但是当我在生产中使用真正的登录ID和事务密钥时,它不起作用。我打电话给Authorize.Net,他们说交易从来没有打到他们的系统,并说我需要发布到他们的实时网址而不是测试网址。我按照其他网站的教程进行操作,但没有人告诉他们为Authorize.Net设置网址。

这是我的production.rb

ActiveMerchant::Billing::Base.mode = :production

::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
  :login    => HADEAN_CONFIG['authnet']['login'],
  :password => HADEAN_CONFIG['authnet']['password'],
  :test     => false
)

orders_controller.rb

def update
@order = session_admin_order
@order.ip_address = request.remote_ip

@credit_card ||= ActiveMerchant::Billing::CreditCard.new(cc_params)

address = @order.bill_address.cc_params

if @order.complete?
  #CartItem.mark_items_purchased(session_cart, @order)
  session_admin_cart.mark_items_purchased(@order)
  flash[:error] = I18n.t('the_order_purchased')
  redirect_to admin_history_order_url(@order)
elsif @credit_card.valid?
  if response = @order.create_invoice(@credit_card,
                                      @order.credited_total,
                                      {:email => @order.email, :billing_address=> address, :ip=> @order.ip_address },
                                      @order.amount_to_credit)
    if response.succeeded?
      ##  MARK items as purchased
      #CartItem.mark_items_purchased(session_cart, @order)
      @order.remove_user_store_credits
      session_admin_cart.mark_items_purchased(@order)
      order_completed!
      Notifier.order_confirmation(@order, invoice).deliver rescue puts( 'do nothing...  dont blow up over an email')
      redirect_to admin_history_order_url(@order)
    else
      form_info
      flash[:error] =  [I18n.t('could_not_process'), I18n.t('the_order')].join(' ')
      render :action => "show"
    end
  else
    form_info
    flash[:error] = [I18n.t('could_not_process'), I18n.t('the_credit_card')].join(' ')
    render :action => 'show'
  end
else
  form_info
  flash[:error] = [I18n.t('credit_card'), I18n.t('is_not_valid')].join(' ')
  render :action => 'show'
end

private

def form_info 

def cc_params
{
      :type               => params[:type],
      :number             => params[:number],
      :verification_value => params[:verification_value],
      :month              => params[:month],
      :year               => params[:year],
      :first_name         => params[:first_name],
      :last_name          => params[:last_name]
} end

1 个答案:

答案 0 :(得分:0)

尝试进行这一小改动:

ActiveMerchant::Billing::Base.mode = :production
ActiveMerchant::Billing::AuthorizeNetCimGateway.new( 
  :login    => HADEAN_CONFIG['authnet']['login'],
  :password => HADEAN_CONFIG['authnet']['password']
)