spreedly 2.0.11 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +29 -0
  3. data/README.md +17 -6
  4. data/lib/spreedly.rb +4 -0
  5. data/lib/spreedly/connection.rb +0 -1
  6. data/lib/spreedly/environment.rb +61 -3
  7. data/lib/spreedly/gateway_class.rb +4 -3
  8. data/lib/spreedly/payment_methods/credit_card.rb +2 -1
  9. data/lib/spreedly/receiver.rb +30 -0
  10. data/lib/spreedly/transactions/deliver_payment_method.rb +31 -0
  11. data/lib/spreedly/transactions/recache_sensitive_data.rb +17 -0
  12. data/lib/spreedly/transactions/transaction.rb +6 -0
  13. data/lib/spreedly/transactions/verification.rb +12 -0
  14. data/lib/spreedly/urls.rb +12 -0
  15. data/lib/spreedly/version.rb +1 -1
  16. data/test/remote/remote_add_gateway_test.rb +1 -3
  17. data/test/remote/remote_add_receiver_test.rb +40 -0
  18. data/test/remote/remote_deliver_payment_method_test.rb +65 -0
  19. data/test/remote/remote_update_credit_card_test.rb +3 -1
  20. data/test/remote/remote_verify_test.rb +48 -0
  21. data/test/unit/add_receiver_test.rb +53 -0
  22. data/test/unit/deliver_payment_method_test.rb +73 -0
  23. data/test/unit/find_payment_method_test.rb +1 -0
  24. data/test/unit/gateway_options_test.rb +1 -0
  25. data/test/unit/response_stubs/add_credit_card_stubs.rb +3 -0
  26. data/test/unit/response_stubs/add_gateway_stubs.rb +1 -0
  27. data/test/unit/response_stubs/add_receiver_stubs.rb +26 -0
  28. data/test/unit/response_stubs/authorization_stubs.rb +4 -0
  29. data/test/unit/response_stubs/deliver_payment_method_stubs.rb +80 -0
  30. data/test/unit/response_stubs/find_gateway_stubs.rb +1 -0
  31. data/test/unit/response_stubs/find_payment_method_stubs.rb +5 -1
  32. data/test/unit/response_stubs/find_transaction_stubs.rb +4 -0
  33. data/test/unit/response_stubs/gateway_options_stubs.rb +4 -0
  34. data/test/unit/response_stubs/list_gateways_stubs.rb +2 -0
  35. data/test/unit/response_stubs/list_payment_methods_stubs.rb +4 -0
  36. data/test/unit/response_stubs/list_transactions_stubs.rb +2 -0
  37. data/test/unit/response_stubs/purchase_stubs.rb +4 -0
  38. data/test/unit/response_stubs/redact_gateway_stubs.rb +1 -0
  39. data/test/unit/response_stubs/redact_payment_method_stubs.rb +2 -0
  40. data/test/unit/response_stubs/retain_payment_method_stubs.rb +4 -0
  41. data/test/unit/response_stubs/update_credit_card_stubs.rb +2 -0
  42. data/test/unit/response_stubs/verification_stubs.rb +143 -0
  43. data/test/unit/verify_test.rb +81 -0
  44. metadata +25 -4
  45. data/lib/certs/cacert.pem +0 -7815
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteAddReceiverTest < 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.add_receiver(:test, 'http://api.example.com/post')
12
+ end
13
+ end
14
+
15
+ def test_non_existent_receiver_type
16
+ assert_raise_with_message(Spreedly::UnexpectedResponseError, "Failed with 403 Forbidden") do
17
+ @environment.add_receiver(:non_existent, nil)
18
+ end
19
+ end
20
+
21
+ def test_add_test_receiver_sans_hostname
22
+ assert_raise_with_message(Spreedly::TransactionCreationError, "Hostnames can't be blank") do
23
+ @environment.add_receiver(:test, nil)
24
+ end
25
+ end
26
+
27
+ def test_add_test_receiver
28
+ receiver = @environment.add_receiver(:test, 'http://api.example.com/post')
29
+ assert_equal "test", receiver.receiver_type
30
+ assert_equal 'http://api.example.com/post', receiver.hostnames
31
+ end
32
+
33
+ # Coming soon
34
+ # def test_need_active_account
35
+ # assert_raise_with_message(Spreedly::PaymentRequiredError, "Your account has not been activated for real transactions. Please update your subscription settings.") do
36
+ # @environment.add_receiver(:braintree)
37
+ # end
38
+ # end
39
+
40
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteDeliverPaymentMethodTest < 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.deliver_to_receiver('rtoken', 'ptoken', headers: headers, url: url, body: receiver_body)
12
+ end
13
+ end
14
+
15
+ def test_payment_method_not_found
16
+ receiver_token = @environment.add_receiver(:test, url).token
17
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified payment method.") do
18
+ @environment.deliver_to_receiver(receiver_token, 'unknown_payment_method',
19
+ headers: headers, url: url, body: receiver_body)
20
+ end
21
+ end
22
+
23
+ def test_receiver_not_found
24
+ card_token = create_card_on(@environment).token
25
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified receiver.") do
26
+ @environment.deliver_to_receiver('unknown_receiver', card_token,
27
+ headers: headers, url: url, body: receiver_body)
28
+ end
29
+ end
30
+
31
+ def test_successfully_deliver_receiver
32
+ receiver_token = @environment.add_receiver(:test, url, receiver_test_credentials).token
33
+ card_token = create_card_on(@environment).token
34
+
35
+ transaction = @environment.deliver_to_receiver(receiver_token, card_token,
36
+ headers: headers, url: url, body: receiver_body)
37
+
38
+ assert_equal(true, transaction.succeeded?)
39
+ assert_equal(card_token, transaction.payment_method.token)
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)
42
+ assert_equal('200', transaction.response.status)
43
+ assert_match(/Server: Apache/m, transaction.response.headers)
44
+ end
45
+
46
+ private
47
+ def headers
48
+ { 'Content-Type' => 'application/json' }
49
+ end
50
+
51
+ def url
52
+ 'http://posttestserver.com/post.php'
53
+ end
54
+
55
+ def receiver_test_credentials
56
+ [
57
+ { name: 'user_name', value: 'test_user', safe: 'true' },
58
+ { name: 'secret_password', value: 'qAAJ6yWN'}
59
+ ]
60
+ end
61
+
62
+ def receiver_body
63
+ '{"product_id":"916593","card_number":"{{ credit_card_number }}","user_name":"{{user_name}}","secret_password":"{{secret_password}}"}'
64
+ end
65
+ end
@@ -41,13 +41,15 @@ class RemoteUpdateCreditCardTest < Test::Unit::TestCase
41
41
  assert_equal 'Cauthon', result.last_name
