Class: SolidusBraintree::Address
- Inherits:
-
Object
- Object
- SolidusBraintree::Address
- Defined in:
- app/models/solidus_braintree/address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #firstname ⇒ Object
-
#initialize(spree_address) ⇒ Address
constructor
A new instance of Address.
- #lastname ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(spree_address) ⇒ Address
Returns a new instance of Address.
19 20 21 |
# File 'app/models/solidus_braintree/address.rb', line 19 def initialize(spree_address) @spree_address = spree_address end |
Class Method Details
.split_name(name) ⇒ Object
14 15 16 17 |
# File 'app/models/solidus_braintree/address.rb', line 14 def self.split_name(name) address_name = Spree::Address::Name.new(name) [address_name.first_name, address_name.last_name].compact end |
Instance Method Details
#firstname ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/models/solidus_braintree/address.rb', line 40 def firstname if SolidusSupport.combined_first_and_last_name_in_address? self.class.split_name(spree_address.name).first else spree_address.firstname end end |
#lastname ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/models/solidus_braintree/address.rb', line 48 def lastname if SolidusSupport.combined_first_and_last_name_in_address? self.class.split_name(spree_address.name).last else spree_address.lastname end end |
#to_json(*_args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/solidus_braintree/address.rb', line 23 def to_json(*_args) address_hash = { line1: address1, line2: address2, city: city, postalCode: zipcode, countryCode: country.iso, phone: phone, recipientName: "#{firstname} #{lastname}" } if ::Spree::Config.address_requires_state && country.states_required address_hash[:state] = state.name end address_hash.to_json end |