spreedly 2.0.18 → 2.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +174 -0
  4. data/README.md +12 -3
  5. data/Rakefile +2 -14
  6. data/lib/spreedly/environment.rb +31 -5
  7. data/lib/spreedly/gateway_class.rb +3 -1
  8. data/lib/spreedly/payment_methods/payment_method.rb +1 -1
  9. data/lib/spreedly/receiver.rb +1 -1
  10. data/lib/spreedly/ssl_requester.rb +1 -4
  11. data/lib/spreedly/transactions/auth_purchase.rb +3 -5
  12. data/lib/spreedly/transactions/authorization.rb +1 -5
  13. data/lib/spreedly/transactions/gateway_transaction.rb +6 -31
  14. data/lib/spreedly/transactions/purchase.rb +0 -3
  15. data/lib/spreedly/transactions/response.rb +13 -0
  16. data/lib/spreedly/transactions/shipping_address.rb +11 -0
  17. data/lib/spreedly/transactions/transaction.rb +0 -4
  18. data/lib/spreedly/urls.rb +25 -8
  19. data/lib/spreedly/version.rb +1 -1
  20. data/lib/spreedly.rb +2 -0
  21. data/spreedly.gemspec +18 -18
  22. data/test/credentials/credentials.yml.example +5 -0
  23. data/test/credentials/test_credentials.rb +1 -1
  24. data/test/helpers/creation_helper.rb +11 -8
  25. data/test/remote/remote_add_credit_card_test.rb +2 -2
  26. data/test/remote/remote_add_receiver_test.rb +2 -2
  27. data/test/remote/remote_authorize_test.rb +17 -2
  28. data/test/remote/remote_complete_test.rb +27 -0
  29. data/test/remote/remote_deliver_payment_method_test.rb +3 -3
  30. data/test/remote/remote_gateway_options_test.rb +1 -1
  31. data/test/remote/remote_purchase_test.rb +42 -0
  32. data/test/remote/remote_recache_payment_method_test.rb +30 -0
  33. data/test/remote/remote_redact_receiver_test.rb +16 -0
  34. data/test/remote/remote_update_credit_card_test.rb +1 -1
  35. data/test/test_helper.rb +1 -0
  36. data/test/unit/add_credit_card_test.rb +1 -2
  37. data/test/unit/authorize_test.rb +9 -2
  38. data/test/unit/capture_test.rb +2 -0
  39. data/test/unit/find_payment_method_test.rb +1 -0
  40. data/test/unit/gateway_options_test.rb +18 -12
  41. data/test/unit/list_payment_methods_test.rb +1 -0
  42. data/test/unit/list_transactions_test.rb +12 -0
  43. data/test/unit/purchase_test.rb +59 -2
  44. data/test/unit/recache_payment_method_test.rb +34 -0
  45. data/test/unit/refund_test.rb +1 -0
  46. data/test/unit/response_stubs/authorization_stubs.rb +6 -2
  47. data/test/unit/response_stubs/capture_stubs.rb +5 -1
  48. data/test/unit/response_stubs/purchase_stubs.rb +106 -0
  49. data/test/unit/response_stubs/recache_payment_method_stubs.rb +53 -0
  50. data/test/unit/verify_test.rb +5 -2
  51. data/test/unit/void_test.rb +1 -0
  52. metadata +44 -16
  53. data/HISTORY.md +0 -153
  54. data/test/credentials/credentials.yml +0 -9
data/spreedly.gemspec CHANGED
@@ -1,30 +1,30 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'spreedly/version'
5
4
 
6
-
7
5
  Gem::Specification.new do |s|
8
- s.name = "spreedly"
9
- s.version = Spreedly::VERSION
10
- s.authors = ["Spreedly"]
11
- s.email = ["duff@spreedly.com"]
12
- s.summary = "Provides a Ruby wrapper for the Spreedly API."
13
- s.description = "The Spreedly gem provides a convenient Ruby wrapper for the Spreedly API."
14
- s.homepage = "https://github.com/spreedly/spreedly-gem"
15
- s.license = "MIT"
6
+ s.name = 'spreedly'
7
+ s.version = Spreedly::VERSION
8
+ s.authors = ['Spreedly']
9
+ s.email = ['duff@spreedly.com', 'doug@spreedly.com', 'jeremy@spreedly.com']
10
+ s.summary = 'Provides a Ruby wrapper for the Spreedly API.'
11
+ s.description = 'The Spreedly gem provides a convenient Ruby wrapper for the Spreedly API.'
12
+ s.homepage = 'https://github.com/spreedly/spreedly-gem'
13
+ s.license = 'MIT'
14
+
15
+ s.metadata["changelog_uri"] = 'https://github.com/spreedly/spreedly-gem/blob/master/CHANGELOG.md'
16
16
 