42
42
  assert_equal 'Mat', result.first_name
43
43
  assert_equal 'cauthon@wot.com', result.email
44
+ assert_equal false, result.eligible_for_card_updater
44
45
  end
45
46
 
46
47
  private
47
48
  def card_deets(options = {})
48
49
  {
49
50
  email: 'cauthon@wot.com', month: 1, year: 2019,
50
- last_name: 'Cauthon', first_name: 'Mat'
51
+ last_name: 'Cauthon', first_name: 'Mat',
52
+ eligible_for_card_updater: 'false'
51
53
  }.merge(options)
52
54
  end
53
55
 
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteVerifyTest < 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.verify_on_gateway('gtoken', 'ptoken')
12
+ end
13
+ end
14
+
15
+ def test_payment_method_not_found
16
+ assert_raise_with_message(Spreedly::TransactionCreationError, "There is no payment method corresponding to the specified payment method token.") do
17
+ @environment.verify_on_gateway('gateway_token', 'unknown_payment_method')
18
+ end
19
+ end
20
+
21
+ def test_gateway_not_found
22
+ card_token = create_card_on(@environment).token
23
+ assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified gateway.") do
24
+ @environment.verify_on_gateway('unknown_gateway', card_token)
25
+ end
26
+ end
27
+
28
+ def test_successful_verify
29
+ gateway_token = @environment.add_gateway(:test).token
30
+ card_token = create_card_on(@environment).token
31
+
32
+ transaction = @environment.verify_on_gateway(gateway_token, card_token)
33
+ assert transaction.succeeded?
34
+ assert_equal card_token, transaction.payment_method.token
35
+ assert_equal gateway_token, transaction.gateway_token
36
+ end
37
+
38
+ def test_failed_verify
39
+ gateway_token = @environment.add_gateway(:test).token
40
+ card_token = create_failed_card_on(@environment).token
41
+
42
+ transaction = @environment.verify_on_gateway(gateway_token, card_token)
43
+ assert !transaction.succeeded?
44
+ assert_equal "Unable to process the verify transaction.", transaction.message
45
+ assert_equal gateway_token, transaction.gateway_token
46
+ end
47
+
48
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'unit/response_stubs/add_receiver_stubs'
3
+
4
+ class AddReceiverTest < Test::Unit::TestCase
5
+
6
+ include AddReceiverStubs
7
+
8
+ def setup
9
+ @environment = Spreedly::Environment.new("key", "secret")
10
+ end
11
+
12
+ def test_add_receiver
13
+ @environment.stubs(:raw_ssl_request).returns(successful_add_receiver_response)
14
+
15
+ receiver = @environment.add_receiver(:test, 'http://api.example.com/post')
16
+ assert_equal("6SzKN5kR5QSa7JvGFwpjka9zkBA", receiver.token)
17
+ assert_equal("test", receiver.receiver_type)
18
+ assert_equal('http://api.example.com/post', receiver.hostnames)
19
+ assert_equal({"app-id"=>"1234", "app-secret"=>nil}, receiver.credentials)
20
+ end
21
+
22
+ def test_request_body_params
23
+ body = get_request_body(successful_add_receiver_response) do
24
+ @environment.add_receiver(:test, 'http://api.example.com/post', receiver_test_credentials)
25
+ end
26
+
27
+ receiver = body.xpath('./receiver')
28
+ assert_xpaths_in receiver,
29
+ [ './receiver_type', 'test' ],
30
+ [ './hostnames', 'http://api.example.com/post' ]
31
+
32
+ first_cred = receiver.xpath('./credentials/credential')[0]
33
+ assert_xpaths_in first_cred,
34
+ [ './name', 'partner_id' ],
35
+ [ './value', 'the_id' ],
36
+ [ './safe', 'true' ]
37
+
38
+ second_cred = receiver.xpath('./credentials/credential')[1]
39
+ assert_xpaths_in second_cred,
40
+ [ './name', 'partner_password' ],
41
+ [ './value', 'the_password' ]
42
+ end
43
+
44
+ private
45
+
46
+ def receiver_test_credentials
47
+ [
48
+ { name: 'partner_id', value: 'the_id', safe: 'true' },
49
+ { name: 'partner_password', value: 'the_password'},
50
+ ]
51
+ end
52
+
53
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+ require 'unit/response_stubs/deliver_payment_method_stubs'
3
+
4
+ class DeliverPaymentMethodTest < Test::Unit::TestCase
5
+
6
+ include DeliverPaymentMethodStubs
7
+
8
+ def setup
9
+ @environment = Spreedly::Environment.new("key", "secret")
10
+ end
11
+
12
+ def test_deliver_receiver
13
+ @environment.stubs(:raw_ssl_request).returns(successful_deliver_payment_method_response)
14
+ t = @environment.deliver_to_receiver('ReceiverToken', 'PaymentMethodToken',
15
+ headers: headers, body: receiver_body, url: url)
16
+
17
+ assert_kind_of(Spreedly::DeliverPaymentMethod, t)
18
+ assert_equal 'QguSkyc5F49S2P68RSbA2Eszkhr', t.token
19
+ assert_equal Time.parse("2014-06-20T20:24:57Z"), t.created_at
20
+ assert_equal Time.parse("2014-06-20T20:24:57Z"), t.updated_at
21
+ assert t.succeeded?
22
+ assert_equal 'succeeded', t.state
23
+ assert_equal 'Succeeded!', t.message
24
+ assert_equal '200', t.response.status
25
+ assert_equal 'test', t.receiver.receiver_type
26
+ assert_equal 'TUwHIV9A3CiEizatDZFuic6C9la', t.payment_method.token
27
+ end
28
+
29
+ def test_request_body_params
30
+ body = get_request_body(successful_deliver_payment_method_response) do
31
+ @environment.deliver_to_receiver('ReceiverToken', 'PaymentMethodToken',
32
+ headers: headers, body: receiver_body, url: url)
33
+ end
34
+
35
+ receiver = body.xpath('./delivery')
36
+ assert_xpaths_in receiver,
37
+ [ './payment_method_token', 'PaymentMethodToken' ],
38
+ [ './url', 'http://api.example.com/posts' ],
39
+ [ './headers', "Host: https://api.example.com/posts\nContent-Length: 1024\nContent-Type: application/soap+xml; charset=utf-8\nSOAPAction: https://api.example.com/posts"],
40
+ ['./body', receiver_body]
41
+ end
42
+
43
+ private
44
+ def headers
45
+ {
46
+ 'Host' => 'https://api.example.com/posts',
47
+ 'Content-Length' => 1024,
48
+ 'Content-Type' => 'application/soap+xml; charset=utf-8',
49
+ 'SOAPAction' => "https://api.example.com/posts"
50
+ }
51
+ end
52
+
53
+ def receiver_body
54
+ <<-XML
55
+ <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
56
+ <soap12:Body>
57
+ <addCOF xmlns="http://api.example.com/">
58
+ <NameOnCard>string</NameOnCard>
59
+ <CardNumber>string</CardNumber>
60
+ <ExpMonth>int</ExpMonth>
61
+ <ExpYear>int</ExpYear>
62
+ <CSC>string</CSC>
63
+ </addCOF>
64
+ </soap12:Body>
65
+ </soap12:Envelope>
66
+ XML
67
+ end
68
+
69
+ def url
70
+ 'http://api.example.com/posts'
71
+ end
72
+
73
+ end
@@ -16,6 +16,7 @@ class FindPaymentMethodTest < Test::Unit::TestCase
16
16
  assert_equal("ROGJFe89QtbJL8QvjaJNMH0UG50", card.token)
