Authorize.Net Gateway Guide

Adding

To add an Authorize.Net gateway you just need to supply your Authorize.net API login ID and your Authorize.net transaction key:


curl https://core.spreedly.com/v1/gateways.xml \
  -u 'Ll6fAtoVSTyVMlJEmtpoJV8S:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSy' \
  -H 'Content-Type: application/xml' \
  -d '<gateway>
        <gateway_type>authorize_net</gateway_type>
        <login>Your Authorize.Net API Login ID</login>
        <password>Your Authorize.Net Transaction Key</password>
      </gateway>'

<gateway>
  <token>OyFP9u3Gm9izNIWObNBw1jP15SR</token>
  <gateway_type>authorize_net</gateway_type>
  <name>Authorize.Net</name>
  <description nil="true"/>
  <login>Your Authorize.Net API Login ID</login>
  <characteristics>
    <supports_purchase type="boolean">true</supports_purchase>
    <supports_authorize type="boolean">true</supports_authorize>
    <supports_capture type="boolean">true</supports_capture>
    <supports_credit type="boolean">true</supports_credit>
    <supports_general_credit type="boolean">true</supports_general_credit>
    <supports_void type="boolean">true</supports_void>
    <supports_verify type="boolean">true</supports_verify>
    <supports_reference_purchase type="boolean">false</supports_reference_purchase>
    <supports_purchase_via_preauthorization type="boolean">false</supports_purchase_via_preauthorization>
    <supports_offsite_purchase type="boolean">false</supports_offsite_purchase>
    <supports_offsite_authorize type="boolean">false</supports_offsite_authorize>
    <supports_3dsecure_purchase type="boolean">false</supports_3dsecure_purchase>
    <supports_3dsecure_authorize type="boolean">false</supports_3dsecure_authorize>
    <supports_store type="boolean">true</supports_store>
    <supports_remove type="boolean">false</supports_remove>
    <supports_fraud_review type="boolean">true</supports_fraud_review>
    <supports_disburse type="boolean">false</supports_disburse>
  </characteristics>
  <credentials>
    <credential>
      <name>login</name>
      <value>Your Authorize.Net API Login ID</value>
    </credential>
  </credentials>
  <gateway_specific_fields>
    <gateway_specific_field>customer_id</gateway_specific_field>
    <gateway_specific_field>customer_profile_id</gateway_specific_field>
    <gateway_specific_field>duplicate_window</gateway_specific_field>
    <gateway_specific_field>disable_partial_auth</gateway_specific_field>
    <gateway_specific_field>market_type</gateway_specific_field>
    <gateway_specific_field>recurring</gateway_specific_field>
    <gateway_specific_field>email_customer</gateway_specific_field>
    <gateway_specific_field>header_email_receipt</gateway_specific_field>
    <gateway_specific_field>line_items</gateway_specific_field>
    <gateway_specific_field>po_number</gateway_specific_field>
    <gateway_specific_field>tax_exempt</gateway_specific_field>
    <gateway_specific_field>tax</gateway_specific_field>
    <gateway_specific_field>duty</gateway_specific_field>
    <gateway_specific_field>shipping</gateway_specific_field>
  </gateway_specific_fields>
  <payment_methods>
    <payment_method>credit_card</payment_method>
    <payment_method>bank_account</payment_method>
    <payment_method>apple_pay</payment_method>
    <payment_method>third_party_token</payment_method>
  </payment_methods>
  <state>retained</state>
  <redacted type="boolean">false</redacted>
  <created_at type="dateTime">2017-06-06T15:09:23Z</created_at>
  <updated_at type="dateTime">2017-06-06T15:09:23Z</updated_at>
</gateway>


env = Spreedly::Environment.new('Ll6fAtoVSTyMlJEm', 'RKcG5D8D3fZxDSg504U2XD4Io5VXz')
env.add_gateway(:authorize_net, login: "Your Authorize.Net API Login ID",
                password: "Your Authorize.Net Transaction Key")