17
- s.files = `git ls-files`.split($/)
17
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
- s.require_paths = ["lib"]
19
+ s.require_paths = ['lib']
20
20
 
21
21
  s.add_dependency 'nokogiri'
22
22
 
23
- s.add_development_dependency 'bundler', '~> 1.3'
24
- s.add_development_dependency 'rake'
25
- s.add_development_dependency 'mocha'
26
- s.add_development_dependency 'log_buddy'
27
23
  s.add_development_dependency 'awesome_print'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'log_buddy'
26
+ s.add_development_dependency 'mocha'
27
+ s.add_development_dependency 'rake'
28
28
  s.add_development_dependency 'test-unit'
29
+ s.add_development_dependency 'pry'
29
30
  end
30
-
@@ -0,0 +1,5 @@
1
+ # To run remote tests you'll need to copy this file to credentials.yml
2
+ # in the same directory and change the values to match your spreedly environment.
3
+
4
+ environment_key: "YOUR-SPREEDLY-ENVIRONMENT-KEY"
5
+ access_secret: "YOUR-SPREEDLY-ACCESS-SECRET"
@@ -23,7 +23,7 @@ module Spreedly
23
23
  end
24
24
 
25
25
  def load_personal_creds
26
- return {} unless File.exists?(personal_creds_file)
26
+ return {} unless File.exist?(personal_creds_file)
27
27
 
28
28
  personal_creds = YAML.load(File.read(personal_creds_file))
29
29
  return {} unless personal_creds
@@ -1,16 +1,19 @@
1
1
 
2
2
  module Spreedly
3
-
4
3
  module CreationHelper
5
-
6
4
  def create_card_on(environment, options = {})
7
- deets = default_card_deets.merge(options)
8
- environment.add_credit_card(deets).payment_method
5
+ options = default_card_options.merge(options)
6
+ environment.add_credit_card(options).payment_method
9
7
  end
10
8
 
11
9
  def create_failed_card_on(environment, options = {})
12
- deets = default_card_deets.merge(number: '4012888888881881').merge(options)
13
- environment.add_credit_card(deets).payment_method
10
+ options = default_card_options.merge(number: '4012888888881881').merge(options)
11
+ environment.add_credit_card(options).payment_method
12
+ end
13
+
14
+ def create_threeds_2_card_on(environment, options = {})
15
+ options = default_card_options.merge(number: '4556761029983886').merge(options)
16
+ environment.add_credit_card(options).payment_method
14
17
  end
15
18
 
16
19
  def create_sprel_on(environment)
@@ -21,9 +24,9 @@ module Spreedly
21
24
 
22
25
  private
23
26
 
24
- def default_card_deets
27
+ def default_card_options
25
28
  {
26
- email: 'perrin@wot.com', number: '5555555555554444', month: 1, year: 2019,
29
+ email: 'perrin@wot.com', number: '5555555555554444', month: 1, year: 2023,
27
30
  last_name: 'Aybara', first_name: 'Perrin', retained: true
28
31
  }
29
32
  end
@@ -51,7 +51,7 @@ class RemoteAddCreditCardTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  def test_successfull_add_using_full_name
54
- t = @environment.add_credit_card(number: '5555555555554444', month: 1, year: 2019, full_name: "Kvothe Jones")
54
+ t = @environment.add_credit_card(number: '5555555555554444', month: 1, year: 2023, full_name: "Kvothe Jones")
55
55
  assert t.succeeded?
56
56
  assert_equal "Kvothe", t.payment_method.first_name
57
57
  assert_equal "Jones", t.payment_method.last_name
@@ -62,7 +62,7 @@ class RemoteAddCreditCardTest < Test::Unit::TestCase
62
62
  private
63
63
  def card_deets(options = {})
64
64
  {
65
- email: 'perrin@wot.com', number: '5555555555554444', month: 1, year: 2019,
65
+ email: 'perrin@wot.com', number: '5555555555554444', month: 1, year: 2023,
66
66
  last_name: 'Aybara', first_name: 'Perrin', data: "occupation: Blacksmith"
67
67
  }.merge(options)
