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,8 +1,5 @@
1
1
  module Braintree
2
- # == More Information
3
- #
4
- # For more detailed documentation on CreditCards, see http://www.braintreepaymentsolutions.com/gateway/credit-card-api
5
- # For more detailed documentation on CreditCard verification, see http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api
2
+ # See http://www.braintreepaymentsolutions.com/docs/ruby
6
3
  class CreditCard
7
4
  include BaseModule # :nodoc:
8
5
 
@@ -32,131 +29,125 @@ module Braintree
32
29
  attr_reader :billing_address, :bin, :card_type, :cardholder_name, :created_at, :customer_id, :expiration_month,
33
30
  :expiration_year, :last_4, :subscriptions, :token, :updated_at
34
31
 
32
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/create
35
33
  def self.create(attributes)
36
- if attributes.has_key?(:expiration_date) && (attributes.has_key?(:expiration_month) || attributes.has_key?(:expiration_year))
37
- raise ArgumentError.new("create with both expiration_month and expiration_year or only expiration_date")
38
- end
39
- Util.verify_keys(_create_signature, attributes)
40
- _do_create("/payment_methods", :credit_card => attributes)
34
+ Configuration.gateway.credit_card.create(attributes)
41
35
  end
42
36
 
37
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/create
43
38
  def self.create!(attributes)
44
39
  return_object_or_raise(:credit_card) { create(attributes) }
45
40
  end
46
41
 
47
- # The transparent redirect URL to use to create a credit card.
42
+ # Deprecated. Use Braintree::TransparentRedirect.url
43
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/create_tr
48
44
  def self.create_credit_card_url
49
45
  warn "[DEPRECATED] CreditCard.create_credit_card_url is deprecated. Please use TransparentRedirect.url"
50
- "#{Braintree::Configuration.base_merchant_url}/payment_methods/all/create_via_transparent_redirect_request"
46
+ Configuration.gateway.credit_card.create_credit_card_url
51
47
  end
52
48
 
49
+ # Deprecated. Use Braintree::TransparentRedirect.confirm
50
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/create_tr
53
51
  def self.create_from_transparent_redirect(query_string)
54
52
  warn "[DEPRECATED] CreditCard.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
