Class: AuthorizeNet::CreditCard

Inherits:
Object
  • Object
show all
Defined in:
lib/authorize_net/payment_methods/credit_card.rb

Overview

Models a credit card.

Constant Summary collapse

PAYMENT_METHOD_CODE =
AuthorizeNet::PaymentMethodType::CREDIT_CARD
@@option_defaults =

The option defaults for the constructor.

{
  :card_code => nil,
  :card_type => nil
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card_number, expiration, options = {}) ⇒ CreditCard

Constructs a new credit card object. Takes a credit card number and an expiration date. The CCV code can be passed as an option. So can the data tracks (1 & 2). When passing in data tracks, please pass the whole track. Sentinels and the LRC will be removed by the SDK. Track data must be passed along as ASCII. The raw bit stream from the card is not acceptable.

Field separators on

card_number

The credit card number as a string.

expiration

The credit card expiration date as a string with format MMYY.

options

A hash of options.

Options

card_code

Sets the CCV code for the credit card.

card_type

Sets the type of card (Visa, MasterCard, Dinners Club, etc.)

track_1

Sets the track 1 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change).

track_2

Sets the track 2 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change).



39
40
41
42
43
44
45
46
47
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 39

def initialize(card_number, expiration, options = {})
  @card_number = card_number
  @expiration = expiration
  options = @@option_defaults.merge(options)
  @card_code = options[:card_code]
  @card_type = options[:card_type]
  @track_1 = options[:track_1]
  @track_2 = options[:track_2]
end

Instance Attribute Details

#card_codeObject

Returns the value of attribute card_code.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def card_code
  @card_code
end

#card_numberObject

Returns the value of attribute card_number.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def card_number
  @card_number
end

#card_typeObject

Returns the value of attribute card_type.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def card_type
  @card_type
end

#expirationObject

Returns the value of attribute expiration.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def expiration
  @expiration
end

#track_1Object

Returns the value of attribute track_1.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def track_1
  @track_1
end

#track_2Object

Returns the value of attribute track_2.



18
19
20
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 18

def track_2
  @track_2
end

Instance Method Details

#to_hashObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 49

def to_hash
  Hash.new.tap do |ch|
    ch[:method] = PAYMENT_METHOD_CODE
    ch[:card_num] = @card_number
    ch[:exp_date] = @expiration
    ch[:card_code] = @card_code if @card_code
    ch[:track1] = @track_1.match(/(%|^)(.*?)(\?|$)/)[2] if @track_1
    ch[:track2] = @track_2.match(/(;|^)(.*?)(\?|$)/)[2] if @track_2
    #ch[:track1] = @track_1.match(/^%(?<fc>.)(?<p>[\d]{1,19}+)\^(?<n>.{2,26})\^(?<e>[\d]{0,4}|\^)(?<sc>[\d]{0,3}|\^)(?<dd>.*)\?\Z/) if @track_1
    #ch[:track2] = @track_2.match(/\A;(?<pan>[\d]{1,19}+)=(?<expiration>[\d]{0,4}|=)(?<service_code>[\d]{0,3}|=)(?<discretionary_data>.*)\?\Z/) if @track_2
  end
end