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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d3536add302f60e0f9c0a6d3e03f31ca6b1ba72
4
- data.tar.gz: 05b193ba95d04a5b4fe40c3dbf8e87dc5ee0f3c8
3
+ metadata.gz: a37f361841f4061cc7399fe9bd2ef837b78130fd
4
+ data.tar.gz: 056a38b2f942463ba7f370ff77348520660346e1
5
5
  SHA512:
6
- metadata.gz: 389d569b613f65d763383b1fedba752adcca0b47024e4a2887ac323315e1e93e49fa28cbc7003bb0652a40852089c092feb65bb45c9593aea027d1036396d6e1
7
- data.tar.gz: bb4f1a6b376557a35f67b5c249e7934dbdd839fe3a028d5341b69234629ce4fb5c18fab95335d61853a378a7959b7cf1279d8dc2a515b041d1e20a303205f92a
6
+ metadata.gz: 68d2591350a32dc483495c667710caf9af2c5c39863991935e51c45db417bcc34ae10d82116a2afa4c3649a97b8b9aecfc1da2c60a5600be748f87a9b7d89e39
7
+ data.tar.gz: 3a5d21b3104d2cdd510f8cbea4bae54acba20004cf1bd1420681b447cf2979d2425cbed727c37aef2ea78a705205f0d899b233d8208df9590a802daa0743b6a6
data/HISTORY.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## Next Version
4
+
5
+
6
+ ## 2.0.13
7
+ * Check attributes for non-nil before sending [markabe]
8
+ * Add supports_verify option to Gateway [duff]
9
+ * Add support for verify_on_gateway API call [duff]
10
+ * Add support for RecacheSensitiveData transaction [duff]
11
+ * Remove cacert.pem and rely on system certs [duff]
12
+ * Adds add_receiver method to environment [Thomas Hoen]
13
+ * Adds deliver_receiver functionality [Thomas Hoen]
14
+ * Add support for first_six_digits [duff]
15
+ * Add support for supports_general_credit characteristic [markabe]
16
+
17
+ ## 2.0.12
18
+ * Add support for new credit card field: eligible_for_card_updater [markabe]
19
+
20
+ ## 2.0.11
21
+ * Add support for ThirdPartyTokens [duff]
22
+
23
+ ## 2.0.10
24
+ * Add support for gateway_transaction_id [hoenth]
25
+
26
+ ## 2.0.9
27
+ * Improve support for base_url around ssl [duff]
28
+
29
+ ## 2.0.8
30
+ * Add support for gateway regions [duff]
31
+
3
32
  ## 2.0.7
4
33
  * Add support for company_name to gateway options [duff]
5
34
  * Implemented gateway characteristics [ilyutov]
data/README.md CHANGED
@@ -52,7 +52,7 @@ gateway.token # => "DnbEJaaY2egcVkCvg3s8qT38xgt"
52
52
 
53
53
  #### Add a payment method
54
54
  Need a payment method token to try things out? With Spreedly it's pretty straightforward to use a