68
68
  end
@@ -25,9 +25,9 @@ class RemoteAddReceiverTest < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_add_test_receiver
28
- receiver = @environment.add_receiver(:test, 'http://testserver.com')
28
+ receiver = @environment.add_receiver(:test, 'http://spreedly-echo.herokuapp.com')
29
29
  assert_equal "test", receiver.receiver_type
30
- assert_equal 'http://testserver.com', receiver.hostnames
30
+ assert_equal 'http://spreedly-echo.herokuapp.com', receiver.hostnames
31
31
  end
32
32
 
33
33
  def test_need_active_account
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RemoteAuthorizeTest < Test::Unit::TestCase
4
-
5
4
  def setup
6
5
  @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
7
6
  end
@@ -35,6 +34,23 @@ class RemoteAuthorizeTest < Test::Unit::TestCase
35
34
  assert_equal 899, transaction.amount
36
35
  end
37
36
 
37
+ def test_successful_authorize_with_stored_credentials
38
+ gateway_token = @environment.add_gateway(:test).token
39
+ card_token = create_card_on(@environment).token
40
+
41
+ transaction = @environment.authorize_on_gateway(
42
+ gateway_token,
43
+ card_token,
44
+ 899,
45
+ stored_credential_initiator: :merchant,
46
+ stored_credential_reason_type: :installment
47
+ )
48
+
49
+ assert transaction.succeeded?
50
+ assert_equal 'merchant', transaction.stored_credential_initiator
51
+ assert_equal 'installment', transaction.stored_credential_reason_type
52
+ end
53
+
38
54
  def test_failed_authorize
39
55
  gateway_token = @environment.add_gateway(:test).token
40
56
  card_token = create_failed_card_on(@environment).token
@@ -44,5 +60,4 @@ class RemoteAuthorizeTest < Test::Unit::TestCase
44
60
  assert_equal "Unable to process the authorize transaction.", transaction.message
45
61
  assert_equal gateway_token, transaction.gateway_token
46
62
  end
47
-
48
63
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteCompleteTransactionTest < Test::Unit::TestCase
4
+ def setup
5
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
6
+ end
7
+
8
+ def test_successful_complete_a_3ds_transaction
9
+ gateway_token = @environment.add_gateway(:test).token
10
+ card_token = create_threeds_2_card_on(@environment).token
11
+ base64_encoded_browser_info = "eyJ3aWR0aCI6MTY4MCwiaGVpZ2h0IjoxMDUwLCJkZXB0aCI6MjQsInRpbWV6b25lIjoyNDAsInVzZXJfYWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNF80KSBBcHBsZVdlYktpdC82MDUuMS4xNSAoS0hUTUwsIGxpa2UgR2Vja28pIFZlcnNpb24vMTIuMSBTYWZhcmkvNjA1LjEuMTUiLCJqYXZhIjp0cnVlLCJsYW5ndWFnZSI6ImVuLVVTIn0="
12
+ purchase = @environment.purchase_on_gateway(
13
+ gateway_token,
14
+ card_token,
15
+ 3003,
16
+ browser_info: base64_encoded_browser_info,
17
+ three_ds_version: '2.0',
18
+ redirect_url: 'https://example.com/redirect',
19
+ callback_url: 'https://example.com/callback',
20
+ attempt_3dsecure: true
21
+ )
22
+ assert_equal 'pending', purchase.state
23
+
24
+ complete_transaction = @environment.complete_transaction(purchase.token)
25
+ assert_equal 'succeeded', complete_transaction.state
26
+ end
27
+ end
@@ -38,9 +38,9 @@ class RemoteDeliverPaymentMethodTest < Test::Unit::TestCase
38
38
  assert_equal(true, transaction.succeeded?)
39
39
  assert_equal(card_token, transaction.payment_method.token)
40
40
  assert_equal(receiver_token, transaction.receiver.token)
41
- assert_match(/Successfully dumped 0 post variables.*Post body was 109 chars long/m, transaction.response.body)
41
+ assert_match(/HOST: spreedly-echo.herokuapp.com\nCONNECTION: close/m, transaction.response.body)
42
42
  assert_equal('200', transaction.response.status)
43
- assert_match(/Server: Apache/m, transaction.response.headers)
43
+ assert_match(/Server: thin/m, transaction.response.headers)
44
44
  end
