braintree 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. data/README.rdoc +4 -0
  2. data/lib/braintree.rb +43 -32
  3. data/lib/braintree/add_on.rb +4 -0
  4. data/lib/braintree/address.rb +18 -72
  5. data/lib/braintree/address_gateway.rb +76 -0
  6. data/lib/braintree/advanced_search.rb +31 -13
  7. data/lib/braintree/base_module.rb +6 -0
  8. data/lib/braintree/configuration.rb +57 -39
  9. data/lib/braintree/credit_card.rb +75 -129
  10. data/lib/braintree/credit_card_gateway.rb +133 -0
  11. data/lib/braintree/credit_card_verification.rb +8 -0
  12. data/lib/braintree/customer.rb +70 -123
  13. data/lib/braintree/customer_gateway.rb +121 -0
  14. data/lib/braintree/digest.rb +2 -2
  15. data/lib/braintree/discount.rb +4 -0
  16. data/lib/braintree/error_codes.rb +50 -5
  17. data/lib/braintree/error_result.rb +4 -18
  18. data/lib/braintree/errors.rb +1 -2
  19. data/lib/braintree/exceptions.rb +11 -16
  20. data/lib/braintree/gateway.rb +39 -0
  21. data/lib/braintree/http.rb +30 -26
  22. data/lib/braintree/modification.rb +23 -0
  23. data/lib/braintree/resource_collection.rb +1 -1
  24. data/lib/braintree/subscription.rb +29 -129
  25. data/lib/braintree/subscription_gateway.rb +122 -0
  26. data/lib/braintree/subscription_search.rb +6 -7
  27. data/lib/braintree/successful_result.rb +1 -12
  28. data/lib/braintree/test/credit_card_numbers.rb +4 -2
  29. data/lib/braintree/test/transaction_amounts.rb +3 -0
  30. data/lib/braintree/transaction.rb +83 -243
  31. data/lib/braintree/transaction/credit_card_details.rb +4 -4
  32. data/lib/braintree/transaction_gateway.rb +124 -0
  33. data/lib/braintree/transaction_search.rb +5 -3
  34. data/lib/braintree/transparent_redirect.rb +19 -112
  35. data/lib/braintree/transparent_redirect_gateway.rb +105 -0
  36. data/lib/braintree/util.rb +4 -0
  37. data/lib/braintree/validation_error.rb +1 -0
  38. data/lib/braintree/validation_error_collection.rb +5 -23
  39. data/lib/braintree/version.rb +2 -2
  40. data/lib/braintree/xml/parser.rb +1 -1
  41. data/lib/braintree/xml/rexml.rb +2 -2
  42. data/spec/integration/braintree/advanced_search_spec.rb +532 -0
  43. data/spec/integration/braintree/credit_card_spec.rb +5 -8
  44. data/spec/integration/braintree/http_spec.rb +53 -39
  45. data/spec/integration/braintree/subscription_spec.rb +678 -213
  46. data/spec/integration/braintree/transaction_search_spec.rb +318 -43
  47. data/spec/integration/braintree/transaction_spec.rb +134 -3
  48. data/spec/integration/braintree/transparent_redirect_spec.rb +1 -1
  49. data/spec/spec_helper.rb +55 -4
  50. data/spec/unit/braintree/address_spec.rb +8 -8
  51. data/spec/unit/braintree/base_module_spec.rb +1 -1
  52. data/spec/unit/braintree/configuration_spec.rb +34 -29
  53. data/spec/unit/braintree/credit_card_spec.rb +14 -12
  54. data/spec/unit/braintree/credit_card_verification_spec.rb +16 -0
  55. data/spec/unit/braintree/customer_spec.rb +10 -8
  56. data/spec/unit/braintree/digest_spec.rb +8 -17
  57. data/spec/unit/braintree/error_result_spec.rb +12 -2
  58. data/spec/unit/braintree/http_spec.rb +2 -2
  59. data/spec/unit/braintree/subscription_search_spec.rb +77 -0
  60. data/spec/unit/braintree/subscription_spec.rb +16 -8
  61. data/spec/unit/braintree/transaction_spec.rb +17 -12
  62. data/spec/unit/braintree/transparent_redirect_spec.rb +12 -12
  63. data/spec/unit/braintree/util_spec.rb +24 -0
  64. data/spec/unit/braintree/xml/parser_spec.rb +1 -1
  65. data/spec/unit/braintree_spec.rb +1 -1
  66. metadata +16 -5
