spreedly 2.0.0 → 2.0.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 (38) hide show
  1. data/HISTORY.md +11 -0
  2. data/README.md +2 -2
  3. data/lib/spreedly/common/fields.rb +0 -1
  4. data/lib/spreedly/connection.rb +2 -2
  5. data/lib/spreedly/environment.rb +34 -5
  6. data/lib/spreedly/gateway.rb +22 -0
  7. data/lib/spreedly/payment_methods/bank_account.rb +9 -0
  8. data/lib/spreedly/payment_methods/payment_method.rb +9 -0
  9. data/lib/spreedly/transactions/redact_gateway.rb +14 -0
  10. data/lib/spreedly/transactions/transaction.rb +2 -0
  11. data/lib/spreedly/urls.rb +22 -2
  12. data/lib/spreedly/version.rb +1 -1
  13. data/lib/spreedly.rb +2 -0
  14. data/test/remote/remote_add_gateway_test.rb +7 -1
  15. data/test/remote/remote_find_gateway_test.rb +4 -3
  16. data/test/remote/remote_list_gateways_test.rb +35 -0
  17. data/test/remote/remote_list_payment_methods_test.rb +34 -0
  18. data/test/remote/remote_list_transactions_test.rb +29 -1
  19. data/test/remote/remote_redact_gateway_test.rb +30 -0
  20. data/test/remote/{remote_redact_test.rb → remote_redact_payment_method_test.rb} +1 -1
  21. data/test/remote/remote_update_credit_card_test.rb +54 -0
  22. data/test/unit/add_gateway_test.rb +17 -7
  23. data/test/unit/find_gateway_test.rb +5 -4
  24. data/test/unit/find_payment_method_test.rb +23 -0
  25. data/test/unit/list_gateways_test.rb +47 -0
  26. data/test/unit/list_payment_methods_test.rb +47 -0
  27. data/test/unit/list_transactions_test.rb +17 -5
  28. data/test/unit/redact_gateway_test.rb +42 -0
  29. data/test/unit/redact_payment_method_test.rb +3 -3
  30. data/test/unit/response_stubs/find_gateway_stubs.rb +30 -20
  31. data/test/unit/response_stubs/find_payment_method_stubs.rb +26 -0
  32. data/test/unit/response_stubs/list_gateways_stubs.rb +75 -0
  33. data/test/unit/response_stubs/list_payment_methods_stubs.rb +63 -0
  34. data/test/unit/response_stubs/redact_gateway_stubs.rb +47 -0
  35. data/test/unit/response_stubs/redact_payment_method_stubs.rb +1 -6
  36. data/test/unit/response_stubs/update_credit_card_stubs.rb +34 -0
  37. data/test/unit/update_credit_card_test.rb +59 -0
  38. metadata +32 -6
data/HISTORY.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1
4
+ * List the transactions for a payment method
5
+ * Allow adding other gateways
6
+ * Listing Payment Methods (retained on an account)
7
+ * Updating a Payment Method
8
+ * Listing Your Gateways
9
+ * Finding a Gateway
10
+ * Fix Ruby 1.9.2 private method issue
11
+ * Add ability to find a bank account payment method
12
+ * Add ability to redact a gateway
13
+
3
14
  ## 2.0.0
4
15
  * This gem is now intended for the Spreedly API. For the Spreedly
5
16
  Subscriptions API, you can use the spreedly_subscriptions gem
data/README.md CHANGED
@@ -230,10 +230,10 @@ transaction.order_id # => '30-9904-31114'
230
230
  env.find_transaction_transcript(transaction_token)
231
231
  ```
232
232
 
233
- #### Updating a payment method
233
+ #### Updating a credit card
234
234
 
235
235
  ``` ruby
