alpha_card 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +1 -5
  4. data/CHANGELOG.md +54 -0
  5. data/Gemfile.lock +25 -37
  6. data/LICENSE +1 -1
  7. data/README.md +207 -67
  8. data/ROADMAP.md +12 -0
  9. data/alpha_card.gemspec +5 -4
  10. data/lib/alpha_card.rb +11 -6
  11. data/lib/alpha_card/alpha_card_object.rb +59 -3
  12. data/lib/alpha_card/alpha_card_response.rb +99 -16
  13. data/lib/alpha_card/data/avs_responses.yml +20 -0
  14. data/lib/alpha_card/data/credit_card_codes.yml +1 -1
  15. data/lib/alpha_card/data/cvv_responses.yml +5 -0
  16. data/lib/alpha_card/data/response_messages.yml +33 -0
  17. data/lib/alpha_card/errors/alpha_card_error.rb +1 -1
  18. data/lib/alpha_card/errors/invalid_object_error.rb +8 -0
  19. data/lib/alpha_card/objects/account.rb +1 -1
  20. data/lib/alpha_card/objects/billing.rb +15 -4
  21. data/lib/alpha_card/objects/capture.rb +51 -0
  22. data/lib/alpha_card/objects/order.rb +41 -4
  23. data/lib/alpha_card/objects/refund.rb +20 -0
  24. data/lib/alpha_card/objects/sale.rb +32 -22
  25. data/lib/alpha_card/objects/shipping.rb +15 -4
  26. data/lib/alpha_card/objects/update.rb +54 -0
  27. data/lib/alpha_card/objects/void.rb +45 -0
  28. data/lib/alpha_card/version.rb +18 -2
  29. data/spec/alpha_card/objects/account_spec.rb +20 -0
  30. data/spec/alpha_card/objects/capture_spec.rb +51 -0
  31. data/spec/alpha_card/objects/deprecated_methods_spec.rb +32 -0
  32. data/spec/alpha_card/objects/refund_spec.rb +35 -0
  33. data/spec/alpha_card/objects/sale_spec.rb +143 -0
  34. data/spec/alpha_card/objects/update_spec.rb +36 -0
  35. data/spec/alpha_card/objects/void_spec.rb +48 -0
  36. data/spec/alpha_card/response_spec.rb +111 -0
  37. data/spec/spec_helper.rb +7 -2
  38. metadata +44 -9
  39. data/spec/alpha_card/alpha_card_account_spec.rb +0 -18
  40. data/spec/alpha_card/alpha_card_response_spec.rb +0 -63
  41. data/spec/alpha_card/alpha_card_spec.rb +0 -123
@@ -1,7 +1,12 @@
1
1
  require 'rack/test'
2
2
 
3
- require 'coveralls'
4
- Coveralls.wear!
3
+ if ENV['CI'] || ENV['TRAVIS'] || ENV['COVERALLS'] || ENV['JENKINS_URL']
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+ else
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+ end
5
10
 
6
11
  require 'bundler/setup'
7
12
  Bundler.setup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alpha_card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulaj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -30,20 +30,40 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.5
33
+ - !ruby/object:Gem::Dependency
34
+ name: rack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.2'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: rspec
35
55
  requirement: !ruby/object:Gem::Requirement
36
56
  requirements:
37
57
  - - "~>"
38
58
  - !ruby/object:Gem::Version
39
- version: '3'
59
+ version: '3.5'
40
60
  type: :development
41
61
  prerelease: false
42
62
  version_requirements: !ruby/object:Gem::Requirement
43
63
  requirements:
44
64
  - - "~>"
45
65
  - !ruby/object:Gem::Version
46
- version: '3'
66
+ version: '3.5'
47
67
  description: Gem for creating sales with Alpha Card Services
48
68
  email: bulajnikita@gmail.com
49
69
  executables: []
@@ -53,27 +73,42 @@ files:
53
73
  - ".gitignore"
54
74
  - ".rspec"
55
75
  - ".travis.yml"
76
+ - CHANGELOG.md
56
77
  - Gemfile
57
78
  - Gemfile.lock
58
79
  - LICENSE
59
80
  - README.md
81
+ - ROADMAP.md
60
82
  - Rakefile
61
83
  - alpha_card.gemspec
62
84
  - lib/alpha_card.rb
63
85
  - lib/alpha_card/alpha_card_object.rb
64
86
  - lib/alpha_card/alpha_card_response.rb
87
+ - lib/alpha_card/data/avs_responses.yml
65
88
  - lib/alpha_card/data/credit_card_codes.yml
89
+ - lib/alpha_card/data/cvv_responses.yml
90
+ - lib/alpha_card/data/response_messages.yml
66
91
  - lib/alpha_card/errors/alpha_card_error.rb