@@ -1,147 +1,123 @@
1
1
  module Braintree
2
- # == More Information
3
- #
4
- # For more detailed documentation on Customers, see http://www.braintreepaymentsolutions.com/gateway/customer-api
2
+ # See http://www.braintreepaymentsolutions.com/docs/ruby
5
3
  class Customer
6
4
  include BaseModule
7
5
 
8
6
  attr_reader :addresses, :company, :created_at, :credit_cards, :email, :fax, :first_name, :id, :last_name,
9
7
  :phone, :updated_at, :website, :custom_fields
10
8
 
11
- # Returns a ResourceCollection of all customers stored in the vault.
12
- #
13
- # customers = Braintree::Customer.all
14
- # customers.each do |customer|
15
- # puts "Customer #{customer.id} email is #{customer.email}"
16
- # end
9
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/search
17
10
  def self.all
18
- response = Http.post "/customers/advanced_search_ids"
19
- ResourceCollection.new(response) { |ids| _fetch_customers(ids) }
20
- end
21
-
22
- def self._fetch_customers(ids)
23
- response = Http.post "/customers/advanced_search", {:search => {:ids => ids}}
24
- attributes = response[:customers]
25
- Util.extract_attribute_as_array(attributes, :customer).map { |attrs| _new(attrs) }
11
+ Configuration.gateway.customer.all
26
12
  end
27
13
 
28
- # Creates a customer using the given +attributes+. If <tt>:id</tt> is not passed,
29
- # the gateway will generate it.
30
- #
31
- # result = Braintree::Customer.create(
32
- # :first_name => "John",
33
- # :last_name => "Smith",
34
- # :company => "Smith Co.",
35
- # :email => "john@smith.com",
36
- # :website => "www.smithco.com",
37
- # :fax => "419-555-1234",
38
- # :phone => "614-555-1234"
39
- # )
40
- # if result.success?
41
- # puts "Created customer #{result.customer.id}
42
- # else
43
- # puts "Could not create customer, see result.errors"
44
- # end
14
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/create
45
15
  def self.create(attributes = {})
46
- Util.verify_keys(_create_signature, attributes)
47
- _do_create "/customers", :customer => attributes
16
+ Configuration.gateway.customer.create(attributes)
48
17
  end
49
18
 
19
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/create
50
20
  def self.create!(attributes = {})
51
21
  return_object_or_raise(:customer) { create(attributes) }
52
22
  end
53
23
 
24
+ # Deprecated. Use Braintree::TransparentRedirect.url
25
+ #
26
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/create_tr
54
27
  def self.create_customer_url
55
28
  warn "[DEPRECATED] Customer.create_customer_url is deprecated. Please use TransparentRedirect.url"
56
- "#{Braintree::Configuration.base_merchant_url}/customers/all/create_via_transparent_redirect_request"
29
+ Configuration.gateway.customer.create_customer_url
57
30
  end
58
31
 
32
+ # Deprecated. Use Braintree::TransparentRedirect.confirm
33
+ #
34
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/create_tr
59
35
  def self.create_from_transparent_redirect(query_string)
60
36
  warn "[DEPRECATED] Customer.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
61
- params = TransparentRedirect.parse_and_validate_query_string query_string
62
- _do_create("/customers/all/confirm_transparent_redirect_request", :id => params[:id])
37
+ Configuration.gateway.customer.create_from_transparent_redirect(query_string)
63
38
  end
64
39
 
40
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
65
41
  def self.credit(customer_id, transaction_attributes)
66
42
  Transaction.credit(transaction_attributes.merge(:customer_id => customer_id))
67
43
  end
68
44
 
45
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
69
46
  def self.credit!(customer_id, transaction_attributes)
70
47
  return_object_or_raise(:transaction){ credit(customer_id, transaction_attributes) }
71
48
  end
72
49
 
50
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/delete
73
51
  def self.delete(customer_id)
74
- Http.delete("/customers/#{customer_id}")
75
- SuccessfulResult.new
52
+ Configuration.gateway.customer.delete(customer_id)
76
53
  end
