Class: Afterpay::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/afterpay/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total: , items: , consumer: , success_url: , cancel_url: , payment_type: ) ⇒ Address

Initializes an Order object

Parameters:

  • name (String)

    The name

  • line_1 (String)

    Address line 1

  • line_2 (String)

    optional Address line 2

  • suburb (String)

    optional Suburb

  • state (String)

    State

  • postcode (String)

    Postal code

  • country (String)

    optional country Code

  • phone (String|Number)

    The phone number



18
19
20
21
22
23
24
25
26
27
# File 'lib/afterpay/address.rb', line 18

def initialize(attributes = {})
  @name = attributes[:name]
  @line_1 = attributes[:line_1] || ""
  @line_2 = attributes[:line_2] || ""
  @suburb = attributes[:suburb] || ""
  @state = attributes[:state] || ""
  @postcode = attributes[:postcode]
  @country = attributes[:country] || "AU"
  @phone = attributes[:phone]
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def country
  @country
end

#line_1Object

Returns the value of attribute line_1.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def line_1
  @line_1
end

#line_2Object

Returns the value of attribute line_2.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def line_2
  @line_2
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def phone
  @phone
end

#postcodeObject

Returns the value of attribute postcode.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def postcode
  @postcode
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def state
  @state
end

#suburbObject

Returns the value of attribute suburb.



5
6
7
# File 'lib/afterpay/address.rb', line 5

def suburb
  @suburb
end

Class Method Details

.from_response(response) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/afterpay/address.rb', line 42

def self.from_response(response)
  return nil if response.nil?

  new(
    name: response[:name],
    line_1: response[:line1],
    line_2: response[:line2],
    suburb: response[:suburb],
    state: response[:state],
    postcode: response[:postcode],
    country: response[:countryCode],
    phone: response[:phoneNumber]
  )
end

Instance Method Details

#to_hashObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/afterpay/address.rb', line 29

def to_hash
  {
    name: name,
    line1: line_1,
    line2: line_2,
    suburb: suburb,
    state: state,
    postcode: postcode.to_s,
    countryCode: country,
    phoneNumber: phone.to_s
  }
end