spreedly 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.2
4
+ * Add support for gateway options call.
5
+
3
6
  ## 2.0.1
4
7
  * List the transactions for a payment method
5
8
  * Allow adding other gateways
@@ -20,6 +20,8 @@ module Spreedly
20
20
  http.put(endpoint.request_uri, body, headers)
21
21
  when :delete
22
22
  http.delete(endpoint.request_uri, headers)
23
+ when :options
24
+ http.request(OptionsWithResponseBody.new(endpoint.request_uri, headers))
23
25
  else
24
26
  raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
25
27
  end
@@ -36,5 +38,12 @@ module Spreedly
36
38
  http
37
39
  end
38
40
  end
41
+
42
+ class OptionsWithResponseBody < Net::HTTPRequest
43
+ METHOD = 'OPTIONS'
44
+ REQUEST_HAS_BODY = false
45
+ RESPONSE_HAS_BODY = true
46
+ end
47
+
39
48
  end
40
49
 
@@ -7,10 +7,11 @@ module Spreedly
7
7
  include SslRequester
8
8
  include Urls
9
9
 
10
- attr_reader :key, :currency_code
10
+ attr_reader :key, :currency_code, :base_url
11
11
 
12
12
  def initialize(environment_key, access_secret, options={})
13
13
  @key, @access_secret = environment_key, access_secret
14
+ @base_url = options[:base_url] || "https://core.spreedly.com"
14
15
  @currency_code = options[:currency_code] || 'USD'
15
16
  end
16
17
 
@@ -86,6 +87,11 @@ module Spreedly
86
87
  Gateway.new_list_from(xml_doc)
87
88
  end
88
89
 
90
+ def gateway_options
91
+ xml_doc = ssl_options(gateway_options_url)
92
+ GatewayClass.new_list_from(xml_doc)
93
+ end
94
+
89
95
  def add_gateway(gateway_type, credentials = {})
90
96
  body = add_gateway_body(gateway_type, credentials)
91
97
  xml_doc = ssl_post(add_gateway_url, body, headers)
@@ -0,0 +1,36 @@
1
+ module Spreedly
2
+
3
+ class GatewayClass
4
+
5
+ include Fields
6
+ field :gateway_type, :name, :supported_countries, :homepage
7
+ attr_reader :supported_countries, :payment_methods
8
+
9
+ def initialize(xml_doc)
10
+ initialize_fields(xml_doc)
11
+ init_supported_countries(xml_doc)
12
+ init_payment_methods(xml_doc)
13
+ end
14
+
15
+ def self.new_list_from(xml_doc)
16
+ gateways = xml_doc.xpath('.//gateways/gateway')
17
+ gateways.map do |each|
18
+ self.new(each)
19
+ end
20
+ end
21
+
22
+ private
23
+ def init_supported_countries(xml_doc)
24
+ list = xml_doc.at_xpath(".//supported_countries").inner_html.strip
25
+ @supported_countries = list.split(/\s*,\s*/)
26
+ end
27
+
28
+ def init_payment_methods(xml_doc)
29
+ @payment_methods = xml_doc.xpath('.//payment_methods/payment_method').map do |each|
30
+ each.text
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -14,6 +14,10 @@ module Spreedly
14
14
  ssl_request(:put, endpoint, body, headers)
15
15
  end
16
16
 
17
+ def ssl_options(endpoint)
18
+ ssl_request(:options, endpoint, nil, {})
19
+ end
20
+
17
21
  private
18
22
  def ssl_request(method, endpoint, body, headers)
19
23
  raw_response = Timeout::timeout(70) do
@@ -57,6 +61,7 @@ module Spreedly
57
61
 
58
62
  def show_raw_response(raw_response)
59
63
  return unless ENV['SHOW_RAW_RESPONSE'] == 'true'
64
+ puts raw_response.inspect
60
65
  puts "\nraw_response.code: #{raw_response.code}\nraw_response.body:\n#{raw_response.body}"
61
66
  end
62
67
 
data/lib/spreedly/urls.rb CHANGED
@@ -2,10 +2,6 @@ module Spreedly
2
2
 
3
3
  module Urls
4
4
 
5
- def base_url
6
- "https://core.spreedly.com"
7
- end
8
-
9
5
  def find_payment_method_url(token)
10
6
  "#{base_url}/v1/payment_methods/#{token}.xml"
11
7
  end
