-
Notifications
You must be signed in to change notification settings - Fork 195
/
address.rb
74 lines (60 loc) · 2.4 KB
/
address.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
67
68
69
70
71
72
73
74
module Braintree
# See http://www.braintreepaymentsolutions.com/docs/ruby/addresses/details
class Address
include BaseModule # :nodoc:
attr_reader :company, :country_name, :created_at, :customer_id, :extended_address, :first_name, :id,
:last_name, :locality, :postal_code, :region, :street_address, :updated_at,
:country_code_alpha2, :country_code_alpha3, :country_code_numeric
def self.create(attributes)
Configuration.gateway.address.create(attributes)
end
def self.create!(attributes)
return_object_or_raise(:address) { create(attributes) }
end
def self.delete(customer_or_customer_id, address_id)
Configuration.gateway.address.delete(customer_or_customer_id, address_id)
end
def self.find(customer_or_customer_id, address_id)
Configuration.gateway.address.find(customer_or_customer_id, address_id)
end
def self.update(customer_or_customer_id, address_id, attributes)
Configuration.gateway.address.update(customer_or_customer_id, address_id, attributes)
end
def self.update!(customer_or_customer_id, address_id, attributes)
return_object_or_raise(:address) { update(customer_or_customer_id, address_id, attributes) }
end
def initialize(gateway, attributes) # :nodoc:
@gateway = gateway
set_instance_variables_from_hash(attributes)
end
def ==(other) # :nodoc:
return false unless other.is_a?(Address)
id == other.id && customer_id == other.customer_id
end
# Deprecated. Use Braintree::Address.delete
def delete
warn "[DEPRECATED] delete as an instance method is deprecated. Please use Address.delete"
@gateway.address.delete(customer_id, self.id)
end
# Deprecated. Use Braintree::Address.update
def update(attributes)
warn "[DEPRECATED] update as an instance method is deprecated. Please use Address.update"
result = @gateway.address.update(customer_id, id, attributes)
if result.success?
copy_instance_variables_from_object result.address
end
result
end
# Deprecated. Use Braintree::Address.update!
def update!(attributes)
warn "[DEPRECATED] update! as an instance method is deprecated. Please use Address.update!"
return_object_or_raise(:address) { update(attributes) }
end
class << self
protected :new
end
def self._new(*args) # :nodoc:
self.new *args
end
end
end