77
54
 
55
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/search
78
56
  def self.find(customer_id)
79
- raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/
80
- raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
81
- response = Http.get("/customers/#{customer_id}")
82
- new(response[:customer])
83
- rescue NotFoundError
84
- raise NotFoundError, "customer with id #{customer_id.inspect} not found"
57
+ Configuration.gateway.customer.find(customer_id)
85
58
  end
86
59
 
60
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
87
61
  def self.sale(customer_id, transaction_attributes)
88
62
  Transaction.sale(transaction_attributes.merge(:customer_id => customer_id))
89
63
  end
90
64
 
65
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
91
66
  def self.sale!(customer_id, transaction_attributes)
92
- return_object_or_raise(:transaction){ sale(customer_id, transaction_attributes) }
67
+ return_object_or_raise(:transaction) { sale(customer_id, transaction_attributes) }
93
68
  end
94
69
 
95
70
  # Returns a ResourceCollection of transactions for the customer with the given +customer_id+.
96
71
  def self.transactions(customer_id, options = {})
97
- response = Http.post "/customers/#{customer_id}/transaction_ids"
98
- ResourceCollection.new(response) { |ids| _fetch_transactions(customer_id, ids) }
99
- end
100
-
101
- def self._fetch_transactions(customer_id, ids)
102
- response = Http.post "/customers/#{customer_id}/transactions", :search => {:ids => ids}
103
- attributes = response[:credit_card_transactions]
104
- Util.extract_attribute_as_array(attributes, :transaction).map do |transaction_attributes|
105
- Transaction._new transaction_attributes
106
- end
72
+ Configuration.gateway.customer.transactions(customer_id, options = {})
107
73
  end
108
74
 
75
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
109
76
  def self.update(customer_id, attributes)
110
- Util.verify_keys(_update_signature, attributes)
111
- _do_update(:put, "/customers/#{customer_id}", :customer => attributes)
77
+ Configuration.gateway.customer.update(customer_id, attributes)
112
78
  end
113
79
 
80
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
114
81
  def self.update!(customer_id, attributes)
115
82
  return_object_or_raise(:customer) { update(customer_id, attributes) }
116
83
  end
117
84
 
85
+ # Deprecated. Use Braintree::TransparentRedirect.url
86
+ #
87
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update_tr
118
88
  def self.update_customer_url
119
89
  warn "[DEPRECATED] Customer.update_customer_url is deprecated. Please use TransparentRedirect.url"
120
- "#{Braintree::Configuration.base_merchant_url}/customers/all/update_via_transparent_redirect_request"
90
+ Configuration.gateway.customer.update_customer_url
121
91
  end
122
92
 
93
+ # Deprecated. Use Braintree::TransparentRedirect.confirm
94
+ #
95
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update_tr
123
96
  def self.update_from_transparent_redirect(query_string)
124
97
  warn "[DEPRECATED] Customer.update_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
125
- params = TransparentRedirect.parse_and_validate_query_string(query_string)
126
- _do_update(:post, "/customers/all/confirm_transparent_redirect_request", :id => params[:id])
98
+ Configuration.gateway.customer.update_from_transparent_redirect(query_string)
127
99
  end
128
100
 
129
- def initialize(attributes) # :nodoc:
101
+ def initialize(gateway, attributes) # :nodoc:
102
+ @gateway = gateway
130
103
  set_instance_variables_from_hash(attributes)
131
- @credit_cards = (@credit_cards || []).map { |pm| CreditCard._new pm }
132
- @addresses = (@addresses || []).map { |addr| Address._new addr }
104
+ @credit_cards = (@credit_cards || []).map { |pm| CreditCard._new gateway, pm }
105
+ @addresses = (@addresses || []).map { |addr| Address._new gateway, addr }
133
106
  end
134
107
 
108
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
135
109
  def credit(transaction_attributes)
136
- Customer.credit(id, transaction_attributes)
110
+ @gateway.transaction.credit(transaction_attributes.merge(:customer_id => id))
137
111
  end
138
112
 
113
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
139
114
  def credit!(transaction_attributes)
140
115
  return_object_or_raise(:transaction) { credit(transaction_attributes) }
141
116
  end
142
117
 
118
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/delete
143
119
  def delete