55
- [transparent redirect](https://core.spreedly.com/manual/quickstart#submit-payment-form) to give you a
55
+ [transparent redirect](https://docs.spreedly.com/guides/adding-payment-methods/web-form/) to give you a
56
56
  payment method token. A payment form in your application could look something like this:
57
57
 
58
58
  ``` html
@@ -84,7 +84,7 @@ Once Spreedly has recorded the information, it will redirect the browser to the
84
84
 
85
85
  http://yourdomain.com/transparent_redirect_done?token=OEj2G2QJZM4C10AfTLYTrsKIsZH
86
86
 
87
- Once you have the payment method token (OEj2G2QJZM4C10AfTLYTrsKIsZH in this case), you can remember it and use it whenever you'd like. These [test cards](https://core.spreedly.com/manual/test-data) will help.
87
+ Once you have the payment method token (OEj2G2QJZM4C10AfTLYTrsKIsZH in this case), you can remember it and use it whenever you'd like. These [test cards](https://docs.spreedly.com/reference/test-data/) will help.
88
88
 
89
89
  #### Retrieve a payment method
90
90
  Let's say you'd like some additional information about the payment method. You can find a payment method like so:
@@ -119,6 +119,13 @@ You can also specify an optional amount to capture.
119
119
  capture_transaction = env.capture_transaction(auth_transaction.token, amount: 100)
120
120
  ```
121
121
 
122
+ #### Verify
123
+
124
+ Verify a card is legitimate so you can charge it at a later date.
125
+
126
+ ``` ruby
127
+ env.verify_on_gateway(gateway_token, payment_method_token, retain_on_success: true)
128
+ ```
122
129
 
123
130
  #### Void and refund
124
131
 
@@ -162,7 +169,7 @@ env.purchase_on_gateway(gateway_token, payment_method_token, amount, currency_co
162
169
 
163
170
 
164
171
  #### Extra options for the basic operations
165
- For Purchase, Authorize, Capture, Refund, and Void calls, you can specify additional options:
172
+ For Purchase, Authorize, Capture, Refund, Verify, and Void calls, you can specify additional options:
166
173
 
167
174
  ``` ruby
168
175
  env.purchase_on_gateway(gateway_token, payment_method_token, amount,
@@ -175,12 +182,16 @@ env.purchase_on_gateway(gateway_token, payment_method_token, amount,
175
182
  ```
176
183
 
177
184
  #### Retain on success
178
- Retain a payment method automatically if the purchase or authorize transaction succeeded. Saves you a separate call to retain:
185
+ Retain a payment method automatically if the purchase, verify, or authorize transaction succeeded. Saves you a separate call to retain:
179
186
 
180
187
  ``` ruby
181
188
  env.purchase_on_gateway(gateway_token, payment_method_token, amount, retain_on_success: true)
182
189
  ```
183
190
 
191
+ ``` ruby
192
+ env.verify_on_gateway(gateway_token, payment_method_token, retain_on_success: true)
193
+ ```
194
+
184
195
  #### Retrieving gateways
185
196
 
186
197
  ``` ruby
@@ -358,7 +369,7 @@ env.purchase_on_gateway(gateway_token, "Some Unknown Token", 4432) # Raises Spre
358
369
 
359
370
  #### Trying to use a non-test gateway or a non-test payment method with an inactive account
360
371
 
361
- You're free to use [test card data](https://core.spreedly.com/manual/test-data) and a [Test gateway](https://core.spreedly.com/manual/payment-gateways/test) to integrate Spreedly without having a
372
+ You're free to use [test card data](https://docs.spreedly.com/reference/test-data/) and a [Test gateway](https://docs.spreedly.com/payment-gateways/test/) to integrate Spreedly without having a
362
373
  paid Spreedly account. If you try to use a real card or a real gateway when your account isn't yet paid for, we'll raise an exception:
363
374
 
364
375
  ``` ruby
@@ -378,7 +389,7 @@ For api calls that actually talk to a payment gateway, the timout is longer sinc
378
389
 
379
390
  ## Sample applications using the gem
380
391
 
381
- There are some sample applications with source code using this gem. You can [find them here](https://core.spreedly.com/manual/sample_applications).
392
+ There are some sample applications with source code using this gem. You can [find them here](https://docs.spreedly.com/resources/apps-libs/).
382
393
 
383
394
  ## Contributing
384
395
 
@@ -19,13 +19,17 @@ require 'spreedly/transactions/add_payment_method'
19
19
  require 'spreedly/transactions/auth_purchase'
20
20
  require 'spreedly/transactions/purchase'
21
21
  require 'spreedly/transactions/void'
22
+ require 'spreedly/transactions/verification'
22
23
  require 'spreedly/transactions/authorization'
23
24
  require 'spreedly/transactions/capture'
24
25
  require 'spreedly/transactions/refund'
25
26
  require 'spreedly/transactions/retain_payment_method'
26
27
  require 'spreedly/transactions/redact_payment_method'
27
28
  require 'spreedly/transactions/redact_gateway'
29
+ require 'spreedly/transactions/recache_sensitive_data'
30
+ require 'spreedly/transactions/deliver_payment_method'
28
31
  require 'spreedly/gateway'
32
+ require 'spreedly/receiver'
29
33
  require 'spreedly/gateway_class'
30
34
  require 'spreedly/error'
31
35
 
@@ -41,7 +41,6 @@ module Spreedly
41
41
 
42
42
  http.use_ssl = true
43
43
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
44
- http.ca_file = File.dirname(__FILE__) + '/../certs/cacert.pem'
45
44
  end
46
45
 
47
46
  end
@@ -48,6 +48,11 @@ module Spreedly
48
48
  api_post(authorize_url(gateway_token), body)
49
49
  end
50
50
 
51
+ def verify_on_gateway(gateway_token, payment_method_token, options = {})
52
+ body = verify_body(payment_method_token, options)
53
+ api_post(verify_url(gateway_token), body)
54
+ end
55
+
51
56
  def capture_transaction(authorization_token, options = {})
52
57
  api_post(capture_url(authorization_token), capture_body(options))
53
58
  end
@@ -106,6 +111,12 @@ module Spreedly
106
111
  Gateway.new(xml_doc)
107
112
  end
108
113
 
114
+ def add_receiver(receiver_type, host_names = nil, credentials = [])
115
+ body = add_receiver_body(receiver_type, host_names, credentials)
116
+ xml_doc = ssl_post(add_receiver_url, body, headers)
117
+ Receiver.new(xml_doc)
118
+ end
119
+
109
120
  def add_credit_card(options)
110
121
  api_post(add_payment_method_url, add_credit_card_body(options), false)
111
122
  end
@@ -116,6 +127,12 @@ module Spreedly
116
127
  PaymentMethod.new_from(xml_doc)
117
128
  end
118
129
 
130
+ def deliver_to_receiver(receiver_token, payment_method_token, receiver_options)
131
+ body = deliver_to_receiver_body(payment_method_token, receiver_options)
132
+ xml_doc = ssl_post(deliver_to_receiver_url(receiver_token), body, headers)
133
+ DeliverPaymentMethod.new_from(xml_doc)
134
+ end
135
+
119
136
  private
120
137
  def headers
121
138
  {
@@ -134,6 +151,14 @@ module Spreedly
134
151
  end
135
152
  end
136
153
 
154
+ def verify_body(payment_method_token, options)
155
+ build_xml_request('transaction') do |doc|
156
+ doc.payment_method_token(payment_method_token)
157
+ add_to_doc(doc, options, :retain_on_success)
158
+ add_extra_options_for_basic_ops(doc, options)
159
+ end
160
+ end
161
+
137
162
  def capture_body(options)
138
163
  return '' if options.empty?
139
164
 
@@ -174,12 +199,31 @@ module Spreedly
174
199
  end
175
200
  end
176
201
 
202
+ def add_receiver_body(receiver_type, host_names, credentials)
203
+ build_xml_request('receiver') do |doc|
204
+ doc.receiver_type receiver_type
205
+ doc.hostnames host_names
206
+ add_credentials_to_doc(doc, credentials) if credentials && !credentials.empty?
207
+ end
208
+ end
209
+
210
+ def add_credentials_to_doc(doc, credentials)
211
+ doc.credentials do
212
+ credentials.each do |credential|
213
+ doc.credential do
214
+ add_to_doc(doc, credential, :name, :value, :safe)
215
+ end
216
+ end
217
+ end
218
+ end
219
+
177
220
  def add_credit_card_body(options)
178
221
  build_xml_request('payment_method') do |doc|
179
222
  add_to_doc(doc, options, :data, :retained, :email)
180
223
  doc.credit_card do
181
224
  add_to_doc(doc, options, :number, :verification_value, :month, :first_name, :last_name,
182
- :year, :address1, :address2, :city, :state, :zip, :country, :phone_number)
225
+ :year, :address1, :address2, :city, :state, :zip, :country, :phone_number,
226
+ :eligible_for_card_updater)
183
227
  end
184
228
  end
185
229
  end
@@ -187,13 +231,27 @@ module Spreedly
187
231
  def update_credit_card_body(options)
188
232
  build_xml_request('payment_method') do |doc|
189
233
  add_to_doc(doc, options, :email, :month, :first_name, :last_name, :year,
190
- :address1, :address2, :city, :state, :zip, :country, :phone_number)
234
+ :address1, :address2, :city, :state, :zip, :country, :phone_number,
235
+ :eligible_for_card_updater)
236
+ end
237
+ end
238
+
239
+ def deliver_to_receiver_body(payment_method_token, receiver_options)
240
+ build_xml_request('delivery') do |doc|
241
+ doc.payment_method_token payment_method_token
242
+ doc.url receiver_options[:url]
243
+ doc.headers do
244
+ doc.cdata receiver_options[:headers].map { |k, v| "#{k}: #{v}" }.join("\r\n")
245
+ end
246
+ doc.body do
247
+ doc.cdata receiver_options[:body]
248
+ end
191
249
  end
192
250
  end
193
251
 
194
252
  def add_to_doc(doc, options, *attributes)
195
253
  attributes.each do |attr|
196
- doc.send(attr, options[attr.to_sym]) if options[attr.to_sym]
254
+ doc.send(attr, options[attr.to_sym]) if options[attr.to_sym] != nil
197
255
  end
198
256
  end
199
257
 
@@ -5,9 +5,10 @@ module Spreedly
5
5
 
6
6
  field :gateway_type, :name, :homepage, :company_name
7
7
  field :supports_purchase, :supports_authorize, :supports_capture, :supports_credit,
8
- :supports_void, :supports_reference_purchase, :supports_purchase_via_preauthorization,
9
- :supports_offsite_purchase, :supports_offsite_authorize, :supports_3dsecure_purchase,
10
- :supports_3dsecure_authorize, :supports_store, :supports_remove, type: :boolean
8
+ :supports_void, :supports_verify, :supports_reference_purchase,
9
+ :supports_purchase_via_preauthorization, :supports_offsite_purchase,
10
+ :supports_offsite_authorize, :supports_3dsecure_purchase, :supports_3dsecure_authorize,
11
+ :supports_store, :supports_remove, :supports_general_credit, type: :boolean
11
12
 
12
13
  attr_reader :supported_countries, :payment_methods, :auth_modes, :regions
13
14
 
@@ -2,8 +2,9 @@ module Spreedly
2
2
 
3
3
  class CreditCard < PaymentMethod
4
4
  field :first_name, :last_name, :full_name, :month, :year
5
- field :number, :last_four_digits, :card_type, :verification_value
5
+ field :number, :last_four_digits, :first_six_digits, :card_type, :verification_value
6
6
  field :address1, :address2, :city, :state, :zip, :country, :phone_number
7
+ field :eligible_for_card_updater, type: :boolean
7
8
  end
8
9
 
9
10
  end
@@ -0,0 +1,30 @@
1
+
2
+ module Spreedly
3
+
4
+ class Receiver < Model
5
+
6
+ field :receiver_type, :hostnames
7
+ attr_reader :credentials
8
+
9
+ def initialize(xml_doc)
10
+ super
11
+ init_credentials(xml_doc)
12
+ end
13
+
14
+ private
15
+ def init_credentials(xml_doc)
16
+ @credentials = {}
17
+
18
+ xml_doc.xpath('.//credentials/credential').each do |each|
19
+ @credentials[each.at_xpath('.//name').text] = cred_value(each)
20
+ end
21
+ end
22
+
23
+ def cred_value(cred)
24
+ value = cred.at_xpath('.//value')
25
+ value ? value.text : nil
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,31 @@
1
+ module Spreedly
2
+
3
+ class DeliverPaymentMethod < Transaction
4
+
5
+ attr_reader :response
6
+ attr_reader :payment_method, :receiver
7
+ field :succeeded, type: :boolean
8
+
9
+ def initialize(xml_doc)
10
+ super
11
+ @payment_method = PaymentMethod.new_from(xml_doc.at_xpath('.//payment_method'))
12
+ @receiver = Receiver.new(xml_doc.at_xpath('.//receiver'))
13
+
14
+ response_xml_doc = xml_doc.at_xpath('.//response')
15
+ @response = response_xml_doc ? DeliverPaymentResponse.new(response_xml_doc) : nil
16
+ end
17
+
18
+ end
19
+
20
+ class DeliverPaymentResponse
21
+ include Fields
22
+
23
+ field :status, :headers, :body
24
+
25
+ def initialize(xml_doc)
26
+ initialize_fields(xml_doc)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,17 @@
1
+ module Spreedly
2
+
3
+ class RecacheSensitiveData < Transaction
4
+
5
+ field :data
6
+ attr_reader :payment_method
7
+
8
+ def initialize(xml_doc)
9
+ super
10
+ @payment_method = PaymentMethod.new_from(xml_doc.at_xpath('.//payment_method'))
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+
@@ -20,12 +20,18 @@ module Spreedly
20
20
  return Refund.new(xml_doc)
21
21
  when 'Void'
22
22
  return Void.new(xml_doc)
23
+ when 'Verification'
24
+ return Verification.new(xml_doc)
23
25
  when 'RetainPaymentMethod'
24
26
  return RetainPaymentMethod.new(xml_doc)
25
27
  when 'RedactPaymentMethod'
26
28
  return RedactPaymentMethod.new(xml_doc)
27
29
  when 'RedactGateway'
28
30
  return RedactGateway.new(xml_doc)
31
+ when 'RecacheSensitiveData'
32
+ return RecacheSensitiveData.new(xml_doc)
33
+ when 'DeliverPaymentMethod'
34
+ return DeliverPaymentMethod.new(xml_doc)
29
35
  else
30
36
  Transaction.new(xml_doc)
31
37
  end
@@ -0,0 +1,12 @@
1
+ module Spreedly
2
+
3
+ class Verification < GatewayTransaction
4
+ attr_reader :payment_method
5
+
6
+ def initialize(xml_doc)
7
+ super
8
+ @payment_method = PaymentMethod.new_from(xml_doc.at_xpath('.//payment_method'))
9
+ end
10
+ end
11
+
12
+ end
@@ -26,6 +26,10 @@ module Spreedly
26
26
  "#{base_url}/v1/gateways/#{gateway_token}/authorize.xml"
27
27
  end
28
28
 
29
+ def verify_url(gateway_token)
30
+ "#{base_url}/v1/gateways/#{gateway_token}/verify.xml"
31
+ end
32
+
29
33
  def capture_url(authorization_token)
30
34
  "#{base_url}/v1/transactions/#{authorization_token}/capture.xml"
31
35
  end
@@ -75,6 +79,10 @@ module Spreedly
75
79
  "#{base_url}/v1/gateways.xml"
76
80
  end
77
81
 
82
+ def add_receiver_url
83
+ "#{base_url}/v1/receivers.xml"
84
+ end
85
+
78
86
  def add_payment_method_url
79
87
  "#{base_url}/v1/payment_methods.xml"
80
88
  end
@@ -83,6 +91,10 @@ module Spreedly
83
91
  "#{base_url}/v1/payment_methods/#{token}.xml"
84
92
  end
85
93
 
94
+ def deliver_to_receiver_url(receiver_token)
95
+ "#{base_url}/v1/receivers/#{receiver_token}/deliver.xml"
96
+ end
97
+
86
98
  end
87
99
 
88
100
  end
@@ -1,3 +1,3 @@
1
1
  module Spreedly
2
- VERSION = "2.0.11"
2
+ VERSION = "2.0.13"
3
3
  end
@@ -2,8 +2,6 @@ require 'test_helper'
2
2
 
3
3
  class RemoteAddGatewayTest < Test::Unit::TestCase
4
4
 
5
- # TODO We'll add more to this soon.
6
-
7
5
  def setup
8
6
  @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
9
7
  end
@@ -29,7 +27,7 @@ class RemoteAddGatewayTest < Test::Unit::TestCase
29
27
 
30
28
  def test_need_active_account
31
29
  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)
30
+ @environment.add_gateway(:wirecard)
33
31
  end
34
32
  end
35
33