236
- env.update_payment_method(payment_method_token, first_name: 'JimBob', last_name: 'Jones')
236
+ env.update_credit_card(credit_card_token, first_name: 'JimBob', last_name: 'Jones')
237
237
  ```
238
238
 
239
239
  #### Adding other types of gateways
@@ -37,7 +37,6 @@ module Spreedly
37
37
  subclass.instance_variable_set("@fields", instance_variable_get("@fields"))
38
38
  end
39
39
 
40
- private
41
40
  def add_accessor_for(f, field_type)
42
41
  case field_type
43
42
  when :boolean
@@ -28,8 +28,8 @@ module Spreedly
28
28
  private
29
29
  def http
30
30
  http = Net::HTTP.new(endpoint.host, endpoint.port)
31
- http.open_timeout = 60
32
- http.read_timeout = 60
31
+ http.open_timeout = 64
32
+ http.read_timeout = 64
33
33
  http.use_ssl = true
34
34
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
35
35
  http.ca_file = File.dirname(__FILE__) + '/../certs/cacert.pem'
@@ -66,13 +66,28 @@ module Spreedly
66
66
  Transaction.new_from(xml_doc)
67
67
  end
68
68
 
69
- def list_transactions(since_token = nil)
70
- xml_doc = ssl_get(list_transactions_url(since_token), headers)
69
+ def redact_gateway(gateway_token, options = {})
70
+ xml_doc = ssl_put(redact_gateway_url(gateway_token), '', headers)
71
+ Transaction.new_from(xml_doc)
72
+ end
73
+
74
+ def list_transactions(since_token = nil, payment_method_token = nil)
75
+ xml_doc = ssl_get(list_transactions_url(since_token, payment_method_token), headers)
71
76
  Transaction.new_list_from(xml_doc)
72
77
  end
73
78
 
74
- def add_gateway(gateway_type, options = {})
75
- body = add_gateway_body(gateway_type, options)
79
+ def list_payment_methods(since_token = nil)
80
+ xml_doc = ssl_get(list_payment_methods_url(since_token), headers)
81
+ PaymentMethod.new_list_from(xml_doc)
82
+ end
83
+
84
+ def list_gateways(since_token = nil)
85
+ xml_doc = ssl_get(list_gateways_url(since_token), headers)
86
+ Gateway.new_list_from(xml_doc)
87
+ end
88
+
89
+ def add_gateway(gateway_type, credentials = {})
90
+ body = add_gateway_body(gateway_type, credentials)
76
91
  xml_doc = ssl_post(add_gateway_url, body, headers)
77
92
  Gateway.new(xml_doc)
78
93
  end
@@ -81,6 +96,12 @@ module Spreedly
81
96
  api_post(add_payment_method_url, add_credit_card_body(options))
82
97
  end
83
98
 
99
+ def update_credit_card(credit_card_token, options)
100
+ body = update_credit_card_body(options)
101
+ xml_doc = ssl_put(update_payment_method_url(credit_card_token), body, headers)
102
+ PaymentMethod.new_from(xml_doc)
103
+ end
104
+
84
105
  private
85
106
  def headers
86
107
  {
@@ -132,9 +153,10 @@ module Spreedly
132
153
  end
133
154
  end
134
155
 
135
- def add_gateway_body(gateway_type, options)
156
+ def add_gateway_body(gateway_type, credentials)
136
157
  build_xml_request('gateway') do |doc|
137
158
  doc.gateway_type gateway_type
159
+ add_to_doc(doc, credentials, *credentials.keys)
138
160
  end
139
161
  end
140
162
 
@@ -148,6 +170,13 @@ module Spreedly
148
170
  end
149
171
  end
150
172
 
173
+ def update_credit_card_body(options)
174
+ build_xml_request('payment_method') do |doc|
175
+ add_to_doc(doc, options, :email, :month, :first_name, :last_name, :year,
176
+ :address1, :address2, :city, :state, :zip, :country, :phone_number)
177
+ end
178
+ end
179
+
151
180
  def add_to_doc(doc, options, *attributes)
152
181
  attributes.each do |attr|
153
182
  doc.send(attr, options[attr.to_sym]) if options[attr.to_sym]
@@ -4,6 +4,28 @@ module Spreedly
4
4
  class Gateway < Model
5
5
 
6
6
  field :gateway_type, :state, :name
7
+ attr_reader :credentials
8
+
9
+ def initialize(xml_doc)
10
+ super
11
+ init_credentials(xml_doc)
12
+ end
13
+
14
+ def self.new_list_from(xml_doc)
15
+ gateways = xml_doc.xpath('.//gateways/gateway')
16
+ gateways.map do |each|
17
+ self.new(each)
18
+ end
19
+ end
20
+
21
+ private
22
+ def init_credentials(xml_doc)
23
+ @credentials = {}
24
+
25
+ xml_doc.xpath('.//credentials/credential').each do |each|
26
+ @credentials[each.at_xpath('.//name').text] = each.at_xpath('.//value').text
27
+ end
28
+ end
7
29
 
8
30
  end
9
31
 
@@ -0,0 +1,9 @@
1
+ module Spreedly
2
+
3
+ class BankAccount < PaymentMethod
4
+ field :first_name, :last_name, :full_name, :bank_name
5
+ field :account_type, :account_holder_type, :routing_number_display_digits
6
+ field :account_number_display_digits, :routing_number, :account_number
7
+ end
8
+
9
+ end
@@ -22,6 +22,15 @@ module Spreedly
22
22
  return Paypal.new(xml_doc)
23
23
  when 'sprel'
24
24
  return Sprel.new(xml_doc)
25
+ when 'bank_account'
26
+ return BankAccount.new(xml_doc)
27
+ end
28
+ end
29
+
30
+ def self.new_list_from(xml_doc)
31
+ payment_methods = xml_doc.xpath('.//payment_methods/payment_method')
32
+ payment_methods.map do |each|
33
+ self.new_from(each)
25
34
  end
26
35
  end
27
36
 
@@ -0,0 +1,14 @@
1
+ module Spreedly
2
+
3
+ class RedactGateway < Transaction
4
+
5
+ attr_reader :gateway
6
+
7
+ def initialize(xml_doc)
8
+ super
9
+ @gateway = Gateway.new(xml_doc.at_xpath('.//gateway'))
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -24,6 +24,8 @@ module Spreedly
24
24
  return RetainPaymentMethod.new(xml_doc)
25
25
  when 'RedactPaymentMethod'
26
26
  return RedactPaymentMethod.new(xml_doc)
27
+ when 'RedactGateway'
28
+ return RedactGateway.new(xml_doc)
27
29
  else
28
30
  Transaction.new(xml_doc)
29
31
  end
data/lib/spreedly/urls.rb CHANGED
@@ -46,9 +46,25 @@ module Spreedly
46
46
  "#{base_url}/v1/payment_methods/#{payment_method_token}/redact.xml"
47
47
  end
48
48
 
49
- def list_transactions_url(since_token)
49
+ def redact_gateway_url(gateway_token)
50
+ "#{base_url}/v1/gateways/#{gateway_token}/redact.xml"
51
+ end
52
+
53
+ def list_transactions_url(since_token, payment_method_token)
54
+ since_param = "?since_token=#{since_token}" if since_token
55
+ return "#{base_url}/v1/transactions.xml#{since_param}" unless payment_method_token
56
+
57
+ "#{base_url}/v1/payment_methods/#{payment_method_token}/transactions.xml#{since_param}"
58
+ end
59
+
60
+ def list_payment_methods_url(since_token)
50
61
  since_param = "?since_token=#{since_token}" if since_token
51
- "#{base_url}/v1/transactions.xml#{since_param}"
62
+ "#{base_url}/v1/payment_methods.xml#{since_param}"
63
+ end
64
+
65
+ def list_gateways_url(since_token)
66
+ since_param = "?since_token=#{since_token}" if since_token
67
+ "#{base_url}/v1/gateways.xml#{since_param}"
52
68
  end
53
69
 
54
70
  def add_gateway_url
@@ -59,6 +75,10 @@ module Spreedly
59
75
  "#{base_url}/v1/payment_methods.xml"
60
76
  end
61
77
 
78
+ def update_payment_method_url(token)
79
+ "#{base_url}/v1/payment_methods/#{token}.xml"
80
+ end
81
+
62
82
  end
63
83
 
64
84
  end
@@ -1,3 +1,3 @@
1
1
  module Spreedly
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/spreedly.rb CHANGED
@@ -9,6 +9,7 @@ require 'spreedly/payment_methods/payment_method'
9
9
  require 'spreedly/payment_methods/credit_card'
10
10
  require 'spreedly/payment_methods/paypal'
11
11
  require 'spreedly/payment_methods/sprel'
12
+ require 'spreedly/payment_methods/bank_account'
12
13
  require 'spreedly/transactions/transaction'
13
14
  require 'spreedly/transactions/gateway_transaction'
14
15
  require 'spreedly/transactions/add_payment_method'
@@ -20,6 +21,7 @@ require 'spreedly/transactions/capture'
20
21
  require 'spreedly/transactions/refund'
21
22
  require 'spreedly/transactions/retain_payment_method'
22
23
  require 'spreedly/transactions/redact_payment_method'
24
+ require 'spreedly/transactions/redact_gateway'
23
25
  require 'spreedly/gateway'
24
26
  require 'spreedly/error'
25
27
 
@@ -24,7 +24,13 @@ class RemoteAddGatewayTest < Test::Unit::TestCase
24
24
  gateway = @environment.add_gateway(:test)
25
25
  assert_equal "test", gateway.gateway_type
26
26
  assert_equal "retained", gateway.state
27
- assert_equal "Test", gateway.name
27
+ assert_equal "Spreedly Test", gateway.name
28
+ end
29
+
30
+ def test_need_active_account
31
+ assert_raise_with_message(Spreedly::PaymentRequiredError, "Your account has not been activated for real transactions. Please update your subscription settings.") do
32
+ gateway = @environment.add_gateway(:wirecard)
33
+ end
28
34
  end
29
35
 
30
36
  end
@@ -23,9 +23,10 @@ class RemoteFindGatewayTest < Test::Unit::TestCase
23
23
 
24
24
  found = @environment.find_gateway(gateway.token)
25
25
 
26
- assert_equal gateway.token, found.token
27
- assert_equal "Test", gateway.name
28
- assert_equal "retained", gateway.state
26
+ assert_equal(gateway.token, found.token)
27
+ assert_equal("Spreedly Test", gateway.name)
28
+ assert_equal("retained", gateway.state)
29
+ assert_equal({}, gateway.credentials)
29
30
  end
30
31
 
31
32
  end
@@ -0,0 +1,35 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class RemoteListGatewaysTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
8
+ end
9
+
10
+ def test_invalid_login
11
+ assert_invalid_login do |environment|
12
+ environment.list_gateways
13
+ end
14
+ end
15
+
16
+ def test_successfully_list_gateways
17
+ g1 = @environment.add_gateway(:test).token
18
+ g2 = @environment.add_gateway(:test).token
19
+ g3 = @environment.add_gateway(:test).token
20
+
21
+ first_twenty = @environment.list_gateways
22
+ assert_equal 20, first_twenty.size
23
+ assert_kind_of Spreedly::Model, first_twenty.first
24
+
25
+ gateways = @environment.list_gateways(g1)
26
+ assert_equal 2, gateways.size
27
+ assert_kind_of(Spreedly::Gateway, gateways.first)
28
+ assert_kind_of(Spreedly::Gateway, gateways.last)
29
+
30
+ assert_equal g2, gateways.first.token
31
+ assert_equal g3, gateways.last.token
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteListPaymentMethodsTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
7
+ end
8
+
9
+ def test_invalid_login
10
+ assert_invalid_login do |environment|
11
+ environment.list_payment_methods
12
+ end
13
+ end
14
+
15
+ def test_successfully_list_payment_methods
16
+ c1 = create_card_on(@environment).token
17
+ c2 = create_card_on(@environment).token
18
+ c3 = create_card_on(@environment).token
19
+
20
+ first_twenty = @environment.list_payment_methods
21
+ assert_equal 20, first_twenty.size
22
+ assert_kind_of Spreedly::Model, first_twenty.first
23
+
24
+ payment_methods = @environment.list_payment_methods(c1)
25
+ assert_equal 2, payment_methods.size
26
+ assert_kind_of(Spreedly::CreditCard, payment_methods.first)
27
+ assert_kind_of(Spreedly::CreditCard, payment_methods.last)
28
+
29
+ assert_equal c2, payment_methods.first.token
30
+ assert_equal c3, payment_methods.last.token
31
+ end
32
+
33
+ end
34
+
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RemoteTransactionsTest < Test::Unit::TestCase
3
+ class RemoteListTransactionsTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
@@ -33,4 +33,32 @@ class RemoteTransactionsTest < Test::Unit::TestCase
33
33
  assert_equal 22, transactions.last.amount
34
34
  end
35
35
 
36
+ def test_successfully_list_transactions_for_a_payment_method
37
+ gateway_token = @environment.add_gateway(:test).token
38
+ card_token = create_card_on(@environment).token
39
+
40
+ t1 = @environment.purchase_on_gateway(gateway_token, card_token, 144)
41
+ t2 = @environment.authorize_on_gateway(gateway_token, card_token, 444)
42
+ t3 = @environment.capture_transaction(t2.token, amount: 22)
43
+
44
+ all = @environment.list_transactions(nil, card_token)
45
+ assert_equal 5, all.size
46
+ assert_kind_of Spreedly::Model, all.first
47
+
48
+ next_group = @environment.list_transactions(t1.token, card_token)
49
+ assert_equal 2, next_group.size
50
+ assert_kind_of(Spreedly::Authorization, next_group.first)
51
+ assert_kind_of(Spreedly::Capture, next_group.last)
52
+
53
+ assert_equal 444, next_group.first.amount
54
+ assert_equal 22, next_group.last.amount
55
+ end
56
+
57
+ def test_list_transactions_non_existent_payment_method
58
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified payment method.") do
59
+ @environment.list_transactions(nil, 'nonExistentToken')
60
+ end
61
+ end
62
+
36
63
  end
64
+
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteRedactGatewayTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
7
+ end
8
+
9
+ def test_invalid_login
10
+ assert_invalid_login do |environment|
11
+ environment.redact_gateway('gateway_token')
12
+ end
13
+ end
14
+
15
+ def test_gateway_token_token_not_found
16
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified gateway.") do
17
+ @environment.redact_gateway('unknown_token')
18
+ end
19
+ end
20
+
21
+ def test_successful_redact
22
+ gateway = @environment.add_gateway(:test)
23
+
24
+ transaction = @environment.redact_gateway(gateway.token)
25
+
26
+ assert transaction.succeeded?
27
+ assert_equal 'redacted', transaction.gateway.state
28
+ end
29
+
30
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RemoteRedactTest < Test::Unit::TestCase
3
+ class RemoteRedactPaymentMethodTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteUpdateCreditCardTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
7
+ end
8
+
9
+ def test_invalid_login
10
+ assert_invalid_login do |environment|
11
+ environment.update_credit_card("card_token", card_deets)
12
+ end
13
+ end
14
+
15
+ def test_non_existent_card_token
16
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified payment method.") do
17
+ @environment.update_credit_card('unknown_card', card_deets)
18
+ end
19
+ end
20
+
21
+ def test_failed_with_validation_errors
22
+ card = create_card_on(@environment)
23
+ error = assert_raises(Spreedly::TransactionCreationError) do
24
+ @environment.update_credit_card(card.token, card_deets(last_name: '', first_name: ' '))
25
+ end
26
+
27
+ expected_errors = [
28
+ { attribute: "first_name", key: "errors.blank", message: "First name can't be blank" },
29
+ { attribute: "last_name", key: "errors.blank", message: "Last name can't be blank" }
30
+ ]
31
+
32
+ assert_equal expected_errors, error.errors
33
+ assert_equal "First name can't be blank\nLast name can't be blank", error.message
34
+ end
35
+
36
+ def test_successful_update_card
37
+ card = create_card_on(@environment)
38
+ result = @environment.update_credit_card(card.token, card_deets)
39
+
40
+ assert_kind_of(Spreedly::CreditCard, result)
41
+ assert_equal 'Cauthon', result.last_name
42
+ assert_equal 'Mat', result.first_name
43
+ assert_equal 'cauthon@wot.com', result.email
44
+ end
45
+
46
+ private
47
+ def card_deets(options = {})
48
+ {
49
+ email: 'cauthon@wot.com', month: 1, year: 2019,
50
+ last_name: 'Cauthon', first_name: 'Mat'
51
+ }.merge(options)
52
+ end
53
+
54
+ end
@@ -13,14 +13,24 @@ class AddGatewayTest < Test::Unit::TestCase
13
13
  @environment.stubs(:raw_ssl_request).returns(successful_add_test_gateway_response)
14
14
 
15
15
  gateway = @environment.add_gateway(:test)
16
- assert_equal "4dFb93AiRDEJ18MS9xDGMyu22uO", gateway.token
17
- assert_equal "test", gateway.gateway_type
18
- assert_equal "retained", gateway.state
19
- assert_equal "Test", gateway.name
16
+ assert_equal("4dFb93AiRDEJ18MS9xDGMyu22uO", gateway.token)
17
+ assert_equal("test", gateway.gateway_type)
18
+ assert_equal("retained", gateway.state)
19
+ assert_equal("Test", gateway.name)
20
+ assert_equal({}, gateway.credentials)
20
21
  end
21
22
 
22
- # TODO
23
- # Tests coming for characteristics, payment_methods, and gateway_specific_fields.
24
- # We'll also soon handle adding other types of gateways.
23
+ def test_request_body_params
24
+ body = get_request_body(successful_add_test_gateway_response) do
25
+ @environment.add_gateway(:wirecard, username: "TheUserName", password: "ThePassword", business_case_signature: "TheSig")
26
+ end
27
+
28
+ gateway = body.xpath('./gateway')
29
+ assert_xpaths_in gateway,
30
+ [ './gateway_type', 'wirecard' ],
31
+ [ './username', 'TheUserName' ],
32
+ [ './password', 'ThePassword' ],
33
+ [ './business_case_signature', 'TheSig']
34
+ end
25
35
 
26
36
  end
@@ -13,10 +13,11 @@ class FindGatewayTest < Test::Unit::TestCase
13
13
  g = find_using(successful_get_gateway_response)
14
14
 
15
15
  assert_kind_of(Spreedly::Gateway, g)
16
- assert_equal("RsVlPgS4dMzeeUpKXxk01rMMRrQ", g.token)
17
- assert_equal Time.parse("2013-08-07 18:53:30 UTC"), g.created_at
18
- assert_equal Time.parse("2013-08-07 18:53:30 UTC"), g.updated_at
19
- assert_equal 'redacted', g.state
16
+ assert_equal("5YqAdCL5AaxdbDdo1yZCkB4r74p", g.token)
17
+ assert_equal(Time.parse("2013-08-23 14:52:25 UTC"), g.created_at)
18
+ assert_equal(Time.parse("2013-08-23 14:52:25 UTC"), g.updated_at)
19
+ assert_equal('redacted', g.state)
20
+ assert_equal({ 'username' => "UsernameOfAwesome", 'business_case_signature' => "Super Sig" }, g.credentials)
20
21
  end
21
22
 
22
23
  private
@@ -80,6 +80,29 @@ class FindPaymentMethodTest < Test::Unit::TestCase
80
80
  assert_equal("retained", paypal.storage_state)
81
81
  end
82
82
 
83
+ def test_successfully_find_bank_account
84
+ b = find_using(successful_get_bank_account_response)
85
+
86
+ assert_kind_of(Spreedly::BankAccount, b)
87
+ assert_equal "seeQDV0jwJwFa1FUUsph6kPMTj", b.token
88
+ assert_equal "daniel@waterhouse.com", b.email
89
+ assert_equal(1376673633, b.created_at.to_i)
90
+ assert_equal(1376673633, b.updated_at.to_i)
91
+ assert_equal("GeekyNote", b.data)
92
+ assert_equal("cached", b.storage_state)
93
+ assert_equal("Daniel", b.first_name)
94
+ assert_equal("Waterhouse", b.last_name)
95
+ assert_equal("Daniel Waterhouse", b.full_name)
96
+ assert_equal("First Bank of Crypto", b.bank_name)
97
+ assert_equal("checking", b.account_type)
98
+ assert_equal("personal", b.account_holder_type)
99
+ assert_equal("021", b.routing_number_display_digits)
100
+ assert_equal("4321", b.account_number_display_digits)
101
+ assert_equal("021*", b.routing_number)
102
+ assert_equal("*4321", b.account_number)
103
+ assert_equal([], b.errors)
104
+ end
105
+
83
106
  private
84
107
  def find_using(response)
85
108
  @environment.stubs(:raw_ssl_request).returns(response)
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'unit/response_stubs/list_gateways_stubs'
3
+
4
+ class ListGatewaysTest < Test::Unit::TestCase
5
+
6
+ include ListGatewaysStubs
7
+
8
+ def setup
9
+ @environment = Spreedly::Environment.new("key", "secret")
10
+ end
11
+
12
+ def test_successful_list_payment_methods
13
+ list = list_using(successful_list_gateways_response)
14
+
15
+ assert_kind_of(Array, list)
16
+ assert_equal 2, list.size
17
+
18
+ assert_equal 'OJUFe5ZR6pFfL4i4ZGVmvGWkZUY', list.first.token
19
+ assert_equal '52wqOssuKZSXEYde30AGTG6xl8v', list.last.token
20
+ assert_kind_of Spreedly::Gateway, list.first
21
+ assert_kind_of Spreedly::Gateway, list.last
22
+ end
23
+
24
+ def test_request_url
25
+ assert_request_url 'https://core.spreedly.com/v1/gateways.xml' do
26
+ @environment.list_gateways
27
+ end
28
+
29
+ assert_request_url 'https://core.spreedly.com/v1/gateways.xml?since_token=SomeToken' do
30
+ @environment.list_gateways("SomeToken")
31
+ end
32
+ end
33
+
34
+ private
35
+ def list_using(response)
36
+ @environment.stubs(:raw_ssl_request).returns(response)
37
+ @environment.list_gateways
38
+ end
39
+
40
+ def assert_request_url(expected_url)
41
+ actual_url = get_request_url(successful_list_gateways_response) do
42
+ yield
43
+ end
44
+ assert_equal expected_url, actual_url
45
+ end
46
+
47
+ end