Class: AbtainBilling::Billing::AuthorizeNetCimGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/abtain_billing/billing/gateways/authorize_net_cim.rb

Overview

Customer Information Manager (CIM)

The Authorize.Net Customer Information Manager (CIM) is an optional additional service that allows you to store sensitive payment information on Authorize.Net’s servers, simplifying payments for returning customers and recurring transactions. It can also help with Payment Card Industry (PCI) Data Security Standard compliance, since customer data is no longer stored locally.

To use the AuthorizeNetCimGateway CIM must be enabled for your account.

Information about CIM is available on the Authorize.Net website. Information about the CIM API is available at the Authorize.Net Integration Center

Login and Password

The login and password are not the username and password you use to login to the Authorize.Net Merchant Interface. Instead, you will use the API Login ID as the login and Transaction Key as the password.

How to Get Your API Login ID and Transaction Key

  1. Log into the Merchant Interface

  2. Select Settings from the Main Menu

  3. Click on API Login ID and Transaction Key in the Security section

  4. Type in the answer to the secret question configured on setup

  5. Click Submit

Constant Summary collapse

AUTHORIZE_NET_CIM_NAMESPACE =
'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
CIM_ACTIONS =
{
  :create_customer_profile => 'createCustomerProfile',
  :create_customer_payment_profile => 'createCustomerPaymentProfile',
  :create_customer_shipping_address => 'createCustomerShippingAddress',
  :get_customer_profile => 'getCustomerProfile',
  :get_customer_profile_ids => 'getCustomerProfileIds',
  :get_customer_payment_profile => 'getCustomerPaymentProfile',
  :get_customer_shipping_address => 'getCustomerShippingAddress',
  :delete_customer_profile => 'deleteCustomerProfile',
  :delete_customer_payment_profile => 'deleteCustomerPaymentProfile',
  :delete_customer_shipping_address => 'deleteCustomerShippingAddress',
  :update_customer_profile => 'updateCustomerProfile',
  :update_customer_payment_profile => 'updateCustomerPaymentProfile',
  :update_customer_shipping_address => 'updateCustomerShippingAddress',
  :create_customer_profile_transaction => 'createCustomerProfileTransaction',
  :validate_customer_payment_profile => 'validateCustomerPaymentProfile'
}
CIM_TRANSACTION_TYPES =
{
  :auth_capture => 'profileTransAuthCapture',
  :auth_only => 'profileTransAuthOnly',
  :capture_only => 'profileTransCaptureOnly'
}
CIM_VALIDATION_MODES =
{
  :none => 'none',
  :test => 'testMode',
  :live => 'liveMode'
}
BANK_ACCOUNT_TYPES =
{
  :checking => 'checking',
  :savings => 'savings',
  :business_checking => 'businessChecking'
}
ECHECK_TYPES =
{
  :ccd => 'CCD',
  :ppd => 'PPD'
}

Constants inherited from Gateway

Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

Constructor Details

#initialize(options = {}) ⇒ AuthorizeNetCimGateway

Creates a new AuthorizeNetCimGateway

The gateway requires that a valid API Login ID and Transaction Key be passed in the options hash.

Options

  • :login – The Authorize.Net API Login ID (REQUIRED)

  • :password – The Authorize.Net Transaction Key. (REQUIRED)

  • :testtrue or false. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.



97
98
99
100
101
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 97

def initialize(options = {})
  requires!(options, :login, :password)
  @options = options
  super
end

Instance Method Details

#create_customer_payment_profile(options) ⇒ Object

Creates a new customer payment profile for an existing customer profile.

Options

  • :customer_profile_id – The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)

  • :payment_profile – A hash containing the elements of the new payment profile (REQUIRED)

Payment Profile

  • :payment – A hash containing information on payment. Either :credit_card or :bank_account (REQUIRED)



186
187
188
189
190
191
192
193
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 186