55
- params = TransparentRedirect.parse_and_validate_query_string query_string
56
- _do_create("/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
53
+ Configuration.gateway.credit_card.create_from_transparent_redirect(query_string)
57
54
  end
58
55
 
56
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
59
57
  def self.credit(token, transaction_attributes)
60
- Transaction.credit(transaction_attributes.merge(
61
- :payment_method_token => token
62
- ))
58
+ Transaction.credit(transaction_attributes.merge(:payment_method_token => token))
63
59
  end
64
60
 
61
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
65
62
  def self.credit!(token, transaction_attributes)
66
63
  return_object_or_raise(:transaction) { credit(token, transaction_attributes) }
67
64
  end
68
65
 
66
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/delete
69
67
  def self.delete(token)
70
- Http.delete("/payment_methods/#{token}")
68
+ Configuration.gateway.credit_card.delete(token)
71
69
  end
72
70
 
73
- # Returns a ResourceCollection of expired credit cards.
71
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/search
74
72
  def self.expired(options = {})
75
- response = Http.post("/payment_methods/all/expired_ids")
76
- ResourceCollection.new(response) { |ids| _fetch_expired(ids) }
73
+ Configuration.gateway.credit_card.expired(options)
77
74
  end
78
75
 
79
- # Returns a ResourceCollection of credit cards expiring between +start_date+ and +end_date+ inclusive.
80
- # Only the month and year of the start and end dates are used.
76
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/search
81
77
  def self.expiring_between(start_date, end_date, options = {})
82
- formatted_start_date = start_date.strftime('%m%Y')
83
- formatted_end_date = end_date.strftime('%m%Y')
84
- response = Http.post("/payment_methods/all/expiring_ids?start=#{formatted_start_date}&end=#{formatted_end_date}")
85
- ResourceCollection.new(response) { |ids| _fetch_expiring_between(formatted_start_date, formatted_end_date, ids) }
78
+ Configuration.gateway.credit_card.expiring_between(start_date, end_date, options)
86
79
  end
87
80
 
88
- # Finds the credit card with the given +token+. Raises a NotFoundError if it cannot be found.
81
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/search
89
82
  def self.find(token)
90
- response = Http.get "/payment_methods/#{token}"
91
- new(response[:credit_card])
92
- rescue NotFoundError
93
- raise NotFoundError, "payment method with token #{token.inspect} not found"
83
+ Configuration.gateway.credit_card.find(token)
94
84
  end
95
85
 
86
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
96
87
  def self.sale(token, transaction_attributes)
97
- Transaction.sale(transaction_attributes.merge(
98
- :payment_method_token => token
99
- ))
88
+ Configuration.gateway.transaction.sale(transaction_attributes.merge(:payment_method_token => token))
100
89
  end
101
90
 
91
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
102
92
  def self.sale!(token, transaction_attributes)
103
93
  return_object_or_raise(:transaction) { sale(token, transaction_attributes) }
104
94
  end
105
95
 
96
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update
106
97
  def self.update(token, attributes)
107
- Util.verify_keys(_update_signature, attributes)
108
- _do_update(:put, "/payment_methods/#{token}", :credit_card => attributes)
98
+ Configuration.gateway.credit_card.update(token, attributes)
109
99
  end
110
100
 
101
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update
111
102
  def self.update!(token, attributes)
112
103
  return_object_or_raise(:credit_card) { update(token, attributes) }
113
104
  end
114
105
 
106
+ # Deprecated. Use Braintree::TransparentRedirect.confirm
107
+ #
108
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update_tr
115
109
  def self.update_from_transparent_redirect(query_string)
116
110
  warn "[DEPRECATED] CreditCard.update_via_transparent_redirect_request is deprecated. Please use TransparentRedirect.confirm"
117
- params = TransparentRedirect.parse_and_validate_query_string query_string
118
- _do_update(:post, "/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
111
+ Configuration.gateway.credit_card.update_from_transparent_redirect(query_string)
119
112
  end
120
113
 
121
- # The transparent redirect URL to use to update a credit card.
114
+ # Deprecated. Use Braintree::TransparentRedirect.url
115
+ #
116
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update_tr
122
117
  def self.update_credit_card_url
123
118
  warn "[DEPRECATED] CreditCard.update_credit_card_url is deprecated. Please use TransparentRedirect.url"
124
- "#{Braintree::Configuration.base_merchant_url}/payment_methods/all/update_via_transparent_redirect_request"
125
- end
126
-
127
- def self._fetch_expired(ids)
128
- response = Http.post("/payment_methods/all/expired", :search => {:ids => ids})
129
- attributes = response[:payment_methods]
130
- Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| _new(attrs) }
119
+ Configuration.gateway.credit_card.update_credit_card_url
131
120
  end
132
121
 
133
- def self._fetch_expiring_between(formatted_start_date, formatted_end_date, ids)
134
- response = Http.post(
135
- "/payment_methods/all/expiring?start=#{formatted_start_date}&end=#{formatted_end_date}",
136
- :search => {:ids => ids}
137
- )
138
- attributes = response[:payment_methods]
139
- Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| _new(attrs) }
140
- end
141
-
142
- def initialize(attributes) # :nodoc:
143
- _init attributes
144
- @subscriptions = (@subscriptions || []).map { |subscription_hash| Subscription._new(subscription_hash) }
122
+ def initialize(gateway, attributes) # :nodoc:
123
+ @gateway = gateway
124
+ set_instance_variables_from_hash(attributes)
125
+ @billing_address = attributes[:billing_address] ? Address._new(@gateway, attributes[:billing_address]) : nil
126
+ @subscriptions = (@subscriptions || []).map { |subscription_hash| Subscription._new(@gateway, subscription_hash) }
145
127
  end