45
45
 
46
46
  private
@@ -49,7 +49,7 @@ class RemoteDeliverPaymentMethodTest < Test::Unit::TestCase
49
49
  end
50
50
 
51
51
  def url
52
- 'http://posttestserver.com/post.php'
52
+ 'https://spreedly-echo.herokuapp.com'
53
53
  end
54
54
 
55
55
  def receiver_test_credentials
@@ -10,7 +10,7 @@ class RemoteGatewayOptionsTest < Test::Unit::TestCase
10
10
  gateway_classes = @environment.gateway_options
11
11
  braintree = gateway_classes.select { |each| each.name == "Braintree" }.first
12
12
  assert_equal "http://www.braintreepaymentsolutions.com/", braintree.homepage
13
- assert_equal %w(credit_card third_party_token apple_pay android_pay), braintree.payment_methods
13
+ assert_equal %w(credit_card third_party_token apple_pay android_pay google_pay), braintree.payment_methods
14
14
  assert_equal %w(asia_pacific europe north_america), braintree.regions
15
15
  assert_equal %w(orange blue), braintree.auth_modes.map { |e| e.auth_mode_type }
16
16
  assert_equal %w(login password), braintree.auth_modes.first.credentials.map { |e| e.name }
@@ -35,6 +35,24 @@ class RemotePurchaseTest < Test::Unit::TestCase
35
35
  assert_equal 144, transaction.amount
36
36
  end
37
37
 
38
+ def test_successful_purchase_with_stored_credentials
39
+ gateway_token = @environment.add_gateway(:test).token
40
+ card_token = create_card_on(@environment).token
41
+
42
+ transaction = @environment.purchase_on_gateway(
43
+ gateway_token,
44
+ card_token,
45
+ 899,
46
+ stored_credential_initiator: :merchant,
47
+ stored_credential_reason_type: :installment
48
+ )
49
+
50
+ assert transaction.succeeded?
51
+ assert_equal 'merchant', transaction.stored_credential_initiator
52
+ assert_equal 'installment', transaction.stored_credential_reason_type
53
+ end
54
+
55
+
38
56
  def test_failed_purchase
39
57
  gateway_token = @environment.add_gateway(:test).token
40
58
  card_token = create_failed_card_on(@environment).token
@@ -66,6 +84,29 @@ class RemotePurchaseTest < Test::Unit::TestCase
66
84
  assert transaction.checkout_url
67
85
  end
68
86
 
87
+ def test_3d_secure_attempt_transaction_arguments
88
+ gateway_token = @environment.add_gateway(:test).token
89
+ card_token = create_card_on(@environment, number: '4556761029983886', retained: false).token
90
+ browser_info = "eyJ3aWR0aCI6MzAwOCwiaGVpZ2h0IjoxNjkyLCJkZXB0aCI6MjQsInRpbWV6b25lIjoyNDAsInVzZXJfYWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMC4xNDsgcnY6NjguMCkgR2Vja28vMjAxMDAxMDEgRmlyZWZveC82OC4wIiwiamF2YSI6ZmFsc2UsImxhbmd1YWdlIjoiZW4tVVMiLCJhY2NlcHRfaGVhZGVyIjoidGV4dC9odG1sLGFwcGxpY2F0aW9uL3hodG1sK3htbCxhcHBsaWNhdGlvbi94bWwifQ=="
91
+ transaction = @environment.purchase_on_gateway(gateway_token, card_token, 3004,
92
+ order_id: "8675",
93
+ description: "SuperDuper",
94
+ ip: "183.128.100.103",
95
+ email: "fred@example.com",
96
+ merchant_name_descriptor: "Real Stuff",
97
+ merchant_location_descriptor: "Raleigh",
98
+ retain_on_success: true,
99
+ redirect_url: "https://example.com/redirect",
100
+ callback_url: "https://example.com/callback",
101
+ browser_info: browser_info,
102
+ attempt_3dsecure: true,
103
+ three_ds_version: "2.0")
104
+
105
+ assert_equal "pending", transaction.state
106
+ assert_equal "https://example.com/redirect", transaction.redirect_url
107
+ assert_equal "device_fingerprint", transaction.required_action
108
+ end
109
+
69
110
  def test_optional_arguments
70
111
  gateway_token = @environment.add_gateway(:test).token