17
17
  assert_equal("alcatraz@occulators.org", card.email)
18
18
  assert_equal("4445", card.last_four_digits)
19
+ assert_equal("411111", card.first_six_digits)
19
20
  assert_equal('XXXX-XXXX-XXXX-4445', card.number)
20
21
  assert_equal("<some_attribute>5</some_attribute>", card.data)
21
22
  assert_equal(1369504152, card.created_at.to_i)
@@ -58,6 +58,7 @@ class GatewayOptionsTest < Test::Unit::TestCase
58
58
  :supports_authorize,
59
59
  :supports_capture,
60
60
  :supports_credit,
61
+ :supports_general_credit,
61
62
  :supports_void,
62
63
  :supports_reference_purchase,
63
64
  :supports_purchase_via_preauthorization,
@@ -18,6 +18,7 @@ module AddCreditCardStubs
18
18
  <data>Don't test everything here, since find_payment_method tests it all.</data>
19
19
  <storage_state>cached</storage_state>
20
20
  <last_four_digits>4942</last_four_digits>
21
+ <first_six_digits>411111</first_six_digits>
21
22
  <card_type>master</card_type>
22
23
  <first_name>Eland</first_name>
23
24
  <last_name>Venture</last_name>
@@ -31,7 +32,9 @@ module AddCreditCardStubs
31
32
  <country>UK</country>