146
128
 
147
- # Creates a credit transaction for this credit card.
129
+ # Deprecated. Use Braintree::CreditCard.credit
130
+ #
131
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
148
132
  def credit(transaction_attributes)
149
- Transaction.credit(transaction_attributes.merge(
150
- :payment_method_token => self.token
151
- ))
133
+ warn "[DEPRECATED] credit as an instance method is deprecated. Please use CreditCard.credit"
134
+ @gateway.transaction.credit(transaction_attributes.merge(:payment_method_token => token))
152
135
  end
153
136
 
137
+ # Deprecated. Use Braintree::CreditCard.credit!
138
+ #
139
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
154
140
  def credit!(transaction_attributes)
141
+ warn "[DEPRECATED] credit! as an instance method is deprecated. Please use CreditCard.credit!"
155
142
  return_object_or_raise(:transaction) { credit(transaction_attributes) }
156
143
  end
157
144
 
145
+ # Deprecated. Use Braintree::CreditCard.delete
146
+ #
147
+ # http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/delete
158
148
  def delete
159
- CreditCard.delete(token)
149
+ warn "[DEPRECATED] delete as an instance method is deprecated. Please use CreditCard.delete"
150
+ @gateway.credit_card.delete(token)
160
151
  end
161
152
 
162
153
  # Returns true if this credit card is the customer's default.
@@ -187,29 +178,39 @@ module Braintree
187
178
  "#{bin}******#{last_4}"
188
179
  end
189
180
 
190
- # Creates a sale transaction for this credit card.
181
+ # Deprecated. Use Braintree::CreditCard.sale
182
+ #
183
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
191
184
  def sale(transaction_attributes)
192
- CreditCard.sale(self.token, transaction_attributes)
185
+ warn "[DEPRECATED] sale as an instance method is deprecated. Please use CreditCard.sale"
186
+ @gateway.transaction.sale(transaction_attributes.merge(:payment_method_token => token))
193
187
  end
194
188
 
189
+ # Deprecated. Use Braintree::CreditCard.sale!
190
+ #
191
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
195
192
  def sale!(transaction_attributes)
193
+ warn "[DEPRECATED] sale! as an instance method is deprecated. Please use CreditCard.sale!"
196
194
  return_object_or_raise(:transaction) { sale(transaction_attributes) }
197
195
  end
198
196
 
197
+ # Deprecated. Use Braintree::CreditCard.update
198
+ #
199
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update
199
200
  def update(attributes)
200
- Util.verify_keys(self.class._update_signature, attributes)
201
- response = Http.put "/payment_methods/#{token}", :credit_card => attributes
202
- if response[:credit_card]
203
- _init response[:credit_card]
204
- SuccessfulResult.new(:credit_card => self)
205
- elsif response[:api_error_response]
206
- ErrorResult.new(response[:api_error_response])
207
- else
208
- raise UnexpectedError, "expected :credit_card or :api_error_response"
201
+ warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update"
202
+ result = @gateway.credit_card.update(token, attributes)
203
+ if result.success?
204
+ copy_instance_variables_from_object result.credit_card
209
205
  end
206
+ result
210
207
  end
211
208
 
209
+ # Deprecated. Use Braintree::CreditCard.update!
210
+ #
211
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/update
212
212
  def update!(attributes)
213
+ warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!"
213
214
  return_object_or_raise(:credit_card) { update(attributes) }
214
215
  end
215
216
 
@@ -230,63 +231,8 @@ module Braintree
230
231
  ]
231
232
  end
232
233
 
233
- def self._create_signature # :nodoc:
234
- _signature(:create)
235
- end
236
-
237
234
  def self._new(*args) # :nodoc:
238
235
  self.new *args
239
236
  end