71
112
  card_token = create_card_on(@environment, retained: false).token
@@ -89,6 +130,7 @@ class RemotePurchaseTest < Test::Unit::TestCase
89
130
  assert_equal "fred@example.com", transaction.email
90
131
  assert_equal "perrin@wot.com", transaction.payment_method.email
91
132
  assert_match /\d/, transaction.gateway_transaction_id
133
+ assert_match "Purchase", transaction.transaction_type
92
134
  end
93
135
 
94
136
  def test_gateway_specific_fields
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteRecachePaymentMethodTest < 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.recache_payment_method('payment_method_token')
12
+ end
13
+ end
14
+
15
+ def test_payment_method_token_token_not_found
16
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified payment method.") do
17
+ @environment.recache_payment_method('unknown_token')
18
+ end
19
+ end
20
+
21
+ def test_successful_recache
22
+ card_token = create_card_on(@environment).token
23
+
24
+ transaction = @environment.recache_payment_method(card_token, verification_value: '123')
25
+
26
+ assert transaction.succeeded?
27
+ assert_equal 'retained', transaction.payment_method.storage_state
28
+ end
29
+
30
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteRedactReceiverTest < Test::Unit::TestCase
4
+ def setup
5
+ @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
6
+ end
7
+
8
+ def test_successful_redact
9
+ receiver = @environment.add_receiver(:test, 'https://sandbox.usaepay.com')
10
+
11
+ transaction = @environment.redact_receiver(receiver.token)
12
+
13
+ assert transaction.succeeded?
14
+ assert_equal 'redacted', transaction.state
15
+ end
16
+ end
@@ -56,7 +56,7 @@ class RemoteUpdateCreditCardTest < Test::Unit::TestCase
56
56
  private
57
57
  def card_deets(options = {})
58
58
  {
59
- email: 'cauthon@wot.com', month: 1, year: 2019,
59
+ email: 'cauthon@wot.com', month: 1, year: 2023,
60
60
  last_name: 'Cauthon', first_name: 'Mat',
61
61
  eligible_for_card_updater: 'false'
62
62
  }.merge(options)
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'mocha/setup'
3
3
  require 'awesome_print'
4
+ require 'pry'
4
5
  require 'logger'
5
6
  require 'log_buddy'
6
7
  require 'spreedly'
@@ -24,6 +24,7 @@ class AddCreditCreditCardTest < Test::Unit::TestCase
24
24
 
25
25
  assert_equal "AXaBXfVUqhaGMg8ytf8isiMAAL9", t.payment_method.token
26
26
  assert_equal "Eland Venture", t.payment_method.full_name
27
+ assert_equal 'credit_card', t.payment_method.payment_method_type
27
28
  assert_equal "Don't test everything here, since find_payment_method tests it all.", t.payment_method.data
28
29
 
29
30
  assert t.payment_method.eligible_for_card_updater
@@ -121,5 +122,3 @@ class AddCreditCreditCardTest < Test::Unit::TestCase
121
122
  end
122
123
 
123
124
  end
124
-
125
-
@@ -28,11 +28,15 @@ class AuthorizeTest < Test::Unit::TestCase
28
28
  assert_equal 'Tax Free Zone', t.merchant_location_descriptor
29
29
  assert_equal 'YjWxOjbpeieXsZFdAsbhM2DFgLe', t.gateway_token
30
30
  assert_equal "44", t.gateway_transaction_id
31
+ assert_equal "three-ds-context", t.three_ds_context
32
+ assert_equal "Authorization", t.transaction_type
31
33
  assert_equal "TheName", t.gateway_specific_fields[:litle][:descriptor_name]
32
34
  assert_equal "33411441", t.gateway_specific_fields[:litle][:descriptor_phone]
33
35
  assert_equal "844", t.gateway_specific_fields[:stripe][:application_fee]
36
+ assert_equal "credit", t.gateway_specific_response_fields[:stripe][:card_funding]
34
37
 
35
38
  assert_equal 'Nh2Vw0kAoSQvcJDpK52q4dZlrVJ', t.payment_method.token
39
+ assert_equal 'credit_card', t.payment_method.payment_method_type
36
40
  assert_equal 'Forthrast', t.payment_method.last_name
37
41
 
38
42
  assert t.response.success
@@ -67,11 +71,13 @@ class AuthorizeTest < Test::Unit::TestCase
67
71
  [ './merchant_name_descriptor', 'TRain' ],