32
33
  <phone_number>43</phone_number>
33
34
  <full_name>Eland Venture</full_name>
35
+ <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
34
36
  <payment_method_type>credit_card</payment_method_type>
37
+ <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
35
38
  <errors>
36
39
  </errors>
37
40
  <verification_value></verification_value>
@@ -11,6 +11,7 @@ module AddGatewayStubs
11
11
  <supports_authorize type="boolean">true</supports_authorize>
12
12
  <supports_capture type="boolean">true</supports_capture>
13
13
  <supports_credit type="boolean">true</supports_credit>
14
+ <supports_general_credit type="boolean">true</supports_general_credit>
14
15
  <supports_void type="boolean">true</supports_void>
15
16
  <supports_reference_purchase type="boolean">true</supports_reference_purchase>
16
17
  <supports_purchase_via_preauthorization type="boolean">true</supports_purchase_via_preauthorization>
@@ -0,0 +1,26 @@
1
+ module AddReceiverStubs
2
+
3
+ def successful_add_receiver_response
4
+ StubResponse.succeeded <<-XML
5
+ <receiver>
6
+ <receiver_type>test</receiver_type>
7
+ <token>6SzKN5kR5QSa7JvGFwpjka9zkBA</token>
8
+ <hostnames>http://api.example.com/post</hostnames>
9
+ <state>retained</state>
10
+ <created_at>2014-05-21T21:39:08Z</created_at>
11
+ <updated_at>2014-05-21T21:39:08Z</updated_at>
12
+ <credentials>
13
+ <credential>
14
+ <name>app-id</name>
15
+ <value>1234</value>
16
+ <safe>true</safe>
17
+ </credential>
18
+ <credential>
19
+ <name>app-secret</name>
20
+ </credential>
21
+ </credentials>
22
+ </receiver>
23
+ XML
24
+ end
25
+
26
+ end
@@ -44,6 +44,7 @@ module AuthorizationStubs
44
44
  <data nil="true"/>
45
45
  <storage_state>retained</storage_state>
46
46
  <last_four_digits>4444</last_four_digits>
47
+ <first_six_digits>411111</first_six_digits>
47
48
  <card_type>master</card_type>
48
49
  <first_name>John</first_name>
49
50
  <last_name>Forthrast</last_name>
@@ -58,6 +59,7 @@ module AuthorizationStubs
58
59
  <phone_number nil="true"/>