240
-
241
- def self._do_create(url, params=nil) # :nodoc:
242
- response = Http.post url, params
243
- if response[:credit_card]
244
- SuccessfulResult.new(:credit_card => new(response[:credit_card]))
245
- elsif response[:api_error_response]
246
- ErrorResult.new(response[:api_error_response])
247
- else
248
- raise UnexpectedError, "expected :credit_card or :api_error_response"
249
- end
250
- end
251
-
252
- def self._do_update(http_verb, url, params) # :nodoc:
253
- response = Http.send http_verb, url, params
254
- if response[:credit_card]
255
- SuccessfulResult.new(:credit_card => new(response[:credit_card]))
256
- elsif response[:api_error_response]
257
- ErrorResult.new(response[:api_error_response])
258
- else
259
- raise UnexpectedError, "expected :credit_card or :api_error_response"
260
- end
261
- end
262
-
263
- def self._update_signature # :nodoc:
264
- _signature(:update)
265
- end
266
-
267
- def self._signature(type) # :nodoc:
268
- billing_address_params = Address._shared_signature
269
- signature = [
270
- :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
271
- {:options => [:make_default, :verification_merchant_account_id, :verify_card]},
272
- {:billing_address => billing_address_params}
273
- ]
274
-
275
- case type
276
- when :create
277
- signature << :customer_id
278
- when :update
279
- billing_address_params << {:options => [:update_existing]}
280
- else
281
- raise ArgumentError
282
- end
283
-
284
- return signature
285
- end
286
-
287
- def _init(attributes) # :nodoc:
288
- set_instance_variables_from_hash(attributes)
289
- @billing_address = attributes[:billing_address] ? Address._new(attributes[:billing_address]) : nil
290
- end
291
237
  end
292
238
  end
