alpha_card 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +3 -1
- data/README.md +18 -1
- data/Rakefile +6 -0
- data/alpha_card.gemspec +3 -1
- data/lib/alpha_card.rb +33 -4
- data/spec/alpha_card/alpha_card_response_spec.rb +63 -0
- data/spec/alpha_card/alpha_card_spec.rb +106 -0
- data/spec/spec_helper.rb +12 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294f83e708f2952a60d2ecf8480ae58af870e368
|
4
|
+
data.tar.gz: 1fa31126072357beaed859e4415c03245a937e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c715932f21918d1914c83df62fd8a96e963b5a322c20da13b7facc00efc60cb8353ca6be255f403d0b684cb5db91fb4b92f623026adb7bdafb2a415ea54bb56
|
7
|
+
data.tar.gz: 1e091ed0479b8d61741f7cd37fea94f2b58ef6f5c34403743d4bd846d8e985080628ecd82a04b22fa15ffff96e0a150cb88c1a4a9daca67c24cd5a34b7dab988
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Ruby lib for creating payments with AlphaCard DirectPost API
|
2
|
-
[](http://badge.fury.io/rb/alpha_card)
|
3
3
|
[](https://gemnasium.com/budev/alpha_card)
|
4
4
|
|
5
5
|
This gem can help your ruby/rails application to integrate with AlphaCard service.
|
@@ -212,6 +212,23 @@ Example of exception:
|
|
212
212
|
AlphaCard::AlphaCardError: Invalid Credit Card Number REFID:127145481
|
213
213
|
```
|
214
214
|
|
215
|
+
## Contributing
|
216
|
+
|
217
|
+
You are very welcome to help improve alpha_card if you have suggestions for features that other people can use.
|
218
|
+
|
219
|
+
To contribute:
|
220
|
+
|
221
|
+
1. Fork the project
|
222
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
223
|
+
3. Make your changes
|
224
|
+
4. Add tests
|
225
|
+
5. Run `rake` to make sure all tests pass
|
226
|
+
6. Commit your changes (`git commit -am 'Add new feature'`)
|
227
|
+
7. Push to the branch (`git push origin my-new-feature`)
|
228
|
+
8. Create new pull request
|
229
|
+
|
230
|
+
Thanks.
|
231
|
+
|
215
232
|
## Copyright
|
216
233
|
|
217
234
|
Copyright (c) 2014 Nikita Bulaj (bulajnikita@gmail.com).
|
data/Rakefile
ADDED
data/alpha_card.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'alpha_card'
|
3
|
-
gem.version = '0.1.
|
3
|
+
gem.version = '0.1.5'
|
4
4
|
gem.date = '2014-06-25'
|
5
5
|
gem.summary = 'Alpha Card Services DirectPost API for Ruby'
|
6
6
|
gem.description = 'Gem for creating sales with Alpha Card Services DirectPost API'
|
@@ -11,4 +11,6 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.homepage = 'http://github.com/budev/alpha_card'
|
12
12
|
gem.license = 'MIT'
|
13
13
|
gem.required_ruby_version = '>= 1.9.3'
|
14
|
+
|
15
|
+
gem.add_development_dependency "rspec", '~> 3'
|
14
16
|
end
|
data/lib/alpha_card.rb
CHANGED
@@ -19,7 +19,7 @@ module AlphaCard
|
|
19
19
|
@api_base = 'https://secure.alphacardgateway.com/api/transact.php'
|
20
20
|
|
21
21
|
# Global Payment Systems (NDC) Credit Card Authorization Codes
|
22
|
-
CREDIT_CARD_CODES = YAML.load_file(File.expand_path('../alpha_card/data/codes.yml',
|
22
|
+
CREDIT_CARD_CODES = YAML.load_file(File.expand_path('../alpha_card/data/codes.yml', __FILE__)) unless defined? CREDIT_CARD_CODES
|
23
23
|
|
24
24
|
class << self
|
25
25
|
attr_accessor :api_base
|
@@ -38,10 +38,14 @@ module AlphaCard
|
|
38
38
|
raise AlphaCardError.new('You must set credentials to create the sale!')
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
begin
|
42
|
+
response = RestClient.post(@api_base, params.merge(account.attributes))
|
43
|
+
rescue => e
|
44
|
+
handle_connection_errors(e)
|
45
|
+
end
|
42
46
|
|
43
47
|
alpha_card_response = AlphaCardResponse.new(response.to_str)
|
44
|
-
|
48
|
+
handle_alpha_card_errors(alpha_card_response)
|
45
49
|
|
46
50
|
alpha_card_response
|
47
51
|
end
|
@@ -56,9 +60,34 @@ module AlphaCard
|
|
56
60
|
#
|
57
61
|
# response = AlphaCard.request(params, account)
|
58
62
|
# handle_errors(response) #=> nil or Exception
|
59
|
-
def self.
|
63
|
+
def self.handle_alpha_card_errors(response)
|
60
64
|
code = response.text
|
61
65
|
raise AlphaCardError.new(CREDIT_CARD_CODES[code] || code) unless response.success?
|
62
66
|
end
|
67
|
+
|
68
|
+
# AlphaCard.handle_connection_errors(exception) -> Exception
|
69
|
+
#
|
70
|
+
# Raise an exception if AlphaCard Gateway return some exception
|
71
|
+
# due to connection problems or some other net errors.
|
72
|
+
#
|
73
|
+
# response = RestClient.post(URL, {param: 'value'})
|
74
|
+
# handle_connection_errors(response) #=> Exception
|
75
|
+
def self.handle_connection_errors(e)
|
76
|
+
case e
|
77
|
+
when RestClient::ServerBrokeConnection, RestClient::RequestTimeout
|
78
|
+
message = "Could not connect to Alpha Card Gateway (#{@api_base}). " +
|
79
|
+
'Please check your internet connection and try again. ' +
|
80
|
+
'If this problem persists, you should check Alpha Card services status.'
|
81
|
+
|
82
|
+
when SocketError
|
83
|
+
message = 'Unexpected error communicating when trying to connect to Alpha Card Gateway. ' +
|
84
|
+
'You may be seeing this message because your DNS is not working.'
|
85
|
+
|
86
|
+
else
|
87
|
+
message = 'Unexpected error communicating with Alpha Card Gateway.'
|
88
|
+
end
|
89
|
+
|
90
|
+
raise AlphaCardError.new(message + "\n\n(Network error: #{e.message})")
|
91
|
+
end
|
63
92
|
end
|
64
93
|
|
@@ -0,0 +1,63 @@
|
|
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
|
@@ -0,0 +1,106 @@
|
|
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
|
+
#TODO: Create rest client mock to imitate requests, normal tests for error exceptions
|
12
|
+
|
13
|
+
context 'With valid attributes' do
|
14
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
|
15
|
+
|
16
|
+
it 'should successfully create the sale' do
|
17
|
+
expect(sale.create(order, account)).to be_truthy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'With invalid Card number' do
|
22
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: 'Invalid', amount: '5.00'}) }
|
23
|
+
|
24
|
+
it 'should raise an AlphaCardError' do
|
25
|
+
expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
26
|
+
expect(e.message).to include('Card number must contain only digits')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'With invalid amount' do
|
32
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '0.00'}) }
|
33
|
+
|
34
|
+
it 'should raise an AlphaCardError' do
|
35
|
+
expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
36
|
+
expect(e.message).to include('Invalid amount')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'With invalid Card expiration date' do
|
42
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: 'Invalid', ccnumber: '4111111111111111', amount: '5.00'}) }
|
43
|
+
|
44
|
+
it 'should raise an AlphaCardError' do
|
45
|
+
expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
46
|
+
expect(e.message).to include('Card expiration should be in the format')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'With invalid Card CVV' do
|
52
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, cvv: 'Invalid', ccnumber: '4111111111111111', amount: '5.00'}) }
|
53
|
+
|
54
|
+
it 'should raise an AlphaCardError' do
|
55
|
+
expect { sale.create(order, account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
56
|
+
expect(e.message).to include('CVV must be')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'With invalid account credentials' do
|
62
|
+
let!(:invalid_account) { AlphaCard::Account.new('demo', 'Invalid password') }
|
63
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
|
64
|
+
|
65
|
+
it 'should raise an AlphaCardError' do
|
66
|
+
expect { sale.create(order, invalid_account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
67
|
+
expect(e.message).to include('Authentication Failed')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'With blank account credentials' do
|
73
|
+
let!(:blank_account) { AlphaCard::Account.new(nil, '') }
|
74
|
+
let!(:sale) { AlphaCard::Sale.new({ccexp: card_exp, ccnumber: '4111111111111111', amount: '5.00'}) }
|
75
|
+
|
76
|
+
it 'should raise an AlphaCardError' do
|
77
|
+
expect { sale.create(order, blank_account) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
78
|
+
expect(e.message).to include('You must set credentials to create the sale')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'With connection errors' do
|
84
|
+
let!(:rest_client_error) { RestClient::RequestTimeout.new }
|
85
|
+
let!(:socket_error) { SocketError.new }
|
86
|
+
let!(:unclassified_error) { StandardError.new('Some error') }
|
87
|
+
|
88
|
+
it 'should raise an Exception if Rest Client Error' do
|
89
|
+
expect { AlphaCard.handle_connection_errors(rest_client_error) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
90
|
+
expect(e.message).to include('Could not connect to Alpha Card Gateway')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should raise an Exception if Socket Error' do
|
95
|
+
expect { AlphaCard.handle_connection_errors(socket_error) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
96
|
+
expect(e.message).to include('Unexpected error communicating when trying to connect to Alpha Card Gateway')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should raise an Exception if Unclassified Error' do
|
101
|
+
expect { AlphaCard.handle_connection_errors(unclassified_error) }.to raise_error(AlphaCard::AlphaCardError) do |e|
|
102
|
+
expect(e.message).to include('Unexpected error communicating with Alpha Card Gateway')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alpha_card
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Bulaj
|
@@ -9,16 +9,33 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-06-25 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
13
27
|
description: Gem for creating sales with Alpha Card Services DirectPost API
|
14
28
|
email: bulajnikita@gmail.com
|
15
29
|
executables: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".rspec"
|
19
35
|
- Gemfile
|
20
36
|
- LICENSE
|
21
37
|
- README.md
|
38
|
+
- Rakefile
|
22
39
|
- alpha_card.gemspec
|
23
40
|
- lib/alpha_card.rb
|
24
41
|
- lib/alpha_card/account.rb
|
@@ -31,6 +48,9 @@ files:
|
|
31
48
|
- lib/alpha_card/order.rb
|
32
49
|
- lib/alpha_card/sale.rb
|
33
50
|
- lib/alpha_card/shipping.rb
|
51
|
+
- spec/alpha_card/alpha_card_response_spec.rb
|
52
|
+
- spec/alpha_card/alpha_card_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
34
54
|
homepage: http://github.com/budev/alpha_card
|
35
55
|
licenses:
|
36
56
|
- MIT
|