def create_customer_payment_profile(options)
  requires!(options, :customer_profile_id)
  requires!(options, :payment_profile)
  requires!(options[:payment_profile], :payment)
  
  request = build_request(:create_customer_payment_profile, options)
  commit(:create_customer_payment_profile, request)
end

#create_customer_profile(options) ⇒ Object

Creates a new customer profile along with any customer payment profiles and customer shipping addresses for the customer profile.

Returns a Response with the Customer Profile ID of the new customer profile in the authorization field. It is CRITICAL that you save this ID. There is no way to retrieve this through the API. You will not be able to create another Customer Profile with the same information.

Options

TODO



170
171
172
173
174
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 170

def create_customer_profile(options)
  # TODO Add requires
  request = build_request(:create_customer_profile, options)
  commit(:create_customer_profile, request)
end

#create_customer_profile_transaction(options) ⇒ Object

Creates a new payment transaction from an existing customer profile

This is what is used to charge a customer whose information you have stored in a Customer Profile.

Returns a Response object that contains the result of the transaction in params['direct_response']

Options

  • :transaction – A hash containing information on the transaction that is being requested. (REQUIRED)

Transaction

  • :type – The type of transaction. Can be either :auth_only, :capture_only, or :auth_capture. (REQUIRED)

  • :amount – The amount for the tranaction. Formatted with a decimal. For example “4.95” (REQUIRED)

  • :customer_profile_id – The Customer Profile ID of the customer to use in this transaction. (REQUIRED)

  • :customer_payment_profile_id – The Customer Payment Profile ID of the Customer Payment Profile to use in this transaction. (REQUIRED)



388
389
390
391
392
393
394
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 388

def create_customer_profile_transaction(options)
  requires!(options, :transaction)
  requires!(options[:transaction], :type, :amount, :customer_profile_id, :customer_payment_profile_id)

  request = build_request(:create_customer_profile_transaction, options)
  commit(:create_customer_profile_transaction, request)
end

#create_customer_shipping_address(options) ⇒ Object

Creates a new customer shipping address for an existing customer profile.

Options

  • :customer_profile_id – The Customer Profile ID of the customer the payment profile will be added to. (REQUIRED)

  • :address – A hash containing the elements of the shipping address (REQUIRED)



201
202
203
204
205
206
207
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 201

def create_customer_shipping_address(options)
  requires!(options, :customer_profile_id)
  requires!(options, :address)
  
  request = build_request(:create_customer_shipping_address, options)
  commit(:create_customer_shipping_address, request)
end

#delete_customer_payment_profile(options) ⇒ Object

Deletes a customer payment profile from an existing customer profile.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)

  • :customer_payment_profile_id – The Payment Profile ID of the payment profile to be deleted. (REQUIRED)



227
228
229
230
231
232
233
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 227

def delete_customer_payment_profile(options)
  requires!(options, :customer_profile_id)
  requires!(options, :customer_payment_profile_id)

  request = build_request(:delete_customer_payment_profile, options)
  commit(:delete_customer_payment_profile, request)
end

#delete_customer_profile(options) ⇒ Object

Deletes an existing customer profile along with all associated customer payment profiles and customer shipping addresses.

Options

  • :customer_profile_id – The Customer Profile ID of the customer to be deleted. (REQUIRED)



214
215
216
217
218
219
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 214

def delete_customer_profile(options)
  requires!(options, :customer_profile_id)

  request = build_request(:delete_customer_profile, options)
  commit(:delete_customer_profile, request)
end

#delete_customer_shipping_address(options) ⇒ Object

Deletes a customer shipping address from an existing customer profile.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be deleted. (REQUIRED)

  • :customer_address_id – The Shipping Address ID of the shipping address to be deleted. (REQUIRED)



241
242
243
244
245
246
247
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 241

def delete_customer_shipping_address(options)
  requires!(options, :customer_profile_id)
  requires!(options, :customer_address_id)

  request = build_request(:delete_customer_shipping_address, options)
  commit(:delete_customer_shipping_address, request)