#<Spreedly::Gateway:0x007fd58132bbe0
 @created_at="2016-11-28T20:57:48Z",
 @credentials={"login"=>"Your Authorize.Net API Login ID"},
 @gateway_type="authorize_net",
 @name="Authorize.Net",
 @state="retained",
 @token="N1y7VIgGTfWFdlr2GMMOs6raTM5",
 @updated_at="2016-11-28T20:57:48Z">

Gateway specific response fields

A response from Authorize.net may contain a response_reason_code or authorization_code.

You can find this information in gateway_specific_response_fields. For example, a transaction could have something like this:

<transaction>
  <token>LgpTNGjsWQs9DwdxcbreUVz0R8p</token>
  <transaction_type>Purchase</transaction_type>
  <gateway_specific_response_fields>
     <authorize_net>
       <response_reason_code>103</response_reason_code>
       <authorization_code>IJK2DZ</authorization_code>
     </authorize_net>
  </gateway_specific_response_fields>
</transaction>

Authorize.net offers response reason code lookup tool which may help you discern why a transaction is failing. This can be especially helpful when you initially setup your Authorize.net gateway and run a real transaction to verify your credentials are correct.

Gateway specific request fields

When interacting with a Authorize.Net gateway to run transactions, there are many gateway specific fields you can specify when making a call. These fields can be sent like so:


curl https://core.spreedly.com/v1/gateways/LlkjmEk0xNkcWrNixXa1fvNoTP4/purchase.xml \
  -u 'Ll6fAtoVSTyVMlJEmtpoJV8S:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSy' \
  -H 'Content-Type: application/xml' \
  -d '<transaction>
        <payment_method_token>56wyNnSmuA6CWYP7w0MiYCVIbW6</payment_method_token>
        <amount>100</amount>
        <currency_code>USD</currency_code>
        <gateway_specific_fields>
          <authorize_net>
            <customer_id>3341</customer_id>
            <duplicate_window>0</duplicate_window>
            <disable_partial_auth>true</disable_partial_auth>
            <market_type>0</market_type>
            <recurring>false</recurring>
            <email_customer>true</email_customer>
            <header_email_receipt>subject line</header_email_receipt>
            <po_number>123</po_number>
            <tax_exempt>false</tax_exempt>
            <tax>
              <amount>100</amount>
              <name>tax name</name>
              <description>tax description</description>
            </tax>
            <duty>
              <amount>100</amount>
              <name>duty name</name>
              <description>duty description</description>
            </duty>
            <shipping>
              <amount>100</amount>
              <name>shipping name</name>
              <description>shipping description</description>
            </shipping>
            <line_items>
              <line_item>
                <item_id>1</item_id>
                <name>mug</name>
                <description>coffee</description>
                <quantity>100</quantity>
                <unit_price>10</unit_price>
              </line_item>
              <line_item>
                <item_id>2</item_id>
                <name>vase</name>
                <description>floral</description>
                <quantity>200</quantity>
                <unit_price>20</unit_price>
              </line_item>
            </line_items>
          </authorize_net>
        </gateway_specific_fields>
      </transaction>'

