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
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/authorize_net/payment_methods/credit_card.rb', line 49

def to_hash
  hash = {
    :method => PAYMENT_METHOD_CODE,
    :card_num => @card_number,
    :exp_date => @expiration
  }
  hash[:card_code] = @card_code unless @card_code.nil?
  unless @track_1.nil?
    track_1 = @track_1
    if track_1[0..0] == '%'
      track_1 = track_1[1..(@track_1.rindex('?') - 1)]
    end
    hash[:track1] = track_1
  end
  unless @track_2.nil?
    track_2 = @track_2
    if track_2[0..0] == ';'
      track_2 = track_2[1..(@track_2.rindex('?') - 1)]
    end
    hash[:track2] = track_2
  end
  hash
end