68
72
  [ './merchant_location_descriptor', 'British Colombia' ],
69
73
  [ './gateway_specific_fields/braintree/customer_id', '1143' ],
70
- [ './retain_on_success', 'true' ]
74
+ [ './retain_on_success', 'true' ],
75
+ [ './continue_caching', 'true']
71
76
  end
72
77
 
73
78
 
74
79
  private
80
+
75
81
  def authorize_using(response)
76
82
  @environment.stubs(:raw_ssl_request).returns(response)
77
83
  @environment.authorize_on_gateway("IgnoredGatewayTokenSinceResponseIsStubbed", "IgnoredPaymentMethodTokenSinceResponseIsStubbed", 5921)
@@ -88,7 +94,8 @@ class AuthorizeTest < Test::Unit::TestCase
88
94
  gateway_specific_fields: {
89
95
  braintree: { customer_id: "1143" }
90
96
  },
91
- retain_on_success: true
97
+ retain_on_success: true,
98
+ continue_caching: true
92
99
  }
93
100
  end
94
101
 
@@ -28,6 +28,8 @@ class CaptureTest < Test::Unit::TestCase
28
28
  assert_equal 'Tax Free Zone', t.merchant_location_descriptor
29
29
  assert_equal 'SoPblCOGDwaRyym68XGWeRiCy1C', t.gateway_token
30
30
  assert_equal 'PH6U2tyFWtDSVp88bNW2nnGy5rk', t.reference_token
31
+ assert_equal 'Capture', t.transaction_type
32
+ assert_equal "credit", t.gateway_specific_response_fields[:stripe][:card_funding]
31
33
 
32
34
  assert t.response.success
33
35
  assert_equal 'Successful capture', t.response.message
@@ -22,6 +22,7 @@ class FindPaymentMethodTest < Test::Unit::TestCase
22
22
  assert_equal(1369504152, card.created_at.to_i)
23
23
  assert_equal(1369508044, card.updated_at.to_i)
24
24
  assert_equal('master', card.card_type)
25
+ assert_equal('credit_card', card.payment_method_type)
25
26
  assert_equal('Alcatraz', card.first_name)
26
27
  assert_equal('Smedry', card.last_name)
27
28
  assert_equal('8', card.month)
@@ -53,25 +53,31 @@ class GatewayOptionsTest < Test::Unit::TestCase
53
53
  def test_characteristics
54
54
  @environment.stubs(:raw_ssl_request).returns(successful_gateway_options_response)
55
55
  gateway_class = @environment.gateway_options.first
56
-
57
- [ :supports_purchase,
56
+ characteristics = gateway_class.class.fields.select{|f| f =~ /supports/ }.sort
57
+ expected_characteristics = [
58
+ :supports_3dsecure_authorize,
59
+ :supports_3dsecure_purchase,
60
+ :supports_3dsecure_2_authorize,
61
+ :supports_3dsecure_2_purchase,
62
+ :supports_3dsecure_2_mpi_authorize,
63
+ :supports_3dsecure_2_mpi_purchase,
58
64
  :supports_authorize,
59
65
  :supports_capture,
60
66
  :supports_credit,
67
+ :supports_fraud_review,
61
68
  :supports_general_credit,
62
- :supports_void,
63
- :supports_reference_purchase,
64
- :supports_purchase_via_preauthorization,
65
- :supports_offsite_purchase,
66
69
  :supports_offsite_authorize,
67
- :supports_3dsecure_purchase,
68
- :supports_3dsecure_authorize,
70
+ :supports_offsite_purchase,
71
+ :supports_purchase,
72
+ :supports_purchase_via_preauthorization,
73
+ :supports_reference_purchase,
74
+ :supports_remove,
69
75
  :supports_store,
70
- :supports_fraud_review,
71
- ].each do |c|
72
- assert gateway_class.send("#{c}?")
73
- end
76
+ :supports_verify,
77
+ :supports_void,
78
+ ].sort
74
79
 
80
+ assert_equal expected_characteristics, characteristics
75
81
  assert !gateway_class.send(:supports_remove?)
76
82
  end
77
83
  end
@@ -23,6 +23,7 @@ class ListPaymentMethodsTest < Test::Unit::TestCase
23
23
 
24
24
  assert_equal 'Perrin Aybara', list.first.full_name
25
25
  assert_equal 'Mat Cauthon', list[1].full_name