@@ -0,0 +1,133 @@
1
+ module Braintree
2
+ class CreditCardGateway # :nodoc:
3
+ def initialize(gateway)
4
+ @gateway = gateway
5
+ @config = gateway.config
6
+ end
7
+
8
+ def create(attributes)
9
+ if attributes.has_key?(:expiration_date) && (attributes.has_key?(:expiration_month) || attributes.has_key?(:expiration_year))
10
+ raise ArgumentError.new("create with both expiration_month and expiration_year or only expiration_date")
11
+ end
12
+ Util.verify_keys(CreditCardGateway._create_signature, attributes)
13
+ _do_create("/payment_methods", :credit_card => attributes)
14
+ end
15
+
16
+ # Deprecated
17
+ def create_credit_card_url
18
+ "#{@config.base_merchant_url}/payment_methods/all/create_via_transparent_redirect_request"
19
+ end
20
+
21
+ # Deprecated
22
+ def create_from_transparent_redirect(query_string)
23
+ params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
24
+ _do_create("/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
25
+ end
26
+
27
+ def delete(token)
28
+ @config.http.delete("/payment_methods/#{token}")
29
+ end
30
+
31
+ def expired(options = {})
32
+ response = @config.http.post("/payment_methods/all/expired_ids")
33
+ ResourceCollection.new(response) { |ids| _fetch_expired(ids) }
34
+ end
35
+
36
+ def expiring_between(start_date, end_date, options = {})
37
+ formatted_start_date = start_date.strftime('%m%Y')
38
+ formatted_end_date = end_date.strftime('%m%Y')
39
+ response = @config.http.post("/payment_methods/all/expiring_ids?start=#{formatted_start_date}&end=#{formatted_end_date}")
40
+ ResourceCollection.new(response) { |ids| _fetch_expiring_between(formatted_start_date, formatted_end_date, ids) }
41
+ end
42
+
43
+ def find(token)
44
+ response = @config.http.get "/payment_methods/#{token}"
45
+ CreditCard._new(@gateway, response[:credit_card])
46
+ rescue NotFoundError
47
+ raise NotFoundError, "payment method with token #{token.inspect} not found"
48
+ end
49
+
50
+ def update(token, attributes)
51
+ Util.verify_keys(CreditCardGateway._update_signature, attributes)
52
+ _do_update(:put, "/payment_methods/#{token}", :credit_card => attributes)
53
+ end
54
+
55
+ # Deprecated
56
+ def update_from_transparent_redirect(query_string)
57
+ warn "[DEPRECATED] CreditCard.update_via_transparent_redirect_request is deprecated. Please use TransparentRedirect.confirm"
58
+ params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
59
+ _do_update(:post, "/payment_methods/all/confirm_transparent_redirect_request", :id => params[:id])
60
+ end
61
+
62
+ # Deprecated
63
+ def update_credit_card_url
64
+ warn "[DEPRECATED] CreditCard.update_credit_card_url is deprecated. Please use TransparentRedirect.url"
65
+ "#{@config.base_merchant_url}/payment_methods/all/update_via_transparent_redirect_request"
66
+ end
67
+
68
+ def self._create_signature # :nodoc:
69
+ _signature(:create)
70
+ end
71
+
72
+ def self._update_signature # :nodoc:
73
+ _signature(:update)
74
+ end
75
+
76
+ def self._signature(type) # :nodoc:
77
+ billing_address_params = AddressGateway._shared_signature
78
+ signature = [
79
+ :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
80
+ {:options => [:make_default, :verification_merchant_account_id, :verify_card]},
81
+ {:billing_address => billing_address_params}
82
+ ]
83
+
84
+ case type
85
+ when :create
86
+ signature << :customer_id
87
+ when :update
88
+ billing_address_params << {:options => [:update_existing]}
89
+ else
90
+ raise ArgumentError
91
+ end
92
+
93
+ return signature
94
+ end
95
+
96
+ def _do_create(url, params=nil) # :nodoc:
97
+ response = @config.http.post url, params
98
+ if response[:credit_card]
99
+ SuccessfulResult.new(:credit_card => CreditCard._new(@gateway, response[:credit_card]))
100
+ elsif response[:api_error_response]
101
+ ErrorResult.new(@gateway, response[:api_error_response])
102
+ else
103
+ raise UnexpectedError, "expected :credit_card or :api_error_response"
104
+ end
105
+ end
106
+
107
+ def _do_update(http_verb, url, params) # :nodoc:
108
+ response = @config.http.send http_verb, url, params
109
+ if response[:credit_card]
110
+ SuccessfulResult.new(:credit_card => CreditCard._new(@gateway, response[:credit_card]))
111
+ elsif response[:api_error_response]
112
+ ErrorResult.new(@gateway, response[:api_error_response])
113
+ else
114
+ raise UnexpectedError, "expected :credit_card or :api_error_response"
115
+ end
116
+ end
117
+
118
+ def _fetch_expired(ids) # :nodoc:
119
+ response = @config.http.post("/payment_methods/all/expired", :search => {:ids => ids})
120
+ attributes = response[:payment_methods]
121
+ Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| CreditCard._new(@gateway, attrs) }
122
+ end
123
+
124
+ def _fetch_expiring_between(formatted_start_date, formatted_end_date, ids) # :nodoc:
125
+ response = @config.http.post(
126
+ "/payment_methods/all/expiring?start=#{formatted_start_date}&end=#{formatted_end_date}",
127
+ :search => {:ids => ids}
128
+ )
129
+ attributes = response[:payment_methods]
130
+ Util.extract_attribute_as_array(attributes, :credit_card).map { |attrs| CreditCard._new(@gateway, attrs) }
131
+ end
132
+ end
133
+ end
@@ -1,7 +1,15 @@
1
1
  module Braintree
2
+ # See http://www.braintreepaymentsolutions.com/docs/ruby/general/card_verification
2
3
  class CreditCardVerification
3
4
  include BaseModule
4
5
 
6
+ module Status
7
+ FAILED = 'failed'
8
+ GATEWAY_REJECTED = 'gateway_rejected'
9
+ PROCESSOR_DECLINED = 'processor_declined'
10
+ VERIFIED = 'verified'
11
+ end
12
+
5
13
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code,
6
14
  :cvv_response_code, :merchant_account_id, :processor_response_code, :processor_response_text, :status,
7
15
  :gateway_rejection_reason