arrow_payments 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  rvm:
2
2
  - 1.9.2
3
- - 1.9.3
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013 Dan Sosedoff.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,15 +1,19 @@
1
1
  # ArrowPayments
2
2
 
3
- Ruby wrapper for Arrow Payments gateway
4
-
5
- **Under Development**
3
+ Ruby wrapper for [Arrow Payments](http://www.arrowpayments.com/) gateway
6
4
 
7
5
  ## Installation
8
6
 
9
- In your Gemfile add a line:
7
+ Add dependency to your Gemfile:
8
+
9
+ ```
10
+ gem 'arrow_payments'
11
+ ```
12
+
13
+ Or install manually:
10
14
 
11
15
  ```
12
- gem 'arrow_payments', :github => 'sosedoff/arrow_payments'
16
+ gem install arrow_payments
13
17
  ```
14
18
 
15
19
  ## Configuration
@@ -184,78 +188,7 @@ List of all gateway objects:
184
188
  - `Address` - User for shipping and billing addresses
185
189
  - `LineItem` - Contains information about transaction item
186
190
 
187
- ### Address
188
-
189
- - `address`
190
- - `address2`
191
- - `city`
192
- - `state`
193
- - `zip`
194
- - `phone`
195
- - `tag`
196
-
197
- ### Customer
198
-
199
- - `id`
200
- - `name`
201
- - `code`
202
- - `contact`
203
- - `phone`
204
- - `email`
205
- - `recurring_billings` - Array of `RecurringBilling` instances if any
206
- - `payment_methods` - Array of PaymentMethod instances if any
207
-
208
- ### PaymentMethod
209
-
210
- - `id`
211
- - `card_type`
212
- - `last_digits`
213
- - `first_name`
214
- - `last_name`
215
- - `expiration_month`
216
- - `expiration_year`
217
- - `address`
218
- - `address2`
219
- - `city`
220
- - `state`
221
- - `zip`
222
-
223
- ### LineItem
224
-
225
- - `id`
226
- - `commodity_code`
227
- - `description`
228
- - `price`
229
- - `product_code`
230
- - `unit_of_measure`
231
-
232
- ### Transaction
233
-
234
- - `id`
235
- - `account`
236
- - `transaction_type`
237
- - `created_at` - A `DateTime` object of creation
238
- - `level`
239
- - `total_amount`
240
- - `description`
241
- - `transaction_source`
242
- - `status` - One of `NotSettled`, `Settled`, `Voided`, `Failed`
243
- - `capture_amount`
244
- - `authorization_code`
245
- - `payment_method_id`
246
- - `cardholder_first_name`
247
- - `cardholder_last_name`
248
- - `card_type`
249
- - `card_last_digits`
250
- - `customer_po_number`
251
- - `tax_amount`
252
- - `shipping_amount`
253
- - `shipping_address_id`
254
- - `shipping_address`
255
- - `customer_id`
256
- - `customer_name`
257
- - `line_items`
258
- - `billing_address`
191
+ Check `REFERENCE.md` file for details
259
192
 
260
193
  ## Testing
261
194
 
@@ -265,8 +198,6 @@ To run a test suite:
265
198
  rake test
266
199
  ```
267
200
 
268
- ## TODO
269
-
270
- There are multiple features that are pending implementation:
201
+ ## License
271
202
 
272
- - Filter transactions by status
203
+ See `LICENSE` file for details
data/REFERENCE.md ADDED
@@ -0,0 +1,72 @@
1
+ ### Address
2
+
3
+ - `address`
4
+ - `address2`
5
+ - `city`
6
+ - `state`
7
+ - `zip`
8
+ - `phone`
9
+ - `tag`
10
+
11
+ ### Customer
12
+
13
+ - `id`
14
+ - `name`
15
+ - `code`
16
+ - `contact`
17
+ - `phone`
18
+ - `email`
19
+ - `recurring_billings` - Array of `RecurringBilling` instances if any
20
+ - `payment_methods` - Array of PaymentMethod instances if any
21
+
22
+ ### PaymentMethod
23
+
24
+ - `id`
25
+ - `card_type`
26
+ - `last_digits`
27
+ - `first_name`
28
+ - `last_name`
29
+ - `expiration_month`
30
+ - `expiration_year`
31
+ - `address`
32
+ - `address2`
33
+ - `city`
34
+ - `state`
35
+ - `zip`
36
+
37
+ ### LineItem
38
+
39
+ - `id`
40
+ - `commodity_code`
41
+ - `description`
42
+ - `price`
43
+ - `product_code`
44
+ - `unit_of_measure`
45
+
46
+ ### Transaction
47
+
48
+ - `id`
49
+ - `account`
50
+ - `transaction_type`
51
+ - `created_at` - A `DateTime` object of creation
52
+ - `level`
53
+ - `total_amount`
54
+ - `description`
55
+ - `transaction_source`
56
+ - `status` - One of `NotSettled`, `Settled`, `Voided`, `Failed`
57
+ - `capture_amount`
58
+ - `authorization_code`
59
+ - `payment_method_id`
60
+ - `cardholder_first_name`
61
+ - `cardholder_last_name`
62
+ - `card_type`
63
+ - `card_last_digits`
64
+ - `customer_po_number`
65
+ - `tax_amount`
66
+ - `shipping_amount`
67
+ - `shipping_address_id`
68
+ - `shipping_address`
69
+ - `customer_id`
70
+ - `customer_name`
71
+ - `line_items`
72
+ - `billing_address`
@@ -10,8 +10,9 @@ Gem::Specification.new do |s|
10
10
  s.email = ["dan.sosedoff@gmail.com"]
11
11
 
12
12
  s.add_development_dependency 'webmock', '~> 1.6'
13
- s.add_development_dependency 'rake', '~> 0.9'
13
+ s.add_development_dependency 'rake', '~> 10.0'
14
14
  s.add_development_dependency 'rspec', '~> 2.12'
15
+ s.add_development_dependency 'simplecov', '~> 0.7'
15
16
 
16
17
  s.add_runtime_dependency 'faraday', '~> 0.8'
17
18
  s.add_runtime_dependency 'faraday_middleware', '~> 0.8'
@@ -22,4 +23,4 @@ Gem::Specification.new do |s|
22
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
24
25
  s.require_paths = ["lib"]
25
- end
26
+ end
@@ -22,4 +22,4 @@ module ArrowPayments
22
22
  ArrowPayments::Client.new(options)
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -21,7 +21,7 @@ module ArrowPayments
21
21
  @api_key = options[:api_key] || ArrowPayments::Configuration.api_key
22
22
  @mode = (options[:mode] || ArrowPayments::Configuration.mode || 'production').to_s
23
23
  @merchant_id = options[:merchant_id] || ArrowPayments::Configuration.merchant_id
24
- @debug = options[:debug] == true
24
+ @debug = (options[:debug] || ArrowPayments::Configuration.debug) === true
25
25
 
26
26
  if api_key.to_s.empty?
27
27
  raise ArgumentError, "API key required"
@@ -6,6 +6,8 @@ module ArrowPayments
6
6
  get('/customers').map { |c| Customer.new(c) }
7
7
  end
8
8
 
9
+ alias :get_customer :customers
10
+
9
11
  # Get an existing customer
10
12
  # @param [Integer] customer ID
11
13
  # @return [Customer]
@@ -15,6 +17,8 @@ module ArrowPayments
15
17
  nil
16
18
  end
17
19
 
20
+ alias :get_customer :customer
21
+
18
22
  # Create a new customer
19
23
  # @param [Hash] customer attributes
20
24
  # @return [Customer]
@@ -8,6 +8,8 @@ module ArrowPayments
8
8
  customer(customer_id).payment_methods.select { |cc| cc.id == id }.first
9
9
  end
10
10
 
11
+ alias :get_payment_method :payment_method
12
+
11
13
  # Start a new payment method
12
14
  # @param [Integer] customer ID
13
15
  # @param [Address] billing address instance
@@ -9,6 +9,8 @@ module ArrowPayments
9
9
  nil
10
10
  end
11
11
 
12
+ alias :get_transaction :transaction
13
+
12
14
  # Get customer transactions by status
13
15
  # @param [String] customer ID
14
16
  # @param [String] transaction status
@@ -22,6 +24,8 @@ module ArrowPayments
22
24
  resp['Transactions'].map { |t| Transaction.new(t) }
23
25
  end
24
26
 
27
+ alias :get_transactions :transactions
28
+
25
29
  # Create a new transaction
26
30
  # @return [Transaction]
27
31
  def create_transaction(transaction)
@@ -61,4 +65,4 @@ module ArrowPayments
61
65
  resp['Success'] == true
62
66
  end
63
67
  end
64
- end
68
+ end
@@ -1,7 +1,7 @@
1
1
  module ArrowPayments
2
2
  class Configuration
3
3
  class << self
4
- attr_accessor :api_key, :mode, :merchant_id
4
+ attr_accessor :api_key, :mode, :merchant_id, :debug
5
5
  end
6
6
  end
7
7
  end
@@ -6,6 +6,11 @@ module ArrowPayments
6
6
  API_PRODUCTION = 'https://gateway.arrowpayments.com'
7
7
  API_SANDBOX = 'http://demo.arrowpayments.com'
8
8
 
9
+ CONNECTION_OPTIONS = {
10
+ :timeout => 10,
11
+ :open_timeout => 10
12
+ }
13
+
9
14
  def get(path, params={}, raw=false)
10
15
  request(:get, path, params, raw)
11
16
  end
@@ -57,7 +62,7 @@ module ArrowPayments
57
62
  end
58
63
 
59
64
  def connection(url)
60
- connection = Faraday.new(url) do |c|
65
+ connection = Faraday.new(url, CONNECTION_OPTIONS) do |c|
61
66
  c.use(Faraday::Request::UrlEncoded)
62
67
  c.use(Faraday::Response::Logger) if debug?
63
68
  c.adapter(Faraday.default_adapter)
@@ -71,4 +71,4 @@ module ArrowPayments
71
71
  end
72
72
  end
73
73
  end
74
- end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module ArrowPayments
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -37,4 +37,4 @@ describe ArrowPayments do
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
data/spec/client_spec.rb CHANGED
@@ -39,4 +39,4 @@ describe ArrowPayments::Client do
39
39
  client.production?.should be_true
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -21,4 +21,11 @@ describe ArrowPayments::Configuration do
21
21
  ArrowPayments::Configuration.merchant_id.should eq(12345)
22
22
  end
23
23
  end
24
+
25
+ describe '#debug=' do
26
+ it 'sets debug mode' do
27
+ ArrowPayments::Configuration.debug = true
28
+ ArrowPayments::Configuration.debug.should be_true
29
+ end
30
+ end
24
31
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArrowPayments::Connection do
4
+ let(:subject) { ArrowPayments::Client.new(:api_key => 'foo', :merchant_id => 'bar') }
5
+
6
+ it 'should timeout after 10 seconds' do
7
+ stub_request(:get, "https://gateway.arrowpayments.com/api/foo/hello").
8
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
9
+ to_timeout
10
+
11
+ expect { subject.get('/hello') }.to raise_error Faraday::Error::TimeoutError
12
+ end
13
+ end
@@ -7,11 +7,12 @@ describe ArrowPayments::Customers do
7
7
  ArrowPayments::Configuration.api_key = 'foobar'
8
8
  ArrowPayments::Configuration.merchant_id = 'foo'
9
9
  ArrowPayments::Configuration.mode = 'sandbox'
10
+ ArrowPayments::Configuration.debug = false
10
11
  end
11
12
 
12
13
  describe '#customers' do
13
14
  before do
14
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customers").
15
+ stub_request(:get, "#{api_url}/foobar/customers").
15
16
  to_return(:status => 200, :body => fixture('customers.json'))
16
17
  end
17
18
 
@@ -24,8 +25,9 @@ describe ArrowPayments::Customers do
24
25
 
25
26
  describe '#customer' do
26
27
  it 'returns an existing customer by ID' do
27
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/10162").
28
- to_return(:status => 200, :body => fixture('customer.json'))
28
+ stub_request(:get, "#{api_url}/foobar/customer/10162").
29
+ to_return(:status => 200,
30
+ :body => fixture('customer.json'))
29
31
 
30
32
  customer = client.customer(10162)
31
33
  customer.should_not be_nil
@@ -34,8 +36,10 @@ describe ArrowPayments::Customers do
34
36
  end
35
37
 
36
38
  it 'returns nil if customer does not exist' do
37
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/12345").
38
- to_return(:status => 404, :body => "", :headers => {:error => "Customer Not Found"})
39
+ stub_request(:get, "#{api_url}/foobar/customer/12345").
40
+ to_return(:status => 404,
41
+ :body => "",
42
+ :headers => {:error => "Customer Not Found"})
39
43
 
40
44
  customer = client.customer(12345)
41
45
  customer.should be_nil
@@ -53,44 +57,51 @@ describe ArrowPayments::Customers do
53
57
  )
54
58
  end
55
59
 
60
+ let(:request) do
61
+ {
62
+ :body => "{\"Name\":\"First Supplies\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"PaymentMethods\":[],\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
63
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
64
+ }
65
+ end
66
+
56
67
  it 'creates and returns a new customer' do
57
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/add").
58
- with(
59
- :body => "{\"Name\":\"First Supplies\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"PaymentMethods\":[],\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
60
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
61
- ).
62
- to_return(:status => 200, :body => fixture('customer.json'), :headers => {})
68
+ stub_request(:post, "#{api_url}/customer/add").
69
+ with(request).
70
+ to_return(:status => 200,
71
+ :body => fixture('customer.json'),
72
+ :headers => {})
63
73
 
64
74
  new_customer = client.create_customer(customer)
65
75
  new_customer.id.should eq(10162)
66
76
  end
67
77
 
68
78
  it 'raises error when unable to create' do
69
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/add").
70
- with(
71
- :body => "{\"Name\":\"First Supplies\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"PaymentMethods\":[],\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
72
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
73
- ).
74
- to_return(:status => 500, :body => "", :headers => {:error => "Customer with Name First Supplies already exists for merchant"})
79
+ stub_request(:post, "#{api_url}/customer/add").
80
+ with(request).to_return(:status => 500,
81
+ :body => "",
82
+ :headers => {:error => "Customer with Name First Supplies already exists for merchant"})
75
83
 
76
84
  expect { client.create_customer(customer) }.to raise_error ArrowPayments::Error, 'Customer with Name First Supplies already exists for merchant'
77
85
  end
78
86
  end
79
87
 
80
88
  describe '#update_customer' do
81
- it 'raises error if customer does not exist' do
82
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/10162").
83
- to_return(:status => 200, :body => fixture('customer.json'))
89
+ before do
90
+ stub_request(:get, "#{api_url}/foobar/customer/10162").
91
+ to_return(:status => 200,
92
+ :body => fixture('customer.json'))
93
+ end
84
94
 
85
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/update").
95
+ it 'raises error if customer does not exist' do
96
+ stub_request(:post, "#{api_url}/customer/update").
86
97
  with(
87
- :body => "{\"ID\":\"10163\",\"Name\":\"Foobar\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"RecurrentBilling\":[],\"PaymentMethods\":[{\"ID\":12436,\"CardType\":\"Visa\",\"Last4\":\"1111\",\"CardholderFirstName\":\"Paola\",\"CardholderLastName\":\"Chen\",\"ExpirationMonth\":6,\"ExpirationYear\":2015,\"BillingStreet1\":\"7495 Center St.\",\"BillingCity\":\"Chicago\",\"BillingState\":\"IL\",\"BillingZip\":\"60601\"}],\"CustomerID\":\"10163\",\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
98
+ :body => "{\"ID\":\"10163\",\"Name\":\"Foobar\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"RecurrentBilling\":[],\"PaymentMethods\":[{\"ID\":12436,\"CardType\":\"Visa\",\"Last4\":\"1111\",\"CardholderFirstName\":\"Paola\",\"CardholderLastName\":\"Chen\",\"ExpirationMonth\":6,\"ExpirationYear\":2015,\"BillingStreet1\":\"7495 Center St.\",\"BillingCity\":\"Chicago\",\"BillingState\":\"IL\",\"BillingZip\":\"60601\"}],\"CustomerID\":\"10163\",\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
88
99
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
89
100
  ).
90
101
  to_return(:status => 404, :body => "", :headers => {:error => "Customer Not Found"})
91
102
 
92
- customer = client.customer('10162')
93
- customer.id = '10163'
103
+ customer = client.customer('10162')
104
+ customer.id = '10163'
94
105
  customer.name = 'Foobar'
95
106
 
96
107
  expect { client.update_customer(customer) }.
@@ -98,17 +109,14 @@ describe ArrowPayments::Customers do
98
109
  end
99
110
 
100
111
  it 'raises error if customer is not valid' do
101
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/10162").
102
- to_return(:status => 200, :body => fixture('customer.json'))
103
-
104
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/update").
105
- with(
112
+ stub_request(:post, "#{api_url}/customer/update").with(
106
113
  :body => "{\"ID\":10162,\"Name\":\"Foobar\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"RecurrentBilling\":[],\"PaymentMethods\":[{\"ID\":12436,\"CardType\":\"Visa\",\"Last4\":\"1111\",\"CardholderFirstName\":\"Paola\",\"CardholderLastName\":\"Chen\",\"ExpirationMonth\":6,\"ExpirationYear\":2015,\"BillingStreet1\":\"7495 Center St.\",\"BillingCity\":\"Chicago\",\"BillingState\":\"IL\",\"BillingZip\":\"60601\"}],\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
107
114
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
108
- ).
109
- to_return(:status => 500, :body => "", :headers => {:error => "Customer with Name Foobar already exists for merchant"})
115
+ ).to_return(:status => 500,
116
+ :body => "",
117
+ :headers => {:error => "Customer with Name Foobar already exists for merchant"})
110
118
 
111
- customer = client.customer('10162')
119
+ customer = client.customer('10162')
112
120
  customer.name = 'Foobar'
113
121
 
114
122
  expect { client.update_customer(customer) }.
@@ -116,17 +124,13 @@ describe ArrowPayments::Customers do
116
124
  end
117
125
 
118
126
  it 'returns true if customer was updated' do
119
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/10162").
120
- to_return(:status => 200, :body => fixture('customer.json'))
121
-
122
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/update").
123
- with(
124
- :body => "{\"ID\":10162,\"Name\":\"Foobar\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"RecurrentBilling\":[],\"PaymentMethods\":[{\"ID\":12436,\"CardType\":\"Visa\",\"Last4\":\"1111\",\"CardholderFirstName\":\"Paola\",\"CardholderLastName\":\"Chen\",\"ExpirationMonth\":6,\"ExpirationYear\":2015,\"BillingStreet1\":\"7495 Center St.\",\"BillingCity\":\"Chicago\",\"BillingState\":\"IL\",\"BillingZip\":\"60601\"}],\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
127
+ stub_request(:post, "#{api_url}/customer/update").with(
128
+ :body => "{\"ID\":10162,\"Name\":\"Foobar\",\"Code\":\"First Supplies\",\"PrimaryContact\":\"John Peoples\",\"PrimaryContactPhone\":\"8325539616\",\"PrimaryContactEmailAddress\":\"John.Peoples@arrow-test.com\",\"RecurrentBilling\":[],\"PaymentMethods\":[{\"ID\":12436,\"CardType\":\"Visa\",\"Last4\":\"1111\",\"CardholderFirstName\":\"Paola\",\"CardholderLastName\":\"Chen\",\"ExpirationMonth\":6,\"ExpirationYear\":2015,\"BillingStreet1\":\"7495 Center St.\",\"BillingCity\":\"Chicago\",\"BillingState\":\"IL\",\"BillingZip\":\"60601\"}],\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
125
129
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
126
- ).
127
- to_return(:status => 200, :body => {'Success' => true}.to_json)
130
+ ).to_return(:status => 200,
131
+ :body => {'Success' => true}.to_json)
128
132
 
129
- customer = client.customer('10162')
133
+ customer = client.customer('10162')
130
134
  customer.name = 'Foobar'
131
135
 
132
136
  client.update_customer(customer).should be_true
@@ -134,27 +138,29 @@ describe ArrowPayments::Customers do
134
138
  end
135
139
 
136
140
  describe '#delete_customer' do
141
+ let(:request) do
142
+ {
143
+ :body => "{\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
144
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
145
+ }
146
+ end
147
+
137
148
  it 'raises error if customer does not exist' do
138
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/delete").
139
- with(
140
- :body => "{\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
141
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
142
- ).
143
- to_return(:status => 404, :body => "", :headers => {:error => "Customer Not Found"})
149
+ stub_request(:post, "#{api_url}/customer/delete").
150
+ with(request).to_return(:status => 404,
151
+ :body => "",
152
+ :headers => {:error => "Customer Not Found"})
144
153
 
145
154
  expect { client.delete_customer(10162) }.
146
155
  to raise_error ArrowPayments::NotFound, 'Customer Not Found'
147
156
  end
148
157
 
149
158
  it 'returns true if customer was deleted' do
150
- stub_request(:post, "http://demo.arrowpayments.com/api/customer/delete").
151
- with(
152
- :body => "{\"CustomerID\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
153
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
154
- ).
155
- to_return(:status => 200, :body => {'Success' => true}.to_json)
159
+ stub_request(:post, "#{api_url}/customer/delete").
160
+ with(request).to_return(:status => 200,
161
+ :body => {'Success' => true}.to_json)
156
162
 
157
163
  client.delete_customer(10162).should be_true
158
164
  end
159
165
  end
160
- end
166
+ end
data/spec/entity_spec.rb CHANGED
@@ -52,4 +52,4 @@ describe ArrowPayments::Entity do
52
52
  hash['FooBar'].should eq('c')
53
53
  end
54
54
  end
55
- end
55
+ end
@@ -26,4 +26,4 @@
26
26
  "ID": 40023,
27
27
  "Success": true,
28
28
  "Message": null
29
- }
29
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "ID":10162,
3
+ "Success":true,
4
+ "Message":"Tansaction Voided"
5
+ }
@@ -13,4 +13,4 @@ describe ArrowPayments::PaymentMethod do
13
13
  it { should respond_to :city }
14
14
  it { should respond_to :state }
15
15
  it { should respond_to :zip }
16
- end
16
+ end
@@ -3,102 +3,126 @@ require 'spec_helper'
3
3
  describe ArrowPayments::PaymentMethods do
4
4
  let(:client) { ArrowPayments.client }
5
5
 
6
+ let(:card) do
7
+ {
8
+ :first_name => 'John',
9
+ :last_name => 'Doe',
10
+ :number => '4111111111111111',
11
+ :security_code => '123',
12
+ :expiration_month => 12,
13
+ :expiration_year => 14
14
+ }
15
+ end
16
+
17
+ let(:address) do
18
+ {
19
+ :address => '3128 N Broadway',
20
+ :address2 => "Upstairs",
21
+ :city => 'Chicago',
22
+ :state => 'IL',
23
+ :zip => '60657',
24
+ :phone => '123123123'
25
+ }
26
+ end
27
+
6
28
  before :all do
7
29
  ArrowPayments::Configuration.api_key = 'foobar'
8
30
  ArrowPayments::Configuration.merchant_id = 'foo'
9
31
  ArrowPayments::Configuration.mode = 'sandbox'
32
+ ArrowPayments::Configuration.debug = false
10
33
  end
11
34
 
12
35
  describe '#start_payment_method' do
13
- it 'raises error if customer does not exist' do
14
- stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
15
- with(
16
- :body => "{\"CustomerId\":11843,\"BillingAddress\":{},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
17
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
18
- ).
19
- to_return(:status => 404, :body => "", :headers => {:error => "Invalid customer"})
20
36
 
21
- expect { client.start_payment_method(11843, {}) }.
22
- to raise_error ArrowPayments::NotFound, "Invalid customer"
37
+ context "when the request is accepted" do
38
+ it 'returns submit form url' do
39
+ stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
40
+ with(
41
+ :body => "{\"CustomerId\":11843,\"BillingAddress\":{\"Address1\":\"3128 N Broadway\",\"Address2\":\"Upstairs\",\"City\":\"Chicago\",\"State\":\"IL\",\"Postal\":\"60657\",\"Phone\":\"123123123\"},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
42
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
43
+ ).
44
+ to_return(:status => 200, :body => fixture('start_payment_method.json'), :headers => {})
45
+
46
+ url = client.start_payment_method(11843, address)
47
+ url.should eq('https://secure.nmi.com/api/v2/three-step/4i873m0s')
48
+ end
23
49
  end
24
50
 
25
- it 'raises error if address is not valid' do
26
- stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
27
- with(
28
- :body => "{\"CustomerId\":11843,\"BillingAddress\":{},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
29
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
30
- ).
31
- to_return(:status => 500, :body => "", :headers => {:error => "Something went wrong"})
32
-
33
- expect { client.start_payment_method(11843, {}) }.
34
- to raise_error ArrowPayments::Error
51
+ context "when the request is rejected" do
52
+ it 'raises error if customer does not exist' do
53
+ stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
54
+ with(
55
+ :body => "{\"CustomerId\":11843,\"BillingAddress\":{},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
56
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
57
+ ).
58
+ to_return(:status => 404, :body => "", :headers => {:error => "Invalid customer"})
59
+
60
+ expect { client.start_payment_method(11843, {}) }.
61
+ to raise_error ArrowPayments::NotFound, "Invalid customer"
62
+ end
63
+
64
+ it 'raises error if address is not valid' do
65
+ stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
66
+ with(
67
+ :body => "{\"CustomerId\":11843,\"BillingAddress\":{},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
68
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
69
+ ).
70
+ to_return(:status => 500, :body => "", :headers => {:error => "Something went wrong"})
71
+
72
+ expect { client.start_payment_method(11843, {}) }.
73
+ to raise_error ArrowPayments::Error
74
+ end
35
75
  end
76
+ end
36
77
 
37
- it 'returns submit form url' do
38
- address = {
39
- :address => '3128 N Broadway',
40
- :address2 => "Upstairs",
41
- :city => 'Chicago',
42
- :state => 'IL',
43
- :zip => '60657',
44
- :phone => '123123123'
78
+ describe '#setup_payment_method' do
79
+ let(:url) { 'https://secure.nmi.com/api/v2/three-step/4i873m0s' }
80
+
81
+ let(:request_body) do
82
+ {
83
+ "billing-cc-exp" => "1214",
84
+ "billing-cc-number" => "4111111111111111",
85
+ "billing-cvv" => "123",
86
+ "billing-first-name" => "John",
87
+ "billing-last-name" => "Doe"
45
88
  }
46
-
47
- stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
48
- with(
49
- :body => "{\"CustomerId\":11843,\"BillingAddress\":{\"Address1\":\"3128 N Broadway\",\"Address2\":\"Upstairs\",\"City\":\"Chicago\",\"State\":\"IL\",\"Postal\":\"60657\",\"Phone\":\"123123123\"},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
50
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
51
- ).
52
- to_return(:status => 200, :body => fixture('start_payment_method.json'), :headers => {})
53
-
54
- url = client.start_payment_method(11843, address)
55
- url.should eq('https://secure.nmi.com/api/v2/three-step/4i873m0s')
56
89
  end
57
- end
58
90
 
59
- describe '#setup_payment_method' do
60
- it 'return token to complete payment' do
61
- url = 'https://secure.nmi.com/api/v2/three-step/4i873m0s'
62
-
63
- card = {
64
- :first_name => 'John',
65
- :last_name => 'Doe',
66
- :number => '4111111111111111',
67
- :security_code => '123',
68
- :expiration_month => 12,
69
- :expiration_year => 14
91
+ let(:request_headers) do
92
+ {
93
+ 'Accept' => '*/*',
94
+ 'Content-Type' => 'application/x-www-form-urlencoded',
95
+ 'User-Agent' => 'Faraday v0.8.7'
70
96
  }
71
-
72
- stub_request(:post, "https://secure.nmi.com/api/v2/three-step/4i873m0s").
73
- with(
74
- :body => {"billing-cc-exp"=>"1214", "billing-cc-number"=>"4111111111111111", "billing-cvv"=>"123", "billing-first-name"=>"John", "billing-last-name"=>"Doe"},
75
- :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}
76
- ).
77
- to_return(
78
- :status => 200,
79
- :body => "",
80
- :headers => {:location => 'http://arrowdemo.cloudapp.net/api/echo?token-id=4i873m0s'}
81
- )
97
+ end
98
+
99
+ before do
100
+ stub_request(:post, url).with(:body => request_body, :headers => request_headers)
101
+ .to_return(:status => 200, :body => "", :headers => {:location => 'http://arrowdemo.cloudapp.net/api/echo?token-id=4i873m0s'} )
102
+ end
82
103
 
104
+ it 'returns a token to complete payment' do
83
105
  token = client.setup_payment_method(url, card)
84
106
  token.should eq('4i873m0s')
85
107
  end
86
108
  end
87
109
 
88
110
  describe '#complete_payment_method' do
89
- it 'returns a newly created payment method' do
90
- token = '4i873m0s'
111
+ let(:token) { '4i873m0s' }
91
112
 
113
+ before do
92
114
  stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/complete").
93
115
  with(
94
116
  :body => "{\"TokenID\":\"4i873m0s\",\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
95
117
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
96
118
  ).
97
119
  to_return(:status => 200, :body => fixture('complete_payment_method.json'), :headers => {})
120
+ end
98
121
 
99
- card = client.complete_payment_method(token)
100
- card.should be_a ArrowPayments::PaymentMethod
101
- card.id.should eq(14240)
122
+ it 'returns a newly created payment method' do
123
+ credit_card = client.complete_payment_method(token)
124
+ credit_card.should be_a ArrowPayments::PaymentMethod
125
+ credit_card.id.should eq(14240)
102
126
  end
103
127
  end
104
128
 
@@ -106,51 +130,33 @@ describe ArrowPayments::PaymentMethods do
106
130
  it 'return a newly created payment method' do
107
131
  customer_id = 11843
108
132
 
109
- address = {
110
- :address => '3128 N Broadway',
111
- :address2 => "Upstairs",
112
- :city => 'Chicago',
113
- :state => 'IL',
114
- :zip => '60657',
115
- :phone => '123123123'
116
- }
117
-
118
- card = {
119
- :first_name => 'John',
120
- :last_name => 'Doe',
121
- :number => '4111111111111111',
122
- :security_code => '123',
123
- :expiration_month => 12,
124
- :expiration_year => 14
125
- }
126
-
127
133
  stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/start").
128
134
  with(
129
135
  :body => "{\"CustomerId\":11843,\"BillingAddress\":{\"Address1\":\"3128 N Broadway\",\"Address2\":\"Upstairs\",\"City\":\"Chicago\",\"State\":\"IL\",\"Postal\":\"60657\",\"Phone\":\"123123123\"},\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
130
136
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
131
137
  ).
132
138
  to_return(:status => 200, :body => fixture('start_payment_method.json'), :headers => {})
133
-
139
+
134
140
  stub_request(:post, "https://secure.nmi.com/api/v2/three-step/4i873m0s").
135
141
  with(
136
142
  :body => {"billing-cc-exp"=>"1214", "billing-cc-number"=>"4111111111111111", "billing-cvv"=>"123", "billing-first-name"=>"John", "billing-last-name"=>"Doe"},
137
- :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}
143
+ :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.7'}
138
144
  ).
139
145
  to_return(
140
- :status => 200,
141
- :body => "",
146
+ :status => 200,
147
+ :body => "",
142
148
  :headers => {:location => 'http://arrowdemo.cloudapp.net/api/echo?token-id=4i873m0s'}
143
149
  )
144
-
150
+
145
151
  stub_request(:post, "http://demo.arrowpayments.com/api/paymentmethod/complete").
146
152
  with(
147
- :body => "{\"TokenID\":\"4i873m0s\",\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
153
+ :body => "{\"TokenID\":\"4i873m0s\",\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
148
154
  :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
149
155
  ).
150
156
  to_return(:status => 200, :body => fixture('complete_payment_method.json'), :headers => {})
151
157
 
152
- card = client.create_payment_method(customer_id, address, card)
153
- card.id.should eq(14240)
158
+ credit_card = client.create_payment_method(customer_id, address, card)
159
+ credit_card.id.should eq(14240)
154
160
  end
155
161
  end
156
162
 
@@ -178,4 +184,4 @@ describe ArrowPayments::PaymentMethods do
178
184
  client.delete_payment_method(12345).should be_true
179
185
  end
180
186
  end
181
- end
187
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  $:.unshift File.expand_path("../..", __FILE__)
2
5
 
3
6
  require 'webmock'
@@ -16,4 +19,18 @@ end
16
19
 
17
20
  def json_fixture(file)
18
21
  JSON.parse(fixture(file))
19
- end
22
+ end
23
+
24
+ def api_url(path=nil)
25
+ url = "http://demo.arrowpayments.com/api"
26
+ url << path if path
27
+ url
28
+ end
29
+
30
+ def stub_api(method, path, options={})
31
+ options[:status] ||= 200
32
+ options[:headers] ||= {}
33
+ options[:body] ||= ""
34
+
35
+ stub_request(method, api_url(path)).to_return(options)
36
+ end
@@ -11,18 +11,19 @@ describe ArrowPayments::Transactions do
11
11
 
12
12
  describe '#transaction' do
13
13
  it 'returns a transaction by ID' do
14
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/transaction/40023").
15
- to_return(:status => 200, :body => fixture('transaction.json'), :headers => {})
14
+ stub_api(:get, "/foobar/transaction/40023", :body => fixture('transaction.json'))
16
15
 
17
- tran = client.transaction('40023')
16
+ transaction = client.transaction('40023')
18
17
 
19
- tran.should_not be_nil
20
- tran.id.should eq(40023)
18
+ transaction.should_not be_nil
19
+ transaction.id.should eq(40023)
21
20
  end
22
21
 
23
22
  it 'returns nil if transaction does not exist' do
24
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/transaction/400231").
25
- to_return(:status => 404, :body => "", :headers => {:error => "Transaction Not Found"})
23
+ stub_request(:get, "#{api_url}/foobar/transaction/400231").
24
+ to_return(:status => 404,
25
+ :body => "",
26
+ :headers => {:error => "Transaction Not Found"})
26
27
 
27
28
  client.transaction('400231').should be_nil
28
29
  end
@@ -34,8 +35,10 @@ describe ArrowPayments::Transactions do
34
35
  end
35
36
 
36
37
  it 'returns unsettled transactions' do
37
- stub_request(:get, "http://demo.arrowpayments.com/api/foobar/customer/10162/Transactions/NotSettled").
38
- to_return(:status => 200, :body => fixture('transactions.json'), :headers => {})
38
+ stub_request(:get, "#{api_url}/foobar/customer/10162/Transactions/NotSettled").
39
+ to_return(:status => 200,
40
+ :body => fixture('transactions.json'),
41
+ :headers => {})
39
42
 
40
43
  transactions = client.transactions(10162, 'NotSettled')
41
44
 
@@ -50,52 +53,131 @@ describe ArrowPayments::Transactions do
50
53
  end
51
54
 
52
55
  describe '#create_transaction' do
53
- pending
56
+ let(:payment_information) do
57
+ {
58
+ :customer_id => "10162",
59
+ :payment_method_id => '0',
60
+ :transaction_type => 'sale',
61
+ :total_amount => 250,
62
+ :tax_amount => 0,
63
+ :shipping_amount => 0
64
+ }
65
+ end
66
+
67
+ let(:request) do
68
+ {
69
+ :body => "{\"TransactionType\":\"sale\",\"TotalAmount\":250,\"TransactionSource\":\"API\",\"PaymentMethodID\":\"0\",\"TaxAmount\":0,\"ShippingAmount\":0,\"CustomerID\":\"10162\",\"Amount\":250,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
70
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
71
+ }
72
+ end
73
+
74
+ it "creates a new transaction record" do
75
+ stub_request(:post, "#{api_url}/transaction/add").with(request).
76
+ to_return(:status => 200,
77
+ :body => fixture('transaction.json'),
78
+ :headers => {})
79
+
80
+ transaction = client.create_transaction(payment_information)
81
+ transaction.should_not be_nil
82
+ transaction.customer_name.should eq("First Supplies")
83
+ transaction.authorization_code.should eq("123456")
84
+ transaction.status.should eq("Not Settled")
85
+ end
86
+
87
+ it "raises an error if the payment method is not found" do
88
+ stub_request(:post, "#{api_url}/transaction/add").with(request).
89
+ to_return(:status => 404,
90
+ :body => "",
91
+ :headers => {:error => "Payment Method Not Found"})
92
+
93
+ expect {client.create_transaction(payment_information) }.to raise_error "Payment Method Not Found"
94
+ end
54
95
  end
55
96
 
56
97
  describe '#capture_transaction' do
98
+ let(:request) do
99
+ {
100
+ :body => "{\"TransactionId\":10162,\"Amount\":100,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
101
+ :headers => {'Accept'=>'application/json','Content-Type'=>'application/json','User-Agent'=>'Ruby'}
102
+ }
103
+ end
104
+
57
105
  it 'raises error if transaction does not exist' do
58
- stub_request(:post, "http://demo.arrowpayments.com/api/transaction/capture").
59
- with(
60
- :body => "{\"TransactionId\":10162,\"Amount\":100,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
61
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
62
- ).
63
- to_return(:status => 404, :body => "", :headers => {:error => "Transaction Not Found"})
106
+ stub_request(:post, "#{api_url}/transaction/capture").with(request).
107
+ to_return(:status => 404,
108
+ :body => "",
109
+ :headers => {:error => "Transaction Not Found"})
64
110
 
65
111
  expect { client.capture_transaction(10162, 100) }.to raise_error "Transaction Not Found"
66
112
  end
67
113
 
68
114
  it 'captures transaction for amount' do
69
- stub_request(:post, "http://demo.arrowpayments.com/api/transaction/capture").
70
- with(
71
- :body => "{\"TransactionId\":10162,\"Amount\":100,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
72
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
73
- ).
74
- to_return(:status => 200, :body => fixture('transaction_capture.json'), :headers => {})
115
+ stub_request(:post, "#{api_url}/transaction/capture").with(request).
116
+ to_return(:status => 200,
117
+ :body => fixture('transaction_capture.json'),
118
+ :headers => {})
75
119
 
76
120
  client.capture_transaction(10162, 100).should be_true
77
121
  end
78
122
 
79
123
  it 'raises a error if amount is greater than original' do
80
- pending
124
+
125
+ stub_request(:post, "#{api_url}/transaction/capture").with(request).
126
+ to_return(:status => 400,
127
+ :body => "",
128
+ :headers => {:error => "Unable to Capture for more than the original amount of $10.00"})
129
+
130
+ expect { client.capture_transaction(10162, 100) }.to raise_error "Unable to Capture for more than the original amount of $10.00"
81
131
  end
82
132
 
83
133
  it 'raises an error if transaction is already captured' do
84
- pending
134
+ stub_request(:post, "#{api_url}/transaction/capture").with(request).
135
+ to_return(:status => 400,
136
+ :body => "",
137
+ :headers => {:error => "Transaction is Captured Already"})
138
+
139
+ expect { client.capture_transaction(10162, 100) }.to raise_error "Transaction is Captured Already"
85
140
  end
86
141
  end
87
142
 
88
143
  describe '#void_transaction' do
89
- it 'raises an error if transaction does not exist' do
90
- pending
144
+
145
+ let(:request) do
146
+ {
147
+ :body => "{\"TransactionId\":10162,\"ApiKey\":\"foobar\",\"MID\":\"foo\"}",
148
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}
149
+ }
91
150
  end
92
151
 
93
- it 'voids transaction' do
94
- pending
152
+ context "successful request" do
153
+ it 'voids transaction' do
154
+ stub_request(:post, "#{api_url}/transaction/void").with(request).
155
+ to_return(:status => 200,
156
+ :body => fixture("void_transaction.json"),
157
+ :headers => {})
158
+
159
+ client.void_transaction(10162).should be_true
160
+ end
95
161
  end
96
162
 
97
- it 'raises an error if transaction is already voided' do
98
- pending
163
+ context "unsuccessful requests" do
164
+ it 'raises an error if transaction does not exist' do
165
+ stub_request(:post, "#{api_url}/transaction/void").with(request).
166
+ to_return(:status => 404,
167
+ :body => "",
168
+ :headers => {:error => "Transaction Not Found"})
169
+
170
+ expect { client.void_transaction(10162) }.to raise_error "Transaction Not Found"
171
+ end
172
+
173
+ it 'raises an error if transaction is already voided' do
174
+ stub_request(:post, "#{api_url}/transaction/void").with(request)
175
+ .to_return(:status => 400,
176
+ :body => "",
177
+ :headers => {:error => "Transaction Already Void"})
178
+
179
+ expect { client.void_transaction(10162) }.to raise_error "Transaction Already Void"
180
+ end
99
181
  end
100
182
  end
101
- end
183
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arrow_payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0.9'
37
+ version: '10.0'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0.9'
45
+ version: '10.0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.7'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.7'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: faraday
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +150,9 @@ files:
134
150
  - .rspec
135
151
  - .travis.yml
136
152
  - Gemfile
153
+ - LICENSE
137
154
  - README.md
155
+ - REFERENCE.md
138
156
  - Rakefile
139
157
  - arrow_payments.gemspec
140
158
  - lib/arrow_payments.rb
@@ -156,6 +174,7 @@ files:
156
174
  - spec/arrow_payments_spec.rb
157
175
  - spec/client_spec.rb
158
176
  - spec/configuration_spec.rb
177
+ - spec/connection_spec.rb
159
178
  - spec/customer_spec.rb
160
179
  - spec/customers_spec.rb
161
180
  - spec/entity_spec.rb
@@ -169,6 +188,7 @@ files:
169
188
  - spec/fixtures/transaction.json
170
189
  - spec/fixtures/transaction_capture.json
171
190
  - spec/fixtures/transactions.json
191
+ - spec/fixtures/void_transaction.json
172
192
  - spec/line_item_spec.rb
173
193
  - spec/payment_method_spec.rb
174
194
  - spec/payment_methods_spec.rb
@@ -203,6 +223,7 @@ test_files:
203
223
  - spec/arrow_payments_spec.rb
204
224
  - spec/client_spec.rb
205
225
  - spec/configuration_spec.rb
226
+ - spec/connection_spec.rb
206
227
  - spec/customer_spec.rb
207
228
  - spec/customers_spec.rb
208
229
  - spec/entity_spec.rb
@@ -216,6 +237,7 @@ test_files:
216
237
  - spec/fixtures/transaction.json
217
238
  - spec/fixtures/transaction_capture.json
218
239
  - spec/fixtures/transactions.json
240
+ - spec/fixtures/void_transaction.json
219
241
  - spec/line_item_spec.rb
220
242
  - spec/payment_method_spec.rb
221
243
  - spec/payment_methods_spec.rb