<transaction>
  <on_test_gateway type="boolean">true</on_test_gateway>
  <created_at type="dateTime">2017-06-06T15:09:24Z</created_at>
  <updated_at type="dateTime">2017-06-06T15:09:25Z</updated_at>
  <succeeded type="boolean">true</succeeded>
  <state>succeeded</state>
  <token>AcMbTutZbVUPr5ACqyHjaWjWqXQ</token>
  <transaction_type>Purchase</transaction_type>
  <order_id nil="true"/>
  <ip nil="true"/>
  <description nil="true"/>
  <email nil="true"/>
  <merchant_name_descriptor nil="true"/>
  <merchant_location_descriptor nil="true"/>
  <gateway_specific_fields>
    <authorize_net>
      <customer_id>3341</customer_id>
      <duplicate_window>0</duplicate_window>
      <disable_partial_auth>true</disable_partial_auth>
      <market_type>0</market_type>
      <recurring>false</recurring>
      <email_customer>true</email_customer>
      <header_email_receipt>subject line</header_email_receipt>
      <po_number>123</po_number>
      <tax_exempt>false</tax_exempt>
      <tax>
        <amount>100</amount>
        <name>tax name</name>
        <description>tax description</description>
      </tax>
      <duty>
        <amount>100</amount>
        <name>duty name</name>
        <description>duty description</description>
      </duty>
      <shipping>
        <amount>100</amount>
        <name>shipping name</name>
        <description>shipping description</description>
      </shipping>
      <line_items>
        <line_item type="array">
          <line_item>
            <item_id>1</item_id>
            <name>mug</name>
            <description>coffee</description>
            <quantity>100</quantity>
            <unit_price>10</unit_price>
          </line_item>
          <line_item>
            <item_id>2</item_id>
            <name>vase</name>
            <description>floral</description>
            <quantity>200</quantity>
            <unit_price>20</unit_price>
          </line_item>
        </line_item>
      </line_items>
    </authorize_net>
  </gateway_specific_fields>
  <gateway_specific_response_fields>
  </gateway_specific_response_fields>
  <gateway_transaction_id>68</gateway_transaction_id>
  <gateway_latency_ms type="integer">0</gateway_latency_ms>
  <amount type="integer">100</amount>
  <currency_code>USD</currency_code>
  <retain_on_success type="boolean">false</retain_on_success>
  <payment_method_added type="boolean">false</payment_method_added>
  <message key="messages.transaction_succeeded">Succeeded!</message>
  <gateway_token>HW8ineDHN6A6b5qvZzeP2AlPt41</gateway_token>
  <shipping_address>
    <name>Danyka Lebsack</name>
    <address1 nil="true"/>
    <address2 nil="true"/>
    <city nil="true"/>
    <state nil="true"/>
    <zip nil="true"/>
    <country nil="true"/>
    <phone_number nil="true"/>
  </shipping_address>
  <response>
    <success type="boolean">true</success>
    <message>Successful purchase</message>
    <avs_code nil="true"/>
    <avs_message nil="true"/>
    <cvv_code nil="true"/>
    <cvv_message nil="true"/>
    <pending type="boolean">false</pending>
    <result_unknown type="boolean">false</result_unknown>
    <error_code></error_code>
    <error_detail nil="true"/>
    <cancelled type="boolean">false</cancelled>
    <fraud_review nil="true"/>
    <created_at type="dateTime">2017-06-06T15:09:24Z</created_at>
    <updated_at type="dateTime">2017-06-06T15:09:25Z</updated_at>
  </response>
  <api_urls>
  </api_urls>
  <payment_method>
    <token>IX9U9LT5hiz4r7NEc8N0XjFACsn</token>
    <created_at type="dateTime">2017-05-15T19:45:57Z</created_at>
    <updated_at type="dateTime">2017-06-01T15:34:29Z</updated_at>
    <email nil="true"/>
    <data nil="true"/>
    <storage_state>retained</storage_state>
    <test type="boolean">true</test>
    <last_four_digits>1111</last_four_digits>
    <first_six_digits>411111</first_six_digits>
    <card_type>visa</card_type>
    <first_name>Danyka</first_name>
    <last_name>Lebsack</last_name>
    <month type="integer">4</month>
    <year type="integer">2020</year>
    <address1 nil="true"/>
    <address2 nil="true"/>
    <city nil="true"/>
    <state nil="true"/>
    <zip nil="true"/>
    <country nil="true"/>
    <phone_number nil="true"/>
    <company nil="true"/>
    <full_name>Danyka Lebsack</full_name>
    <eligible_for_card_updater nil="true"/>
    <shipping_address1 nil="true"/>
    <shipping_address2 nil="true"/>
    <shipping_city nil="true"/>
    <shipping_state nil="true"/>
    <shipping_zip nil="true"/>
    <shipping_country nil="true"/>
    <shipping_phone_number nil="true"/>
    <payment_method_type>credit_card</payment_method_type>
    <errors>
    </errors>
    <verification_value></verification_value>
    <number>XXXX-XXXX-XXXX-1111</number>
    <fingerprint nil="true"/>
  </payment_method>
</transaction>