144
- Customer.delete(id)
120
+ @gateway.customer.delete(id)
145
121
  end
146
122
 
147
123
  def inspect # :nodoc:
@@ -154,35 +130,48 @@ module Braintree
154
130
  "#<#{self.class} #{nice_attributes.join(', ')}>"
155
131
  end
156
132
 
133
+ # Deprecated. Use Braintree::Customer.sale
134
+ #
135
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
157
136
  def sale(transaction_attributes)
158
- Customer.sale(id, transaction_attributes)
137
+ warn "[DEPRECATED] sale as an instance method is deprecated. Please use CreditCard.sale"
138
+ @gateway.transaction.sale(transaction_attributes.merge(:customer_id => id))
159
139
  end
160
140
 
141
+ # Deprecated. Use Braintree::Customer.sale!
142
+ #
143
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
161
144
  def sale!(transaction_attributes)
145
+ warn "[DEPRECATED] sale! as an instance method is deprecated. Please use CreditCard.sale!"
162
146
  return_object_or_raise(:transaction) { sale(transaction_attributes) }
163
147
  end
164
148
 
165
149
  # Returns a ResourceCollection of transactions for the customer.
166
150
  def transactions(options = {})
167
- Customer.transactions(id, options)
151
+ @gateway.customer.transactions(id, options)
168
152
  end
169
153
 
154
+ # Deprecated. Use Braintree::Customer.update
155
+ #
156
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
170
157
  def update(attributes)
171
- response = Http.put "/customers/#{id}", :customer => attributes
172
- if response[:customer]
173
- set_instance_variables_from_hash response[:customer]
174
- SuccessfulResult.new(:customer => self)
175
- elsif response[:api_error_response]
176
- ErrorResult.new(response[:api_error_response])
177
- else
178
- raise "expected :customer or :errors"
158
+ warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update"
159
+ result = @gateway.customer.update(id, attributes)
160
+ if result.success?
161
+ copy_instance_variables_from_object result.customer
179
162
  end
163
+ result
180
164
  end
181
165
 
166
+ # Deprecated. Use Braintree::Customer.update!
167
+ #
168
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
182
169
  def update!(attributes)
170
+ warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!"
183
171
  return_object_or_raise(:customer) { update(attributes) }
184
172
  end
185
173
 
174
+ # Returns true if +other+ is a Customer with the same id
186
175
  def ==(other)
187
176
  return false unless other.is_a?(Customer)
188
177
  id == other.id
@@ -192,56 +181,14 @@ module Braintree
192
181
  protected :new
193
182
  end
194
183
 
195
- def self._attributes # :nodoc:
196
- [
197
- :addresses, :company, :credit_cards, :email, :fax, :first_name, :id, :last_name, :phone, :website,
198
- :created_at, :updated_at
199
- ]
200
- end
201
-
202
- def self._create_signature # :nodoc:
203
- credit_card_signature = CreditCard._create_signature - [:customer_id]
204
- [
205
- :company, :email, :fax, :first_name, :id, :last_name, :phone, :website,
206
- {:credit_card => credit_card_signature},
207
- {:custom_fields => :_any_key_}
208
- ]
209
- end
210
-
211
- def self._do_create(url, params=nil) # :nodoc:
212
- response = Http.post url, params
213
- if response[:customer]
214
- SuccessfulResult.new(:customer => new(response[:customer]))
215
- elsif response[:api_error_response]
216
- ErrorResult.new(response[:api_error_response])
217
- else
218
- raise "expected :customer or :api_error_response"
219
- end
220
- end
221
-
222
- def self._do_update(http_verb, url, params) # :nodoc:
223
- response = Http.send http_verb, url, params
224
- if response[:customer]
225
- SuccessfulResult.new(:customer => new(response[:customer]))
226
- elsif response[:api_error_response]
227
- ErrorResult.new(response[:api_error_response])
228
- else
229
- raise UnexpectedError, "expected :customer or :api_error_response"
230
- end
231
- end
232
-
233
184
  def self._new(*args) # :nodoc:
234
185
  self.new *args
235
186
  end
236
187
 