26
+ assert_equal 'credit_card', list.first.payment_method_type
26
27
  assert_equal 'test_vault:4111111111111111', list[2].third_party_token
27
28
  assert_equal 'retained', list[3].storage_state
28
29
  assert_equal '4321', list[4].account_number_display_digits
@@ -40,6 +40,18 @@ class ListTransactionsTest < Test::Unit::TestCase
40
40
  assert_request_url 'https://core.spreedly.com/v1/payment_methods/SomePaymentMethodToken/transactions.xml?since_token=SinceToken' do
41
41
  @environment.list_transactions('SinceToken', 'SomePaymentMethodToken')
42
42
  end
43
+
44
+ assert_request_url 'https://core.spreedly.com/v1/transactions.xml?order=asc' do
45
+ @environment.list_transactions(nil, nil, order: :asc)
46
+ end
47
+
48
+ assert_request_url 'https://core.spreedly.com/v1/transactions.xml?since_token=SinceToken&count=10&state=succeeded' do
49
+ @environment.list_transactions('SinceToken', nil, state: :succeeded, count: 10)
50
+ end
51
+
52
+ assert_request_url 'https://core.spreedly.com/v1/payment_methods/SomePaymentMethodToken/transactions.xml?since_token=SinceToken&count=10&order=asc&state=succeeded' do
53
+ @environment.list_transactions('SinceToken', 'SomePaymentMethodToken', order: :asc, state: :succeeded, count: 10)
54
+ end
43
55
  end
44
56
 
45
57
  private
@@ -29,6 +29,8 @@ class PurchaseTest < Test::Unit::TestCase
29
29
  assert_equal 'YOaCn5a9xRaBTGgmGAWbkgWUuqv', t.gateway_token
30
30
  assert_equal '8xXXIPGXTaPXysDA5OUpgnjTEjK', t.payment_method.token
31
31
  assert_equal "44", t.gateway_transaction_id
32
+ assert_equal "Purchase", t.transaction_type
33
+ assert_equal "three-ds-context", t.three_ds_context
32
34
 
33
35
  assert t.response.success
34
36
  assert_equal 'Successful purchase', t.response.message
@@ -54,6 +56,59 @@ class PurchaseTest < Test::Unit::TestCase
54
56
  assert_equal '', t.shipping_address.phone_number
55
57
  end
56
58
 
59
+ def test_successful_3dsecure_purchase_attempt
60
+ t = purchase_using(successful_purchase_3dsecure_attempt_response)
61
+
62
+ assert_kind_of(Spreedly::Purchase, t)
63
+ assert_equal 'Btcyks35m4JLSNOs9ymJoNQLjeX', t.token
64
+ assert_equal 144, t.amount
65
+ assert t.on_test_gateway?
66
+ assert_equal Time.parse("2013-07-31 19:46:26 UTC"), t.created_at
67
+ assert_equal Time.parse("2013-07-31 19:46:32 UTC"), t.updated_at
68
+ assert_equal 'USD', t.currency_code
69
+ assert !t.succeeded?
70
+ assert_equal 'pending', t.state
71
+ assert_equal 'none', t.required_action
72
+ assert_equal 'http://challenge_url.test', t.challenge_url
73
+ assert_equal 'challenge form data', t.challenge_form
74
+ assert_equal 'device fingerprint form data', t.device_fingerprint_form
75
+ assert_equal '', t.order_id
76
+ assert_equal '', t.ip
77
+ assert_equal '4 Shardblades', t.description
78
+ assert_equal '', t.merchant_name_descriptor
79
+ assert_equal '', t.merchant_location_descriptor
80
+ assert_equal 'YOaCn5a9xRaBTGgmGAWbkgWUuqv', t.gateway_token
81
+ assert_equal '8xXXIPGXTaPXysDA5OUpgnjTEjK', t.payment_method.token
82
+ assert_equal "44", t.gateway_transaction_id
83
+
84
+ assert t.response.success
85
+ assert_equal 'Checked enrollment status', t.response.message
86
+ assert !t.response.pending
87
+ assert !t.response.fraud_review
88
+ assert_equal '', t.response.error_code
89
+ assert_equal Time.parse('2013-07-31T19:46:26Z'), t.response.created_at
90
+ assert_equal Time.parse('2013-07-31T19:46:27Z'), t.response.updated_at
91
+
92
+ assert_equal 'https://example.com/callback_url', t.callback_url
93
+ assert_equal 'https://example.com/redirect_url', t.redirect_url
94
+ assert_equal '', t.checkout_url
95
+
96
+ assert t.checkout_form.include?('<form action="https://core.spreedly.com/test/1234/auth/1234" method="POST">')
97
+ assert t.checkout_form.include?('<input name="PaReq" value="" type="hidden"/>')
98
+ assert t.checkout_form.include?('<input name="MD" value="" type="hidden"/>')
99
+ assert t.checkout_form.include?('<input name="TermUrl" value="https://core.spreedly.com/transaction/Btcyks35m4JLSNOs9ymJoNQLjeX/redirect" type="hidden"/>')
100
+ assert t.checkout_form.include?('<input name="Complete" value="Authorize Transaction" type="submit"/>')
101
+
102
+ assert_equal '', t.shipping_address.name
103
+ assert_equal '', t.shipping_address.address1
104
+ assert_equal '', t.shipping_address.address2
105
+ assert_equal '', t.shipping_address.city
106
+ assert_equal '', t.shipping_address.state
107
+ assert_equal '', t.shipping_address.zip
108
+ assert_equal '', t.shipping_address.country
109
+ assert_equal '', t.shipping_address.phone_number
110
+ end
111
+
57
112
  def test_failed_purchase
