Authorize.net:此交易已被拒绝

时间:2014-07-12 18:05:14

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

CreditCard模型

def charge_cents!(cents)
  begin
    gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new($installation[:authorize])
    response = nil
    Timeout::timeout(120.seconds) {
      response = gateway.purchase(cents, self.to_am_creditcard, {
        :order_id      => self.customer.contract_number[1..-1],
        :cust_id       => self.customer.contract_number[1..-1]
      }.merge(self.am_billing_address_hash))
    }
    return response
  rescue
    return response = nil
  end
end

to_am_creditcard

  def to_am_creditcard
    ActiveMerchant::Billing::CreditCard.new({
      :number   => self.number,
      :month    => self.month,
      :year     => self.year,
      :first_name => self.first_name,
      :last_name  => self.last_name,
    })
  end

am_billing_address_hash

  def am_billing_address_hash
    {:billing_address => self.to_hash }
  end

现在,拿最后一张信用卡

1.9.3p484 :003 > @card = CreditCard.last
 => #<CreditCard id: 17263, crypted_number: "uXHr8wFYPvlaLWkB7hMltzex60ZtINOMH7EDB+/uSZU=\n", last_4: "4242", first_name: "test3", last_name: "test4", phone: "1234567890", customer_id: 66837, month: 7, year: 2017, address_id: 230222, created_at: "2014-07-11 03:36:21", updated_at: "2014-07-11 03:36:21"> 

现在,使用charge_cents方法

1.9.3p484 :006 >  response = @card.charge_cents!(amount * 100.0)
 => #<ActiveMerchant::Billing::Response:0xbac6ce0 @params={"response_code"=>2, "response_reason_code"=>"2", "response_reason_text"=>"This transaction has been declined.", "avs_result_code"=>"U", "transaction_id"=>"6328764577", "card_code"=>"", "authorization_code"=>"", "cardholder_authentication_code"=>"", "action"=>"AUTH_CAPTURE"}, @message="This transaction has been declined", @success=false, @test=false, @authorization="6328764577", @fraud_review=false, @avs_result={"code"=>"U", "message"=>"Address information unavailable.", "street_match"=>nil, "postal_match"=>nil}, @cvv_result={"code"=>nil, "message"=>nil}> 

请参阅:response_reason_text :获取此交易已被拒绝

我不知道为什么我会收到此错误,它正在测试模式,但是当我删除测试模式然后出现此错误时。

或者,如果在rails 3.2上将auth.net与ruby集成的任何其他方式,请使用代码为此提供帮助。

更新 我传递了这些数据: CC号:4242424242424242 ExpireDate:11/2015

请帮助我。

先谢谢。

1 个答案:

答案 0 :(得分:0)

首先,当您指定测试模式时,网关仅检查API登录和事务密钥是否正确,如果有效则返回成功。这对于沙箱或生产都是如此。你永远不应该在沙盒中使用测试模式。

尝试在测试模式为false的沙箱中使用4111111111111111来测试事务。