env = Spreedly::Environment.new('Ll6fAtoVSTyMlJEm', 'RKcG5D8D3fZxDSg504U2XD4Io5VXz')
env.purchase_on_gateway("LlkjmEk0xNkcWrNixXa1fvNoTP4", "56wyNnSmuA6CWYP7w0MiYCVIbW6", 4432,
  gateway_specific_fields: {
    authorize_net: {
      customer_id: "19311",
      duplicate_window: 0,
      email_customer: "true",
      header_email_receipt: "subject line",
      line_items: {
        line_item: [
        {
          item_id: "1",
          name: "mug",
          description: "coffee",
          quantity: "100",
          unit_price: "10"
        },
        {
          item_id: "2",
          name: "vase",
          description: "floral",
          quantity: "200",
          unit_price: "20"
        }
        ]
      }
    }
  }
)


#<Spreedly::Purchase:0x007faf3231db78
 @amount="4432",
 @created_at="2016-12-05T19:44:42Z",
 @currency_code="USD",
 @description="",
 @email="",
 @gateway_specific_fields=
  {:authorize_net=>
    {:customer_id=>"19311",
     :duplicate_window=>"0",
     :email_customer=>"true",
     :header_email_receipt=>"subject line",
     :line_items=>
      "\n        [{:item_id=>\"1\", :name=>\"mug\", :description=>\"coffee\", :quantity=>\"100\", :unit_price=>\"10\"}, {:item_id=>\"2\", :name=>\"vase\", :description=>\"floral\", :quantity=>\"200\", :unit_price=>\"20\"}]\n      "}},
 @gateway_token="DAoIl7Tgm42p2TXwxYMSNNpKvFQ",
 @gateway_transaction_id="54",
 @ip="",
 @merchant_location_descriptor="",
 @merchant_name_descriptor="",
 @message="Succeeded!",
 @on_test_gateway="true",
 @order_id="",
 @payment_method=
  #<Spreedly::CreditCard:0x007faf323087c8
   @address1="",
   @address2="",
   @card_type="visa",
   @city="",
   @company="",
   @country="",
   @created_at="2016-12-05T18:16:51Z",
   @data="",
   @eligible_for_card_updater="",
   @email="",
   @errors=[],
   @fingerprint="",
   @first_name="Lempi",
   @first_six_digits="411111",
   @full_name="Lempi Thompson",
   @last_four_digits="1111",
   @last_name="Thompson",
   @month="4",
   @number="XXXX-XXXX-XXXX-1111",
   @phone_number="",
   @state="",
   @storage_state="retained",
   @token="VugBz5uZRjCXIMrFA4YDexyD9bN",
   @updated_at="2016-12-05T19:14:43Z",
   @verification_value="",
   @year="2020",
   @zip="">,
 @response=
  #<Spreedly::Response:0x007faf323142a8
   @avs_code="",
   @avs_message="",
   @cancelled="false",
   @created_at="2016-12-05T19:44:42Z",
   @cvv_code="",
   @cvv_message="",
   @error_code="",
   @error_detail="",
   @fraud_review="",
   @message="Successful purchase",
   @pending="false",
   @success="true",
   @updated_at="2016-12-05T19:44:42Z">,
 @shipping_address=
  #<Spreedly::ShippingAddress:0x007faf3230d1b0
   @address1="",
   @address2="",
   @city="",
   @country="",
   @name="Lempi Thompson",
   @phone_number="",
   @state="",
   @zip="">,
 @state="succeeded",
 @succeeded="true",
 @token="Zi54ghFJ5GRdQJaor9MRgDkbece",
 @updated_at="2016-12-05T19:44:42Z">

Recurring Billing

By default, if the payment method is not a credit card, or is a credit card without a cvv value, the request’s recurringBilling flag is set as recurring, otherwise the flag is not sent. If you wish to override this behavior, you can specify the recurring gateway specific field as false to not send the recurringBilling field, or as true to ensure that it is sent as recurring.

Authorize.Net customer_profile_id

When storing a credit card with Authorize.Net CIM using third party vaulting, you can specify a customer_profile_id if you’d like to add the card onto an existing customer in your Authorize.Net account:


