-
Notifications
You must be signed in to change notification settings - Fork 22
Address
[:company, :country_code_numeric, :customer_id, :extended_address, :first_name, :id, :last_name, :locality, :postal_code, :region, :street_address]
[:company, :country_code_numeric, :extended_address, :first_name, :last_name, :locality, :postal_code, :region, :street_address]
[:country_code_alpha2, :country_code_alpha3, :country_name, :created_at, :updated_at]
address = BraintreeRails::Address.find('customer_id', 'address_id')
address.customer # Loaded from customer_id for persisted addresses.
[:customer_id, :presence => true, :on => :create],
[:first_name, :last_name, :company, :street_address, :extended_address, :locality, :region, :length => {:maximum => 255}],
[:country_code_numeric, :allow_blank => true, :inclusion => { :in => Braintree::Address::CountryNames.map {|country| country[3]} }],
[:street_address, :presence => true, :if => Proc.new { Configuration.require_street_address }],
[:postal_code, :presence => true, :format => { :with => /\A[- a-z0-9]+\z/i}, :if => Proc.new { Configuration.require_postal_code }]
You might noticed that the default validations only checked the :country_code_numeric
attribute instead of
all 4 country name related attributes.
That is because BraintreeRails added a little code that will automatically set :country_code_numeric
when any of the other three are set. This way, the validation logic and the final API call will be much simpler.
(before|after)_validate
(before|around|after)_save
(before|around|after)_create
(before|around|after)_update
(before|around|after)_destroy
def full_name
"#{first_name} #{last_name}".strip
end
Due to the braintree_ruby's API, unlike all other models, BraintreeRaials::Address.find(customer_id, address_id)
takes an extra customer_id to find an given address.
Due to the braintree_ruby's API, unlike all other models, BraintreeRaials::Address.delete(customer_id, address_id)
takes an extra customer_id to delete an given address.
The instance destroy, BraintreeRails::Address#destroy
does not need this extra customer_id.