58
113
  t = purchase_using(failed_purchase_response)
59
114
 
@@ -94,7 +149,8 @@ class PurchaseTest < Test::Unit::TestCase
94
149
  [ './ip', '183.128.100.103' ],
95
150
  [ './merchant_name_descriptor', 'Real Stuff' ],
96
151
  [ './merchant_location_descriptor', 'Raleigh' ],
97
- [ './retain_on_success', 'true' ]
152
+ [ './retain_on_success', 'true' ],
153
+ [ './continue_caching', 'true']
98
154
  end
99
155
 
100
156
 
@@ -112,7 +168,8 @@ class PurchaseTest < Test::Unit::TestCase
112
168
  ip: "183.128.100.103",
113
169
  merchant_name_descriptor: "Real Stuff",
114
170
  merchant_location_descriptor: "Raleigh",
115
- retain_on_success: true
171
+ retain_on_success: true,
172
+ continue_caching: true
116
173
  }
117
174
  end
118
175
 
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+ require 'unit/response_stubs/recache_payment_method_stubs'
3
+
4
+ class RecachePaymentMethodTest < Test::Unit::TestCase
5
+
6
+ include RecachePaymentMethodStubs
7
+
8
+ def setup
9
+ @environment = Spreedly::Environment.new("key", "secret")
10
+ end
11
+
12
+ def test_successful_recache
13
+ t = recache_using(successful_recache_payment_method_response)
14
+
15
+ assert_kind_of(Spreedly::RecacheSensitiveData, t)
16
+ assert_equal '2BSe5T6FHpypph3ensF7m3Nb3qk', t.token
17
+ assert_equal Time.parse('2013-08-05 17:43:41 UTC'), t.created_at
18
+ assert_equal Time.parse('2013-08-05 17:43:41 UTC'), t.updated_at
19
+ assert t.succeeded?
20
+ assert_equal 'Succeeded!', t.message
21
+ assert_equal 'succeeded', t.state
22
+ assert_equal 'retained', t.payment_method.storage_state
23
+ assert_equal 'RvsxKgbAZBmiZHEPhhTcOQzJeC2', t.payment_method.token
24
+ end
25
+
26
+ private
27
+
28
+ def recache_using(response)
29
+ @environment.stubs(:raw_ssl_request).returns(response)
30
+ @environment.recache_payment_method("IgnoredTokenSinceResponseIsStubbed", verification_value: 'VerificationValue')
31
+ end
32
+
33
+ end
34
+
@@ -28,6 +28,7 @@ class RefundTest < Test::Unit::TestCase
28
28
  assert_equal 'Tax Free Zone', t.merchant_location_descriptor
29
29
  assert_equal 'XYI0V2l4KC1cAm6Y3c2kG5loJaA', t.gateway_token
30
30
  assert_equal 'RkIAltzr49eXuWc7ajBjLLeKZt8', t.reference_token
31
+ assert_equal 'Credit', t.transaction_type
31
32
 
32
33
  assert t.response.success
33
34
  assert_equal 'Successful credit', t.response.message