67
92
  - lib/alpha_card/errors/api_connection_error.rb
93
+ - lib/alpha_card/errors/invalid_object_error.rb
68
94
  - lib/alpha_card/objects/account.rb
69
95
  - lib/alpha_card/objects/billing.rb
96
+ - lib/alpha_card/objects/capture.rb
70
97
  - lib/alpha_card/objects/order.rb
98
+ - lib/alpha_card/objects/refund.rb
71
99
  - lib/alpha_card/objects/sale.rb
72
100
  - lib/alpha_card/objects/shipping.rb
101
+ - lib/alpha_card/objects/update.rb
102
+ - lib/alpha_card/objects/void.rb
73
103
  - lib/alpha_card/version.rb
74
- - spec/alpha_card/alpha_card_account_spec.rb
75
- - spec/alpha_card/alpha_card_response_spec.rb
76
- - spec/alpha_card/alpha_card_spec.rb
104
+ - spec/alpha_card/objects/account_spec.rb
105
+ - spec/alpha_card/objects/capture_spec.rb
106
+ - spec/alpha_card/objects/deprecated_methods_spec.rb
107
+ - spec/alpha_card/objects/refund_spec.rb
108
+ - spec/alpha_card/objects/sale_spec.rb
109
+ - spec/alpha_card/objects/update_spec.rb
110
+ - spec/alpha_card/objects/void_spec.rb
111
+ - spec/alpha_card/response_spec.rb
77
112
  - spec/spec_helper.rb
78
113
  homepage: http://github.com/nbulaj/alpha_card
79
114
  licenses:
@@ -87,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
122
  requirements:
88
123
  - - ">="
89
124
  - !ruby/object:Gem::Version
90
- version: 1.9.3
125
+ version: 2.0.0
91
126
  required_rubygems_version: !ruby/object:Gem::Requirement
92
127
  requirements:
93
128
  - - ">="
@@ -95,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
130
  version: '0'
96
131
  requirements: []
97
132
  rubyforge_project:
98
- rubygems_version: 2.4.8
133
+ rubygems_version: 2.5.1
99
134
  signing_key:
100
135
  specification_version: 4