59
60
  <full_name>John Forthrast</full_name>
60
61
  <payment_method_type>credit_card</payment_method_type>
62
+ <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
61
63
  <errors>
62
64
  </errors>
63
65
  <verification_value></verification_value>
@@ -113,6 +115,7 @@ module AuthorizationStubs
113
115
  <data nil="true"/>
114
116
  <storage_state>retained</storage_state>
115
117
  <last_four_digits>1881</last_four_digits>
118
+ <first_six_digits>411111</first_six_digits>
116
119
  <card_type>visa</card_type>
117
120
  <first_name>Perrin</first_name>
118
121
  <last_name>Aybara</last_name>
@@ -127,6 +130,7 @@ module AuthorizationStubs
127
130
  <phone_number nil="true"/>
128
131
  <full_name>Perrin Aybara</full_name>
129
132
  <payment_method_type>credit_card</payment_method_type>
133
+ <eligible_for_card_updater type="boolean">true</eligible_for_card_updater>
130
134
  <errors>
131
135
  </errors>
132
136
  <verification_value></verification_value>
@@ -0,0 +1,80 @@
1
+ module DeliverPaymentMethodStubs
2
+
3
+ def successful_deliver_payment_method_response
4
+ StubResponse.succeeded <<-XML
5
+ <transaction>
6
+ <token>QguSkyc5F49S2P68RSbA2Eszkhr</token>
7
+ <transaction_type>DeliverPaymentMethod</transaction_type>
8
+ <state>succeeded</state>
9
+ <created_at>2014-06-20T20:24:57Z</created_at>
10
+ <updated_at>2014-06-20T20:24:57Z</updated_at>
11
+ <succeeded>true</succeeded>
12
+ <message>Succeeded!</message>
13
+ <response>
14
+ <status>200</status>
15
+ <headers>
16
+ <![CDATA[Date: Fri, 20 Jun 2014 20:24:57 GMT
17
+ Server: Apache
18
+ Access-Control-Allow-Origin: *
19
+ Vary: Accept-Encoding
20
+ Content-Length: 142
21
+ Connection: close
22
+ Content-Type: text/html]]>
23
+ </headers>
24
+ <body>
25
+ <![CDATA[Successfully dumped 0 post variables.
26
+ View it at http://www.posttestserver.com/data/2014/06/20/13.24.571852460525
27
+ Post body was 69 chars long.]]>
28
+ </body>
29
+ </response>
30
+ <receiver>
31
+ <receiver_type>test</receiver_type>
32
+ <token>YRfLgloedGsbYHj2YQlAo37Zjqb</token>
33
+ <hostnames>http://posttestserver.com</hostnames>
34
+ <state>retained</state>
35
+ <created_at>2014-06-20T20:24:56Z</created_at>
36
+ <updated_at>2014-06-20T20:24:56Z</updated_at>
37
+ <credentials>
38
+ <credential>
39
+ <name>app-id</name>
40
+ <value>1234</value>
41
+ <safe>true</safe>
42
+ </credential>
43
+ <credential>
44
+ <name>app-secret</name>
45
+ </credential>
46
+ </credentials>
47
+ </receiver>
48
+ <payment_method>
49
+ <token>TUwHIV9A3CiEizatDZFuic6C9la</token>
50
+ <data nil="true"/>
51
+ <storage_state>retained</storage_state>
52
+ <email nil="true"/>
53
+ <created_at>2014-06-03T14:59:27Z</created_at>
54
+ <updated_at>2014-06-20T20:24:57Z</updated_at>
55
+ <errors/>
56
+ <payment_method_type>credit_card</payment_method_type>
57
+ <first_name>Torrance</first_name>
58
+ <last_name>Dooley</last_name>
59
+ <full_name>Torrance Dooley</full_name>
60
+ <card_type>visa</card_type>
61
+ <last_four_digits>1111</last_four_digits>
62
+ <first_six_digits>411111</first_six_digits>
63
+ <month>4</month>
64
+ <year>2020</year>
65
+ <address1 nil="true"/>
66
+ <address2 nil="true"/>
67
+ <city nil="true"/>
68
+ <state nil="true"/>
69
+ <zip nil="true"/>
70
+ <country nil="true"/>
71
+ <phone_number nil="true"/>
72
+ <eligible_for_card_updater>true</eligible_for_card_updater>
73
+ <verification_value></verification_value>
74
+ <number>XXXX-XXXX-XXXX-1111</number>
75
+ </payment_method>
76
+ </transaction>
77
+ XML
78
+ end
79
+
80
+ end