237
- def self._update_signature # :nodoc:
238
- credit_card_signature = CreditCard._update_signature - [:customer_id]
239
- credit_card_options = credit_card_signature.find { |item| item.respond_to?(:keys) && item.keys == [:options] }
240
- credit_card_options[:options] << :update_existing_token
188
+ def self._attributes # :nodoc:
241
189
  [
242
- :company, :email, :fax, :first_name, :id, :last_name, :phone, :website,
243
- {:credit_card => credit_card_signature},
244
- {:custom_fields => :_any_key_}
190
+ :addresses, :company, :credit_cards, :email, :fax, :first_name, :id, :last_name, :phone, :website,
191
+ :created_at, :updated_at
245
192
  ]
246
193
  end
247
194
  end
@@ -0,0 +1,121 @@
1
+ module Braintree
2
+ class CustomerGateway # :nodoc:
3
+ def initialize(gateway)
4
+ @gateway = gateway
5
+ @config = gateway.config
6
+ end
7
+
8
+ def all
9
+ response = @config.http.post "/customers/advanced_search_ids"
10
+ ResourceCollection.new(response) { |ids| _fetch_customers(ids) }
11
+ end
12
+
13
+ def create(attributes = {})
14
+ Util.verify_keys(CustomerGateway._create_signature, attributes)
15
+ _do_create "/customers", :customer => attributes
16
+ end
17
+
18
+ # Deprecated
19
+ def create_customer_url
20
+ "#{@config.base_merchant_url}/customers/all/create_via_transparent_redirect_request"
21
+ end
22
+
23
+ # Deprecated
24
+ def create_from_transparent_redirect(query_string)
25
+ params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
26
+ _do_create("/customers/all/confirm_transparent_redirect_request", :id => params[:id])
27
+ end
28
+
29
+ def delete(customer_id)
30
+ @config.http.delete("/customers/#{customer_id}")
31
+ SuccessfulResult.new
32
+ end
33
+
34
+ def find(customer_id)
35
+ raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/
36
+ raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
37
+ response = @config.http.get("/customers/#{customer_id}")
38
+ Customer._new(@gateway, response[:customer])
39
+ rescue NotFoundError
40
+ raise NotFoundError, "customer with id #{customer_id.inspect} not found"
41
+ end
42
+
43
+ def transactions(customer_id, options = {})
44
+ response = @config.http.post "/customers/#{customer_id}/transaction_ids"
45
+ ResourceCollection.new(response) { |ids| _fetch_transactions(customer_id, ids) }
46
+ end
47
+
48
+ def update(customer_id, attributes)
49
+ Util.verify_keys(CustomerGateway._update_signature, attributes)
50
+ _do_update(:put, "/customers/#{customer_id}", :customer => attributes)
51
+ end
52
+
53
+ # Deprecated
54
+ def update_customer_url
55
+ warn "[DEPRECATED] Customer.update_customer_url is deprecated. Please use TransparentRedirect.url"
56
+ "#{@config.base_merchant_url}/customers/all/update_via_transparent_redirect_request"
57
+ end
58
+
59
+ # Deprecated
60
+ def update_from_transparent_redirect(query_string)
61
+ params = @gateway.transparent_redirect.parse_and_validate_query_string(query_string)
62
+ _do_update(:post, "/customers/all/confirm_transparent_redirect_request", :id => params[:id])
63
+ end
64
+
65
+ def self._create_signature # :nodoc:
66
+ credit_card_signature = CreditCardGateway._create_signature - [:customer_id]
67
+ [
68
+ :company, :email, :fax, :first_name, :id, :last_name, :phone, :website,
69
+ {:credit_card => credit_card_signature},
70
+ {:custom_fields => :_any_key_}
71
+ ]
72
+ end
73
+
74
+ def _do_create(url, params=nil) # :nodoc:
75
+ response = @config.http.post url, params
76
+ if response[:customer]
77
+ SuccessfulResult.new(:customer => Customer._new(@gateway, response[:customer]))
78
+ elsif response[:api_error_response]
79
+ ErrorResult.new(@gateway, response[:api_error_response])
80
+ else
81
+ raise "expected :customer or :api_error_response"
82
+ end
83
+ end
84
+
85
+ def _do_update(http_verb, url, params) # :nodoc:
86
+ response = @config.http.send http_verb, url, params
87
+ if response[:customer]
88
+ SuccessfulResult.new(:customer => Customer._new(@gateway, response[:customer]))
89
+ elsif response[:api_error_response]
90
+ ErrorResult.new(@gateway, response[:api_error_response])
91
+ else
92
+ raise UnexpectedError, "expected :customer or :api_error_response"
93
+ end
94
+ end
95
+
96
+ def _fetch_customers(ids) # :nodoc:
97
+ response = @config.http.post "/customers/advanced_search", {:search => {:ids => ids}}
98
+ attributes = response[:customers]
99
+ Util.extract_attribute_as_array(attributes, :customer).map { |attrs| Customer._new(@gateway, attrs) }
100
+ end
101
+
102
+ def _fetch_transactions(customer_id, ids) # :nodoc:
103
+ response = @config.http.post "/customers/#{customer_id}/transactions", :search => {:ids => ids}
104
+ attributes = response[:credit_card_transactions]
105
+ Util.extract_attribute_as_array(attributes, :transaction).map do |transaction_attributes|
106
+ Transaction._new @gateway, transaction_attributes
107
+ end
108
+ end
109
+
110
+ def self._update_signature # :nodoc:
111
+ credit_card_signature = CreditCardGateway._update_signature - [:customer_id]
112
+ credit_card_options = credit_card_signature.find { |item| item.respond_to?(:keys) && item.keys == [:options] }
113
+ credit_card_options[:options] << :update_existing_token
114
+ [
115
+ :company, :email, :fax, :first_name, :id, :last_name, :phone, :website,
116
+ {:credit_card => credit_card_signature},
117
+ {:custom_fields => :_any_key_}
118
+ ]
119
+ end
120
+ end
121
+ end
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Digest # :nodoc:
3
- def self.hexdigest(string)
4
- _hmac_sha1(Configuration.private_key, string)
3
+ def self.hexdigest(private_key, string)
4
+ _hmac_sha1(private_key, string)
5
5
  end