@@ -67,6 +63,10 @@ module Spreedly
67
63
  "#{base_url}/v1/gateways.xml#{since_param}"
68
64
  end
69
65
 
66
+ def gateway_options_url
67
+ "#{base_url}/v1/gateways.xml"
68
+ end
69
+
70
70
  def add_gateway_url
71
71
  "#{base_url}/v1/gateways.xml"
72
72
  end
@@ -1,3 +1,3 @@
1
1
  module Spreedly
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
data/lib/spreedly.rb CHANGED
@@ -23,6 +23,7 @@ require 'spreedly/transactions/retain_payment_method'
23
23
  require 'spreedly/transactions/redact_payment_method'
24
24
  require 'spreedly/transactions/redact_gateway'
25
25
  require 'spreedly/gateway'
26
+ require 'spreedly/gateway_class'
26
27
  require 'spreedly/error'
27
28
 
28
29
  module Spreedly
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteGatewayOptionsTest < 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_successfully_get_options
10
+ gateway_classes = @environment.gateway_options
11
+ braintree = gateway_classes.select { |each| each.name == "Braintree" }.first
12
+ assert_equal "http://www.braintreepaymentsolutions.com/", braintree.homepage
13
+ assert_equal ["credit_card", "third_party_token"], braintree.payment_methods
14
+ end
15
+
16
+ end
17
+
@@ -15,4 +15,12 @@ class EnvironmentTest < Test::Unit::TestCase
15
15
  assert_equal "EUR", environment.currency_code
16
16
  end
17
17
 
18
+ def test_base_url_default
19
+ assert_equal "https://core.spreedly.com", @environment.base_url
20
+ end
21
+
22
+ def test_base_url_override
23
+ environment = Spreedly::Environment.new("TheKey", "TheAccessSecret", base_url: "http://it.com")
24
+ assert_equal "http://it.com", environment.base_url
25
+ end
18
26
  end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+ require 'unit/response_stubs/gateway_options_stubs'
