Class: EwayRapid::Message::Convert::CustomerToInternalCustomer

Inherits:
Object
  • Object
show all
Defined in:
lib/eway_rapid/message/convert/customer_to_internal_customer.rb

Instance Method Summary collapse

Constructor Details

#initialize(is_merge_card_info = nil) ⇒ CustomerToInternalCustomer

Returns a new instance of CustomerToInternalCustomer.



7
8
9
# File 'lib/eway_rapid/message/convert/customer_to_internal_customer.rb', line 7

def initialize(is_merge_card_info = nil)
  @merge_card_detail_to_this = is_merge_card_info unless is_merge_card_info.nil?
end

Instance Method Details

#do_convert(customer) ⇒ InternalModels::Customer

Parameters:

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/eway_rapid/message/convert/customer_to_internal_customer.rb', line 13

def do_convert(customer)
  i_customer = InternalModels::Customer.new
  if customer
    i_customer.phone = customer.phone
    i_customer.reference = customer.reference
    i_customer.token_customer_id = customer.token_customer_id
    i_customer.comments = customer.comments
    i_customer.mobile = customer.mobile
    i_customer.title = customer.title
    i_customer.fax = customer.fax
    i_customer.customer_device_ip = customer.customer_device_ip
    i_customer.email = customer.email

    # @type [Models::CardDetails]
    card_details = customer.card_details
    i_customer.card_details = card_details

    if card_details && @merge_card_detail_to_this
      i_customer.card_start_month = card_details.start_month
      i_customer.card_start_year = card_details.start_year
      i_customer.card_issue_number = card_details.issue_number
      i_customer.card_name = card_details.name
      i_customer.card_number = card_details.number
      begin
        i_customer.card_expiry_year = Integer(card_details.expiry_year)
      rescue
        raise ArgumentError.new 'Invalid expiry year in card details'
      end
      begin
        i_customer.card_expiry_month = Integer(card_details.expiry_month)
      rescue
        raise ArgumentError.new 'Invalid expiry month param in card details'
      end
    end

    i_customer.company_name = customer.company_name
    i_customer.url = customer.url
    i_customer.first_name = customer.first_name
    i_customer.last_name = customer.last_name

    # @type [Models::Address]
    cus_address = customer.address
    if cus_address
      i_customer.state = cus_address.state
      i_customer.postal_code = cus_address.postal_code
      i_customer.country = cus_address.country
      i_customer.city = cus_address.city
      i_customer.street1 = cus_address.street1
      i_customer.street2 = cus_address.street2
    end
    i_customer.job_description = customer.job_description
  end
  i_customer
end