6
6
 
7
7
  def self._hmac_sha1(key, message)
@@ -0,0 +1,4 @@
1
+ module Braintree
2
+ class Discount < Modification
3
+ end
4
+ end
@@ -3,6 +3,7 @@ module Braintree
3
3
  # The constants should be used to check for a specific validation error in a ValidationErrorCollection.
4
4
  # The error messages returned from the server may change, but the codes will remain the same.
5
5
  module ErrorCodes
6
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/addresses/validations
6
7
  module Address
7
8
  CannotBeBlank = "81801"
8
9
  CompanyIsTooLong = "81802"
@@ -23,6 +24,7 @@ module Braintree
23
24
  StreetAddressIsTooLong = "81812"
24
25
  end
25
26
 
27
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/validations
26
28
  module CreditCard
27
29
  BillingAddressConflict = "91701"
28
30
  BillingAddressIdIsInvalid = "91702"
@@ -54,6 +56,7 @@ module Braintree
54
56
  end
55
57
  end
56
58
 
59
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/customers/validations
57
60
  module Customer
58
61
  CompanyIsTooLong = "81601"
59
62
  CustomFieldIsInvalid = "91602"
@@ -64,7 +67,8 @@ module Braintree
64
67
  FaxIsTooLong = "81607"
65
68
  FirstNameIsTooLong = "81608"
66
69
  IdIsInUse = "91609"
67
- IdIsInvaild = "91610"
70
+ IdIsInvaild = "91610" # Deprecated
71
+ IdIsInvalid = "91610"
68
72
  IdIsNotAllowed = "91611"
69
73
  IdIsRequired = "91613"
70
74
  IdIsTooLong = "91612"
@@ -74,10 +78,26 @@ module Braintree
74
78
  WebsiteIsTooLong = "81615"
75
79
  end
76
80
 
81
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/subscriptions/validations
77
82
  module Subscription
83
+ BillingDayOfMonthCannotBeUpdated = "91918"
84
+ BillingDayOfMonthIsInvalid = "91914"
85
+ BillingDayOfMonthMustBeNumeric = "91913"
86
+ CannotAddDuplicateAddonOrDiscount = "91911"
78
87
  CannotEditCanceledSubscription = "81901"