3
+
4
+ class ListGatewaysTest < Test::Unit::TestCase
5
+
6
+ include GatewayOptionsStubs
7
+
8
+ def setup
9
+ @environment = Spreedly::Environment.new("key", "secret")
10
+ end
11
+
12
+ def test_successful_gateway_options
13
+ @environment.stubs(:raw_ssl_request).returns(successful_gateway_options_response)
14
+ list = @environment.gateway_options
15
+
16
+ assert_kind_of(Array, list)
17
+ assert_equal 2, list.size
18
+
19
+ assert_equal 'PayPal', list.first.name
20
+ assert_equal ["US", "GB", "CA"], list.first.supported_countries
21
+ assert_equal ["credit_card", "paypal"], list.first.payment_methods
22
+ assert_equal "paypal", list.first.gateway_type
23
+ assert_equal "http://paypal.com/", list.first.homepage
24
+ assert_kind_of Spreedly::GatewayClass, list.first
25
+ assert_kind_of Spreedly::GatewayClass, list.last
26
+ end
27
+
28
+ end
@@ -0,0 +1,137 @@
1
+ module GatewayOptionsStubs
2
+
3
+ def successful_gateway_options_response
4
+ StubResponse.succeeded <<-XML
5
+ <gateways>
6
+ <gateway>
7
+ <gateway_type>paypal</gateway_type>
8
+ <name>PayPal</name>
9
+ <auth_modes>
10
+ <auth_mode>
11
+ <auth_mode_type>signature</auth_mode_type>
12
+ <name>Signature</name>
13
+ <credentials>
14
+ <credential>
15
+ <name>login</name>
16
+ <label>Login</label>
17
+ <safe type="boolean">true</safe>
18
+ </credential>
19
+ <credential>
20
+ <name>password</name>
21
+ <label>Password</label>
22
+ <safe type="boolean">false</safe>
23
+ </credential>
24
+ <credential>
25
+ <name>signature</name>
26
+ <label>Signature</label>
27
+ <safe type="boolean">false</safe>
28
+ </credential>
29
+ </credentials>
30
+ </auth_mode>
31
+ <auth_mode>
32
+ <auth_mode_type>certificate</auth_mode_type>
33
+ <name>Certificate</name>
34
+ <credentials>
35
+ <credential>
36
+ <name>login</name>
37
+ <label>Login</label>
38
+ <safe type="boolean">true</safe>
39
+ </credential>
40
+ <credential>
41
+ <name>password</name>
42
+ <label>Password</label>
43
+ <safe type="boolean">false</safe>
44
+ </credential>
45
+ <credential>
46
+ <name>pem</name>
47
+ <label>PEM Certificate</label>
48
+ <safe type="boolean">false</safe>
49
+ <large type="boolean">true</large>
50
+ </credential>
51
+ </credentials>
52
+ </auth_mode>
53
+ <auth_mode>
54
+ <auth_mode_type>delegate</auth_mode_type>
55
+ <name>Delegate</name>
56
+ <credentials>
57
+ <credential>
58
+ <name>email</name>
59
+ <label>PayPal Email</label>
60
+ <safe type="boolean">true</safe>
61
+ </credential>
62
+ </credentials>
63
+ </auth_mode>
64
+ </auth_modes>
65
+ <characteristics>
66
+ <supports_purchase type="boolean">true</supports_purchase>
67
+ <supports_authorize type="boolean">true</supports_authorize>
68
+ <supports_capture type="boolean">true</supports_capture>
69
+ <supports_credit type="boolean">true</supports_credit>
70
+ <supports_void type="boolean">true</supports_void>
71
+ <supports_reference_purchase type="boolean">true</supports_reference_purchase>
72
+ <supports_purchase_via_preauthorization type="boolean">true</supports_purchase_via_preauthorization>
73
+ <supports_offsite_purchase type="boolean">true</supports_offsite_purchase>
74
+ <supports_offsite_authorize type="boolean">true</supports_offsite_authorize>
75
+ <supports_3dsecure_purchase type="boolean">false</supports_3dsecure_purchase>
76
+ <supports_3dsecure_authorize type="boolean">false</supports_3dsecure_authorize>
77
+ <supports_store type="boolean">false</supports_store>
78
+ <supports_remove type="boolean">true</supports_remove>
79
+ </characteristics>
80
+ <payment_methods>
81
+ <payment_method>credit_card</payment_method>
82
+ <payment_method>paypal</payment_method>
83
+ </payment_methods>
84
+ <gateway_specific_fields>
85
+ <gateway_specific_field>recurring</gateway_specific_field>
86
+ </gateway_specific_fields>
87
+ <supported_countries>US, GB, CA</supported_countries>
88
+ <homepage>http://paypal.com/</homepage>
89
+ </gateway>
90
+ <gateway>
91
+ <gateway_type>worldpay</gateway_type>
92
+ <name>WorldPay</name>
93
+ <auth_modes>
94
+ <auth_mode>
95
+ <auth_mode_type>default</auth_mode_type>
96
+ <name>Default</name>
97
+ <credentials>
98
+ <credential>
99
+ <name>login</name>
100
+ <label>Login</label>
101
+ <safe type="boolean">true</safe>
102
+ </credential>
103
+ <credential>
104
+ <name>password</name>
105
+ <label>Password</label>
106
+ <safe type="boolean">false</safe>
107
+ </credential>
108
+ </credentials>
109
+ </auth_mode>
110
+ </auth_modes>
111
+ <characteristics>
112
+ <supports_purchase type="boolean">true</supports_purchase>
113
+ <supports_authorize type="boolean">true</supports_authorize>
114
+ <supports_capture type="boolean">true</supports_capture>
115
+ <supports_credit type="boolean">true</supports_credit>
116
+ <supports_void type="boolean">true</supports_void>
117
+ <supports_reference_purchase type="boolean">true</supports_reference_purchase>
118
+ <supports_purchase_via_preauthorization type="boolean">false</supports_purchase_via_preauthorization>
119
+ <supports_offsite_purchase type="boolean">false</supports_offsite_purchase>
120
+ <supports_offsite_authorize type="boolean">false</supports_offsite_authorize>
121
+ <supports_3dsecure_purchase type="boolean">false</supports_3dsecure_purchase>
122
+ <supports_3dsecure_authorize type="boolean">false</supports_3dsecure_authorize>
123
+ <supports_store type="boolean">false</supports_store>
124
+ <supports_remove type="boolean">false</supports_remove>
125
+ </characteristics>
126
+ <payment_methods>
127
+ <payment_method>credit_card</payment_method>
128
+ </payment_methods>
129
+ <gateway_specific_fields/>
130
+ <supported_countries>HK, US, GB, AU, AD, BE, CH, CY, CZ, DE, DK, ES, FI, FR, GI, GR, HU, IE, IL, IT, LI, LU, MC, MT, NL, NO, NZ, PL, PT, SE, SG, SI, SM, TR, UM, VA</supported_countries>
131
+ <homepage>http://worldpay.com</homepage>
132
+ </gateway>
133
+ </gateways>
134
+ XML
135
+ end
136
+
137
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: spreedly
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.1
5
+ version: 2.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Spreedly
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-23 00:00:00.000000000 Z
12
+ date: 2013-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -129,6 +129,7 @@ files:
129
129
  - lib/spreedly/environment.rb
