Class: UpsPickup::Shipper

Inherits:
Object
  • Object
show all
Defined in:
lib/ups_pickup/shipper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Shipper

options=>:card_address=>{:state=>,:city=>,…} Valid Card Type values are : 01 = American Express 03 = Discover 04 = Mastercard 06 = VISA



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ups_pickup/shipper.rb', line 11

def initialize(options={})
  @account_number = options[:account_number]
  @account_country_code = options[:account_country_code] || "US"
  @card_hoder_name = options[:card_hoder_name]
  # TODO Validate card type  01 = American Express 03 = Discover 04 = Mastercard  06 = VISA
  # if country code is US and payment method is 3
  @card_type = options[:card_type]
  @card_number = options[:card_number]
  @expiration_date = options[:expiration_date]
  @security_code = options[:security_code]
  @card_address = UpsPickup::Address.new(options[:card_address])
  #TODO raise an exception for payment method
  @payment_method = options[:payment_method] if !options[:payment_method].nil? && [0,1,2,3,4,5].include?(options[:payment_method].to_i)
  @payment_method ||="00"
end

Instance Attribute Details

#account_country_codeObject

Returns the value of attribute account_country_code.



3
4
5
# File 'lib/ups_pickup/shipper.rb', line 3

def 
  @account_country_code
end

#account_numberObject

Returns the value of attribute account_number.



3
4
5
# File 'lib/ups_pickup/shipper.rb', line 3

def 
  @account_number
end

#card_addressObject

Returns the value of attribute card_address.



4
5
6
# File 'lib/ups_pickup/shipper.rb', line 4

def card_address
  @card_address
end

#card_hoder_nameObject

Returns the value of attribute card_hoder_name.



3
4
5
# File 'lib/ups_pickup/shipper.rb', line 3

def card_hoder_name
  @card_hoder_name
end

#card_numberObject

Returns the value of attribute card_number.



3
4
5
# File 'lib/ups_pickup/shipper.rb', line 3

def card_number
  @card_number
end

#card_typeObject

Returns the value of attribute card_type.



3
4
5
# File 'lib/ups_pickup/shipper.rb', line 3

def card_type
  @card_type
end

#expiration_dateObject

Returns the value of attribute expiration_date.



4
5
6
# File 'lib/ups_pickup/shipper.rb', line 4

def expiration_date
  @expiration_date
end

#payment_methodObject

Returns the value of attribute payment_method.



4
5
6
# File 'lib/ups_pickup/shipper.rb', line 4

def payment_method
  @payment_method
end

#security_codeObject

Returns the value of attribute security_code.



4
5
6
# File 'lib/ups_pickup/shipper.rb', line 4

def security_code
  @security_code
end

Instance Method Details

#to_ups_hashObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ups_pickup/shipper.rb', line 27

def to_ups_hash
  
  if @payment_method.to_i == 3
    {
     "ns2:Account"=>{
      "AccountNumber"=>@account_number,
      "AccountCountryCode"=>@account_country_code
      },
    "ns2:ChargeCard"=>{
      "ns2:CardType"=>@card_type,
      "ns2:CardNumber"=>@card_number,
      "ns2:ExpirationDate"=>@expiration_date,
      "ns2:SecurityCode"=>@security_code,
      "ns2:CardAddress"=>{
        "ns2:AddressLine"=>@card_address.to_ups_hash
        } 
      }
    }
  else
    {
     "ns2:Account"=>{
      "ns2:AccountNumber"=>@account_number,
      "ns2:AccountCountryCode"=>@account_country_code
      }
    }  
  end  

end