curl https://core.spreedly.com/v1/gateways/LlkjmEk0xNkcWrNixXa1fvNoTP4/store.xml \
  -u 'Ll6fAtoVSTyVMlJEmtpoJV8S:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSy' \
  -H 'Content-Type: application/xml' \
  -d '<transaction>
        <payment_method_token>56wyNnSmuA6CWYP7w0MiYCVIbW6</payment_method_token>
        <gateway_specific_fields>
          <authorize_net>
            <customer_profile_id>123456789</customer_profile_id>
          </authorize_net>
        </gateway_specific_fields>
      </transaction>'

<transaction>
  <created_at type="dateTime">2016-11-28T20:57:48Z</created_at>
  <updated_at type="dateTime">2016-11-28T20:57:48Z</updated_at>
  <succeeded type="boolean">true</succeeded>
  <token>VGhRDpvqOH8vgjuAhVDAgpMZOkU</token>
  <state>succeeded</state>
  <gateway_specific_fields>
    <authorize_net>
      <customer_profile_id>123456789</customer_profile_id>
    </authorize_net>
  </gateway_specific_fields>
  <gateway_specific_response_fields>
  </gateway_specific_response_fields>
  <transaction_type>Store</transaction_type>
  <third_party_token nil="true"/>
  <gateway_transaction_id>57</gateway_transaction_id>
  <message key="messages.transaction_succeeded">Succeeded!</message>
  <gateway_token>MV0QL9vSbuUJfaKCCoCP2VTEYyW</gateway_token>
  <payment_method>
    <token>PtsqhzimrxmMu554MO6J53ePoAX</token>
    <created_at type="dateTime">2016-11-28T20:57:48Z</created_at>
    <updated_at type="dateTime">2016-11-28T20:57:48Z</updated_at>
    <gateway_type>test</gateway_type>
    <storage_state>retained</storage_state>
    <third_party_token>test_vault:4111111111111111</third_party_token>
    <payment_method_type>third_party_token</payment_method_type>
    <errors>
    </errors>
  </payment_method>
  <basis_payment_method>
    <token>SGfqoRedhNDIS1ghtD6W2vMQFW3</token>
    <created_at type="dateTime">2016-11-28T19:03:07Z</created_at>
    <updated_at type="dateTime">2016-11-28T20:57:48Z</updated_at>
    <email nil="true"/>
    <data nil="true"/>
    <storage_state>retained</storage_state>
    <test type="boolean">true</test>
    <last_four_digits>1111</last_four_digits>
    <first_six_digits>411111</first_six_digits>
    <card_type>visa</card_type>
    <first_name>Sallie</first_name>
    <last_name>Morissette</last_name>
    <month type="integer">4</month>
    <year type="integer">2020</year>
    <address1 nil="true"/>
    <address2 nil="true"/>
    <city nil="true"/>
    <state nil="true"/>
    <zip nil="true"/>
    <country nil="true"/>
    <phone_number nil="true"/>
    <company nil="true"/>
    <full_name>Sallie Morissette</full_name>
    <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
    <shipping_address1 nil="true"/>
    <shipping_address2 nil="true"/>
    <shipping_city nil="true"/>
    <shipping_state nil="true"/>
    <shipping_zip nil="true"/>
    <shipping_country nil="true"/>
    <shipping_phone_number nil="true"/>
    <payment_method_type>credit_card</payment_method_type>
    <errors>
    </errors>
    <verification_value></verification_value>
    <number>XXXX-XXXX-XXXX-1111</number>
    <fingerprint nil="true"/>
  </basis_payment_method>
  <response>
    <success type="boolean">true</success>
    <message>Successful store</message>
    <avs_code nil="true"/>
    <avs_message nil="true"/>
    <cvv_code nil="true"/>
    <cvv_message nil="true"/>
    <pending type="boolean">false</pending>
    <result_unknown type="boolean">false</result_unknown>
    <error_code></error_code>
    <error_detail nil="true"/>
    <cancelled type="boolean">false</cancelled>
    <fraud_review nil="true"/>
    <created_at type="dateTime">2016-11-28T20:57:48Z</created_at>
    <updated_at type="dateTime">2016-11-28T20:57:48Z</updated_at>
  </response>
</transaction>

If you’d like to request any gateway_specific_fields or gateway_specific_response_fields, please email support@spreedly.com with your request and the gateway documentation for the fields of interest.