101
136
  summary: Alpha Card Services API for Ruby
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AlphaCard::Account do
4
- let!(:valid_account) { AlphaCard::Account.new('demo', 'password') }
5
- let!(:invalid_account) { AlphaCard::Account.new('', '') }
6
-
7
- context 'with valid credentials' do
8
- it 'should return true if credentials are filled' do
9
- expect(valid_account.filled?).to be_truthy
10
- end
11
- end
12
-
13
- context 'with invalid credentials' do
14
- it 'should return false if credentials are filled' do
15
- expect(invalid_account.filled?).to be_falsey
16
- end
17
- end
18
- end
@@ -1,63 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AlphaCard::AlphaCardResponse do
4
- let!(:successful_response_mock) {
5
- "authcode=083319&avsresponse=&cvvresponse=M&orderid=1&response=1&response_code=100&responsetext=AP&transactionid=2303767426&type=sale"
6
- }
7
-
8
- let!(:declined_response_mock) {
9
- "authcode=&avsresponse=&cvvresponse=&orderid=1&response=2&response_code=220&responsetext=INVLD+ACCT&transactionid=2302720045&type=sale"
10
- }
11
-
12
- let!(:error_response_mock) {
13
- "authcode=&avsresponse=&cvvresponse=&orderid=1&response=3&response_code=220&responsetext=ERROR&transactionid=2302620041&type=sale"
14
- }
15
-
16
- context 'successful request' do
17
- let!(:response) { AlphaCard::AlphaCardResponse.new(successful_response_mock) }
18
-
19
- it 'should be success' do
20
- expect(response.success?).to be_truthy
21
- end
22
-
23
- it 'should return responce code' do
24
- expect(response.code).to eq('100')
25
- end
26
-
27
- it 'should return transaction id' do
28
- expect(response.transaction_id).to eq('2303767426')
29
- end
30
- end
31
-
32
- context 'declined request' do
33
- let!(:response) { AlphaCard::AlphaCardResponse.new(declined_response_mock) }
34
-
35
- it 'should be declined' do
36
- expect(response.declined?).to be_truthy
37
- end
38
-
39
- it 'should return responce code' do
40
- expect(response.code).to eq('220')
41
- end
42
-
43
- it 'should return transaction id' do
44
- expect(response.transaction_id).to eq('2302720045')
45
- end
46
- end
47
-
48
- context 'error request' do
49
- let!(:response) { AlphaCard::AlphaCardResponse.new(error_response_mock) }
50
-
51
- it 'should be error' do
52
- expect(response.error?).to be_truthy
53
- end
54
-
55
- it 'should return responce code' do
56
- expect(response.code).to eq('220')
57
- end
58
-
59
- it 'should return transaction id' do
60
- expect(response.transaction_id).to eq('2302620041')
61
- end
62
- end
63
- end
@@ -1,123 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe AlphaCard do
4
- # Shared objects
5
- let!(:account) { AlphaCard::Account.new('demo', 'password') }
6
- let!(:billing) { AlphaCard::Billing.new({email: 'test@example.com'}) }
7
- let!(:shipping) { AlphaCard::Shipping.new({address_1: '22 N str.'}) }
8
- let!(:order) { AlphaCard::Order.new({orderid: '1', billing: billing, shipping: shipping}) }
9
- let!(:card_exp) { "#{'%02d' % Time.now.month}/#{Time.now.year.next}" }
10
-
11
- context 'With valid attributes' do
12
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
13
-
14
- it 'should successfully create the sale' do
15
- expect(sale.create(order, account)).to be_truthy
16
- end
17
- end
18
-
19
- context 'With invalid Card number' do
20
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: 'Invalid', amount: '5.00'}) }
21
-
22
- it 'should raise an AlphaCardError' do
23
- expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
24
- expect(e.message).to include('Card number must contain only digits')
25
- end
26
- end
27
- end
28
-
29
- context 'With invalid amount' do
30
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '0.00'}) }
31
-
32
- it 'should raise an AlphaCardError' do
33
- expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
34
- expect(e.message).to include('Invalid amount')
35
- end
36
- end
37
- end
38
-
39
- context 'With invalid Card expiration date' do
40
- let!(:sale) { AlphaCard::Sale.new({ccexp: 'Invalid', ccnumber: '4111111111111111', amount: '5.00'}) }
41
-
42
- it 'should raise an AlphaCardError' do
43
- expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
44
- expect(e.message).to include('Card expiration should be in the format')
45
- end
46
- end
47
- end
48
-
49
- context 'With invalid Card CVV' do
50
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, cvv: 'Invalid', ccnumber: '4111111111111111', amount: '5.00'}) }
51
-
52
- it 'should raise an AlphaCardError' do
53
- expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
54
- expect(e.message).to include('CVV must be')
55
- end
56
- end
57
- end
58
-
59
- context 'With invalid account credentials' do
60
- let!(:invalid_account) { AlphaCard::Account.new('demo', 'Invalid password') }
61
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
62
-
63
- it 'should raise an AlphaCardError' do
64
- expect { sale.create(order, invalid_account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
65
- expect(e.message).to include('Authentication Failed')
66
- end
67
- end
68
- end
69
-
70
- context 'Without attributes' do
71
- let!(:sale) { AlphaCard::Sale.new({}) }
72
-
73
- it 'should raise an Exception' do
74
- expect { sale.create(order, account) }.to raise_error(ArgumentError)
75
- end
76
- end
77
-
78
- context 'With blank account credentials' do
79
- let!(:blank_account) { AlphaCard::Account.new(nil, '') }
80
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
81
-
82
- it 'should raise an AlphaCardError' do
83
- expect { sale.create(order, blank_account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
84
- expect(e.message).to include('You must set credentials to create the sale')
85
- end
86
- end
87
- end
88
-
89
- context 'With connection errors' do
90
- let!(:timeout_error) { Timeout::Error.new }
91
- let!(:socket_error) { SocketError.new }
92
- let!(:unclassified_error) { StandardError.new('Some error') }
93
-
94
- it 'should raise an APIConnectionError if Timeout Error' do
95
- expect { AlphaCard.handle_connection_errors(timeout_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
96
- expect(e.message).to include('Could not connect to Alpha Card Gateway')
97
- end
98
- end
99
-
100
- it 'should raise an APIConnectionError if Socket Error' do
101
- expect { AlphaCard.handle_connection_errors(socket_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
102
- expect(e.message).to include('Unexpected error communicating when trying to connect to Alpha Card Gateway')
103
- end
104
- end
105
-
106
- it 'should raise an APIConnectionError if Unclassified Error' do
107
- expect { AlphaCard.handle_connection_errors(unclassified_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
108
- expect(e.message).to include('Unexpected error communicating with Alpha Card Gateway')
109
- end
110
- end
111
-
112
- context 'With request exception' do
113
- let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
114
-
115
- it 'should handle an error' do
116
- AlphaCard.api_base = 'https://not-existing.com' # todo: some other service
117
- expect { sale.create(order, account) }.to raise_error(AlphaCard::APIConnectionError)
118
-
119
- AlphaCard.api_base = 'https://secure.alphacardgateway.com/api/transact.php'
120
- end
121
- end
122
- end
123
- end