130
130
  - lib/spreedly/error.rb
131
131
  - lib/spreedly/gateway.rb
132
+ - lib/spreedly/gateway_class.rb
132
133
  - lib/spreedly/model.rb
133
134
  - lib/spreedly/payment_methods/bank_account.rb
134
135
  - lib/spreedly/payment_methods/credit_card.rb
@@ -164,6 +165,7 @@ files:
164
165
  - test/remote/remote_find_gateway_test.rb
165
166
  - test/remote/remote_find_payment_method_test.rb
166
167
  - test/remote/remote_find_transaction_test.rb
168
+ - test/remote/remote_gateway_options_test.rb
167
169
  - test/remote/remote_list_gateways_test.rb
168
170
  - test/remote/remote_list_payment_methods_test.rb
169
171
  - test/remote/remote_list_transactions_test.rb
@@ -184,6 +186,7 @@ files:
184
186
  - test/unit/find_gateway_test.rb
185
187
  - test/unit/find_payment_method_test.rb
186
188
  - test/unit/find_transaction_test.rb
189
+ - test/unit/gateway_options_test.rb
187
190
  - test/unit/list_gateways_test.rb
188
191
  - test/unit/list_payment_methods_test.rb
189
192
  - test/unit/list_transactions_test.rb
@@ -198,6 +201,7 @@ files:
198
201
  - test/unit/response_stubs/find_gateway_stubs.rb
199
202
  - test/unit/response_stubs/find_payment_method_stubs.rb
200
203
  - test/unit/response_stubs/find_transaction_stubs.rb
204
+ - test/unit/response_stubs/gateway_options_stubs.rb
201
205
  - test/unit/response_stubs/list_gateways_stubs.rb
202
206
  - test/unit/response_stubs/list_payment_methods_stubs.rb
203
207
  - test/unit/response_stubs/list_transactions_stubs.rb
@@ -225,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
229
  - !ruby/object:Gem::Version
226
230
  segments:
227
231
  - 0
228
- hash: 2278846472039598155
232
+ hash: -3250380428935698253
229
233
  version: '0'
230
234
  none: false
231
235
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -234,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
238
  - !ruby/object:Gem::Version
235
239
  segments:
236
240
  - 0
237
- hash: 2278846472039598155
241
+ hash: -3250380428935698253
238
242
  version: '0'
239
243
  none: false
240
244
  requirements: []
@@ -257,6 +261,7 @@ test_files:
257
261
  - test/remote/remote_find_gateway_test.rb
258
262
  - test/remote/remote_find_payment_method_test.rb
259
263
  - test/remote/remote_find_transaction_test.rb
264
+ - test/remote/remote_gateway_options_test.rb
260
265
  - test/remote/remote_list_gateways_test.rb
261
266
  - test/remote/remote_list_payment_methods_test.rb
262
267
  - test/remote/remote_list_transactions_test.rb
@@ -277,6 +282,7 @@ test_files:
277
282
  - test/unit/find_gateway_test.rb
278
283
  - test/unit/find_payment_method_test.rb
279
284
  - test/unit/find_transaction_test.rb
285
+ - test/unit/gateway_options_test.rb
280
286
  - test/unit/list_gateways_test.rb
281
287
  - test/unit/list_payment_methods_test.rb
282
288
  - test/unit/list_transactions_test.rb
@@ -291,6 +297,7 @@ test_files:
291
297
  - test/unit/response_stubs/find_gateway_stubs.rb
292
298
  - test/unit/response_stubs/find_payment_method_stubs.rb
293
299
  - test/unit/response_stubs/find_transaction_stubs.rb
300
+ - test/unit/response_stubs/gateway_options_stubs.rb
294
301
  - test/unit/response_stubs/list_gateways_stubs.rb
295
302
  - test/unit/response_stubs/list_payment_methods_stubs.rb
296
303
  - test/unit/response_stubs/list_transactions_stubs.rb