79
- IdIsInUse = "81902"
88
+ CannotEditExpiredSubscription = "81910"
89
+ CannotEditPriceChangingFieldsOnPastDueSubscription = "91920"
90
+ FirstBillingDateCannotBeInThePast = "91916"
91
+ FirstBillingDateCannotBeUpdated = "91919"
92
+ FirstBillingDateIsInvalid = "91915"
93
+ IdIsInUse = "81902"
94
+ InconsistentNumberOfBillingCycles = "91908"
95
+ InconsistentStartDate = "91917"
80
96
  MerchantAccountIdIsInvalid = "91901"
97
+ NumberOfBillingCyclesCannotBeBlank = "91912"
98
+ NumberOfBillingCyclesIsTooSmall = "91909"
99
+ NumberOfBillingCyclesMustBeGreaterThanZero = "91907"
100
+ NumberOfBillingCyclesMustBeNumeric = "91906"
81
101
  PaymentMethodTokenCardTypeIsNotAccepted = "91902"
82
102
  PaymentMethodTokenIsInvalid = "91903"
83
103
  PaymentMethodTokenNotAssociatedWithCustomer = "91905"
@@ -86,16 +106,39 @@ module Braintree
86
106
  PriceFormatIsInvalid = "81904"
87
107
  StatusIsCanceled = "81905"
88
108
  TokenFormatIsInvalid = "81906"
89
- TrialDurationFormatIsInvalid = "81907"
109
+ TrialDurationFormatIsInvalid = "81907"
90
110
  TrialDurationIsRequired = "81908"
91
- TrialDurationUnitIsInvalid = "81909"
111
+ TrialDurationUnitIsInvalid = "81909"
112
+
113
+ module Modification
114
+ AmountCannotBeBlank = "92003"
115
+ AmountIsInvalid = "92002"
116
+ CannotEditModificationsOnPastDueSubscription = "92022"
117
+ CannotUpdateAndRemove = "92015"
118
+ ExistingIdIsIncorrectKind = "92020"
119
+ ExistingIdIsInvalid = "92011"
120
+ ExistingIdIsRequired = "92012"
121
+ IdToRemoveIsIncorrectKind = "92021"
122
+ IdToRemoveIsNotPresent = "92016"
123
+ InconsistentNumberOfBillingCycles = "92018"
124
+ InheritedFromIdIsInvalid = "92013"
125
+ InheritedFromIdIsRequired = "92014"
126
+ NumberOfBillingCyclesCannotBeBlank = "92017"
127
+ NumberOfBillingCyclesIsInvalid = "92005"
128
+ NumberOfBillingCyclesMustBeGreaterThanZero = "92019"
129
+ QuantityCannotBeBlank = "92004"
130
+ QuantityIsInvalid = "92001"
131
+ QuantityMustBeGreaterThanZero = "92010"
132
+ end
92
133
  end
93
134
 
135
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/validations
94
136
  module Transaction
95
137
  AmountCannotBeNegative = "81501"
96
138
  AmountIsRequired = "81502"
97
139
  AmountIsInvalid = "81503"
98
140
  AmountIsTooLarge = "81528"
141
+ AmountMustBeGreaterThanZero = "81531"
99
142
  BillingAddressConflict = "91530"
100
143
  CannotBeVoided = "91504"
101
144
  CannotRefundCredit = "91505"
@@ -108,7 +151,8 @@ module Braintree
108
151
  CustomerIdIsInvalid = "91510"
109
152
  CustomerDoesNotHaveCreditCard = "91511"
110
153
  HasAlreadyBeenRefunded = "91512"
111
- MerchantAccountNameIsInvalid = "91513"
154
+ MerchantAccountIdIsInvalid = "91513"
155
+ MerchantAccountNameIsInvalid = "91513" # Deprecated
112
156
  MerchantAccountIsSuspended = "91514"
113
157
  OrderIdIsTooLong = "91501"
114
158
  PaymentMethodConflict = "91515"
@@ -122,6 +166,7 @@ module Braintree
122
166
  SettlementAmountIsTooLarge = "91522"
123
167
  SubscriptionDoesNotBelongToCustomer = "91529"
124
168
  SubscriptionIdIsInvalid = "91528"
169
+ SubscriptionStatusMustBePastDue = "91531"
125
170
  TypeIsInvalid = "91523"
126
171
  TypeIsRequired = "91524"
127
172
  module Options