end

#get_customer_payment_profile(options) ⇒ Object

Retrieve a customer payment profile for an existing customer profile.

Returns a Response whose params hash contains all the payment profile information. Sensitive information such as credit card numbers will be masked.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)

  • :customer_payment_profile_id – The Payment Profile ID of the payment profile to be retrieved. (REQUIRED)



283
284
285
286
287
288
289
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 283

def get_customer_payment_profile(options)
  requires!(options, :customer_profile_id)
  requires!(options, :customer_payment_profile_id)

  request = build_request(:get_customer_payment_profile, options)
  commit(:get_customer_payment_profile, request)
end

#get_customer_profile(options) ⇒ Object

Retrieves an existing customer profile along with all the associated customer payment profiles and customer shipping addresses.

Returns a Response whose params hash contains all the profile information.

Options

  • :customer_profile_id – The Customer Profile ID of the customer to retrieve. (REQUIRED)



256
257
258
259
260
261
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 256

def get_customer_profile(options)
  requires!(options, :customer_profile_id)

  request = build_request(:get_customer_profile, options)
  commit(:get_customer_profile, request)
end

#get_customer_profile_idsObject

Retrieves a list of all Customer Profile IDs from the gateway

The response’s params contains the list of Customer Profile IDs

Options - none



269
270
271
272
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 269

def get_customer_profile_ids
  request = build_request(:get_customer_profile_ids)
  commit(:get_customer_profile_ids, request)
end

#get_customer_shipping_address(options) ⇒ Object

Retrieve a customer shipping address for an existing customer profile.

Returns a Response whose params hash contains all the shipping address information.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be retrieved. (REQUIRED)

  • :customer_address_id – The Shipping Address ID of the shipping address to be retrieved. (REQUIRED)



299
300
301
302
303
304
305
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 299

def get_customer_shipping_address(options)
  requires!(options, :customer_profile_id)
  requires!(options, :customer_address_id)

  request = build_request(:get_customer_shipping_address, options)
  commit(:get_customer_shipping_address, request)
end

#purchase(money, billing_id) ⇒ Object

Run an auth and capture transaction against the stored CC



147
148
149
150
151
152
153
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 147

def purchase(money, billing_id)
  if (response = get_customer_profile(:customer_profile_id => billing_id)).success?
    create_customer_profile_transaction(:transaction => { :customer_profile_id => billing_id, :customer_payment_profile_id => response.params['profile']['payment_profiles']['customer_payment_profile_id'], :type => :auth_capture, :amount => amount(money) })
  else
    response
  end
end

#store(creditcard, options = {}) ⇒ Object

Create a payment profile



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 107

def store(creditcard, options = {})
  profile = {
    :payment_profiles => {
      :payment => { :credit_card => creditcard }
    }
  }
  profile[:payment_profiles][:bill_to] = options[:billing_address] if options[:billing_address]
  profile[:ship_to_list] = options[:shipping_address] if options[:shipping_address]

  # CIM actually does require a unique ID to be passed in, 
  # either merchant_customer_id or email, so generate it, if necessary
  if options[:billing_id]
    profile[:merchant_customer_id] = options[:billing_id]
  elsif options[:email]
    profile[:email] = options[:email]
  else
    profile[:merchant_customer_id] = Digest::SHA1.hexdigest("#{creditcard.number}#{Time.now.to_i}").first(20)
  end

  create_customer_profile(:profile => profile)
end

#unstore(billing_id) ⇒ Object

Destroy a customer profile



156
157
158
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 156

def unstore(billing_id)
  delete_customer_profile(:customer_profile_id => billing_id)
end

#update(billing_id, creditcard, options = {}) ⇒ Object

Update an existing payment profile



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 130

