title: Authorize.net : This transaction has been declined
body: <p><strong>CreditCard Model</strong></p>
  
  <pre><code>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      =&gt; self.customer.contract_number[1..-1],
          :cust_id       =&gt; self.customer.contract_number[1..-1]
        }.merge(self.am_billing_address_hash))
      }
      return response
    rescue
      return response = nil
    end
  end
  </code></pre>
  
  <p><strong>to_am_creditcard</strong></p>
  
  <pre><code>  def to_am_creditcard
      ActiveMerchant::Billing::CreditCard.new({
        :number   =&gt; self.number,
        :month    =&gt; self.month,
        :year     =&gt; self.year,
        :first_name =&gt; self.first_name,
        :last_name  =&gt; self.last_name,
      })
    end
  </code></pre>
  
  <p><strong>am_billing_address_hash</strong></p>
  
  <pre><code>  def am_billing_address_hash
      {:billing_address =&gt; self.to_hash }
    end
  </code></pre>
  
  <p>Now, Take last credit card</p>
  
  <pre><code>1.9.3p484 :003 &gt; @card = CreditCard.last
   =&gt; #&lt;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"&gt; 
  </code></pre>
  
  <p>and Now, use charge_cents method</p>
  
  <pre><code>1.9.3p484 :006 &gt;  response = @card.charge_cents!(amount * 100.0)
   =&gt; #&lt;ActiveMerchant::Billing::Response:0xbac6ce0 @params={"response_code"=&gt;2, "response_reason_code"=&gt;"2", "response_reason_text"=&gt;"This transaction has been declined.", "avs_result_code"=&gt;"U", "transaction_id"=&gt;"6328764577", "card_code"=&gt;"", "authorization_code"=&gt;"", "cardholder_authentication_code"=&gt;"", "action"=&gt;"AUTH_CAPTURE"}, @message="This transaction has been declined", @success=false, @test=false, @authorization="6328764577", @fraud_review=false, @avs_result={"code"=&gt;"U", "message"=&gt;"Address information unavailable.", "street_match"=&gt;nil, "postal_match"=&gt;nil}, @cvv_result={"code"=&gt;nil, "message"=&gt;nil}&gt; 
  </code></pre>
  
  <p><strong>See : response_reason_text</strong>  : Getting This transaction has been declined</p>
  
  <p>I don't know why I am getting this error, It's working on test mode but when I remove a test mode then getting this error.</p>
  
  <p>or, If any other way to integrate auth.net with ruby on rails 3.2 then please help for this with code.</p>
  
  <p><strong>Update</strong>
  I am passing this data: 
  CC Number : 4242424242424242
  ExpireDate : 11/2015</p>
  
  <p>Please Help Me.</p>
  
  <p>Thanks, In Advance.</p>