def update(billing_id, creditcard, options = {})
  if (response = get_customer_profile(:customer_profile_id => billing_id)).success?
    update_customer_payment_profile(
      :customer_profile_id => billing_id,
      :payment_profile => {
        :customer_payment_profile_id => response.params['profile']['payment_profiles']['customer_payment_profile_id'],
        :payment => {
          :credit_card => creditcard
        }
      }.merge(options[:billing_address] ? {:bill_to => options[:billing_address]} : {})
    )
  else
    response
  end
end

#update_customer_payment_profile(options) ⇒ Object

Updates a customer payment profile for an existing customer profile.

Warning: if you do not provide a parameter in the :payment_profile hash, it is automatically set to nil at Authorize.Net. You will most likely want to first get the profile hash using get_customer_payment_profile and then only change the elements you wish to change.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)

  • :payment_profile – A hash containing the values the Customer Payment Profile should be updated to. (REQUIRED)

Payment Profile

  • :customer_payment_profile_id – The Customer Payment Profile ID of the Customer Payment Profile to update. (REQUIRED)



342
343
344
345
346
347
348
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 342

def update_customer_payment_profile(options)
  requires!(options, :customer_profile_id, :payment_profile)
  requires!(options[:payment_profile], :customer_payment_profile_id)

  request = build_request(:update_customer_payment_profile, options)
  commit(:update_customer_payment_profile, request)
end

#update_customer_profile(options) ⇒ Object

Updates an existing customer profile.

Warning: if you do not provide a parameter in the :payment_profile hash, it is automatically set to nil at Authorize.Net. You will most likely want to first get the profile hash using get_customer_profile and then only change the elements you wish to change.

Options

  • :profile – A hash containing the values the Customer Profile should be updated to. (REQUIRED)

Profile

  • :customer_profile_id – The Customer Profile ID of the customer profile to update. (REQUIRED)



320
321
322
323
324
325
326
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 320

def update_customer_profile(options)
  requires!(options, :profile)
  requires!(options[:profile], :customer_profile_id)

  request = build_request(:update_customer_profile, options)
  commit(:update_customer_profile, request)
end

#update_customer_shipping_address(options) ⇒ Object

Updates a customer shipping address for an existing customer profile.

Warning: if you do not provide a parameter in the :address hash, it is automatically set to nil at Authorize.Net. You will most likely want to first get the profile hash using get_customer_shipping_address and then only change the elements you wish to change.

Options

  • :customer_profile_id – The Customer Profile ID of the customer with the payment profile to be updated. (REQUIRED)

  • :address – A hash containing the values the Customer Shipping Address should be updated to. (REQUIRED)

Address

  • :customer_address_id – The Customer Address ID of the Customer Payment Profile to update. (REQUIRED)



364
365
366
367
368
369
370
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 364

def update_customer_shipping_address(options)
  requires!(options, :customer_profile_id, :address)
  requires!(options[:address], :customer_address_id)

  request = build_request(:update_customer_shipping_address, options)
  commit(:update_customer_shipping_address, request)
end

#validate_customer_payment_profile(options) ⇒ Object

Verifies an existing customer payment profile by generating a test transaction

Returns a Response object that contains the result of the transaction in params['direct_response']

Options

  • :customer_profile_id – The Customer Profile ID of the customer to use in this transaction. (REQUIRED)

  • :customer_payment_profile_id – The Customer Payment Profile ID of the Customer Payment Profile to be verified. (REQUIRED)

  • :customer_address_id – The Customer Address ID of the Customer Shipping Address to be verified.

  • :validation_mode:live or :test In Test Mode, only field validation is performed. In Live Mode, a transaction is generated and submitted to the processor with the amount of $0.01. If successful, the transaction is immediately voided. (REQUIRED)



407
408
409
410
411
412
# File 'lib/abtain_billing/billing/gateways/authorize_net_cim.rb', line 407

def validate_customer_payment_profile(options)
  requires!(options, :customer_profile_id, :customer_payment_profile_id, :validation_mode)

  request = build_request(:validate_customer_payment_profile, options)
  commit(:validate_customer_payment_profile, request)
end