alpha_card 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/alpha_card.gemspec +2 -2
- data/lib/alpha_card.rb +7 -5
- data/lib/alpha_card/alpha_card_response.rb +3 -3
- data/lib/alpha_card/data/{codes.yml → credit_card_codes.yml} +0 -0
- data/lib/alpha_card/errors/alpha_card_error.rb +23 -0
- data/lib/alpha_card/errors/api_connection_error.rb +6 -0
- data/spec/alpha_card/alpha_card_spec.rb +6 -6
- metadata +5 -4
- data/lib/alpha_card/alpha_card_error.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76fc164bc35261fa54520d3d411288fe4dac224e
|
4
|
+
data.tar.gz: fa87d69a8a812fca096d22e394c82ea9ef4f31cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e354992f043c879b4b6f12e931417dba4356b19ad757223b875f98d00f89a50d0281b514c0c0b20aa793727da396ba760d17ae05704849033ed9ef1c0ef1a4b
|
7
|
+
data.tar.gz: c9533e52a55e8ab79b447c32e55e15fffe4e38064e9cd1850ddefb706c4fd3567ee8345aa2fff0d924dfa81842921674f8608fe18674078052970a89ae3dc04b
|
data/alpha_card.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'alpha_card'
|
3
|
-
gem.version = '0.
|
4
|
-
gem.date = '2014-07-
|
3
|
+
gem.version = '0.2.0'
|
4
|
+
gem.date = '2014-07-09'
|
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'
|
7
7
|
gem.authors = ['Nikita Bulaj']
|
data/lib/alpha_card.rb
CHANGED
@@ -6,7 +6,9 @@ require 'rest_client'
|
|
6
6
|
require 'alpha_card/utils'
|
7
7
|
require 'alpha_card/alpha_card_object'
|
8
8
|
require 'alpha_card/alpha_card_response'
|
9
|
-
|
9
|
+
|
10
|
+
require 'alpha_card/errors/alpha_card_error'
|
11
|
+
require 'alpha_card/errors/api_connection_error'
|
10
12
|
|
11
13
|
require 'alpha_card/account'
|
12
14
|
require 'alpha_card/shipping'
|
@@ -25,10 +27,10 @@ module AlphaCard
|
|
25
27
|
# Global Payment Systems (NDC) Credit Card Authorization Codes
|
26
28
|
#
|
27
29
|
# @see http://floristwiki.ftdi.com/images/c/ce/Appendix_A_-_Credit_Card_Authorization_Codes.pdf Credit Card Authorization Codes
|
28
|
-
CREDIT_CARD_CODES ||= YAML.load_file(File.expand_path('../alpha_card/data/
|
30
|
+
CREDIT_CARD_CODES ||= YAML.load_file(File.expand_path('../alpha_card/data/credit_card_codes.yml', __FILE__))
|
29
31
|
|
30
32
|
class << self
|
31
|
-
|
33
|
+
# @return [String] Alpha Card Gateway DirectPost API URL.
|
32
34
|
attr_accessor :api_base
|
33
35
|
end
|
34
36
|
|
@@ -99,7 +101,7 @@ module AlphaCard
|
|
99
101
|
# Alpha Card Services response text.
|
100
102
|
def self.handle_alpha_card_errors(response)
|
101
103
|
code = response.text
|
102
|
-
raise AlphaCardError.new(CREDIT_CARD_CODES[code] || code) unless response.success?
|
104
|
+
raise AlphaCardError.new(CREDIT_CARD_CODES[code] || code, response) unless response.success?
|
103
105
|
end
|
104
106
|
|
105
107
|
##
|
@@ -126,7 +128,7 @@ module AlphaCard
|
|
126
128
|
message = 'Unexpected error communicating with Alpha Card Gateway.'
|
127
129
|
end
|
128
130
|
|
129
|
-
raise
|
131
|
+
raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
@@ -80,7 +80,7 @@ module AlphaCard
|
|
80
80
|
##
|
81
81
|
# Indicate the state of the request to the
|
82
82
|
# Alpha Card Gateway. Returns <i>true</i> if
|
83
|
-
#
|
83
|
+
# request was <i>approved</i>.
|
84
84
|
#
|
85
85
|
# @return [Bool] true if request if successful
|
86
86
|
#
|
@@ -97,7 +97,7 @@ module AlphaCard
|
|
97
97
|
##
|
98
98
|
# Indicate the state of the request to the
|
99
99
|
# Alpha Card Gateway. Returns <i>true</i> if
|
100
|
-
#
|
100
|
+
# request was <i>declined</i>.
|
101
101
|
#
|
102
102
|
# @return [Bool] true if request was declined
|
103
103
|
#
|
@@ -114,7 +114,7 @@ module AlphaCard
|
|
114
114
|
##
|
115
115
|
# Indicate the state of the request to the
|
116
116
|
# Alpha Card Gateway. Returns <i>true</i> if
|
117
|
-
#
|
117
|
+
# request has some <i>errors</i>.
|
118
118
|
#
|
119
119
|
# @return [Bool] true if request has some errors
|
120
120
|
#
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AlphaCard
|
2
|
+
##
|
3
|
+
# Common class for Alpha Card Gateway errors and exceptions.
|
4
|
+
class AlphaCardError < StandardError
|
5
|
+
attr_reader :response
|
6
|
+
attr_reader :message
|
7
|
+
|
8
|
+
##
|
9
|
+
# <code>AlphaCard::AlphaCardError</code> constructor.
|
10
|
+
#
|
11
|
+
# @param [String] error message
|
12
|
+
# @param [AlphaCard::AlphaCardResponse] AlphaCard Gateway response
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# AlphaCard::AlphaCardError.new
|
16
|
+
#
|
17
|
+
# #=> #<AlphaCard::AlphaCardError: AlphaCard::AlphaCardError>
|
18
|
+
def initialize(message = nil, response = nil)
|
19
|
+
@message = message
|
20
|
+
@response = response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -93,20 +93,20 @@ describe AlphaCard do
|
|
93
93
|
let!(:socket_error) { SocketError.new }
|
94
94
|
let!(:unclassified_error) { StandardError.new('Some error') }
|
95
95
|
|
96
|
-
it 'should raise an
|
97
|
-
expect { AlphaCard.handle_connection_errors(rest_client_error) }.to raise_error(AlphaCard::
|
96
|
+
it 'should raise an APIConnectionError if Rest Client Error' do
|
97
|
+
expect { AlphaCard.handle_connection_errors(rest_client_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
|
98
98
|
expect(e.message).to include('Could not connect to Alpha Card Gateway')
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
it 'should raise an
|
103
|
-
expect { AlphaCard.handle_connection_errors(socket_error) }.to raise_error(AlphaCard::
|
102
|
+
it 'should raise an APIConnectionError if Socket Error' do
|
103
|
+
expect { AlphaCard.handle_connection_errors(socket_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
|
104
104
|
expect(e.message).to include('Unexpected error communicating when trying to connect to Alpha Card Gateway')
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
it 'should raise an
|
109
|
-
expect { AlphaCard.handle_connection_errors(unclassified_error) }.to raise_error(AlphaCard::
|
108
|
+
it 'should raise an APIConnectionError if Unclassified Error' do
|
109
|
+
expect { AlphaCard.handle_connection_errors(unclassified_error) }.to raise_error(AlphaCard::APIConnectionError) do |e|
|
110
110
|
expect(e.message).to include('Unexpected error communicating with Alpha Card Gateway')
|
111
111
|
end
|
112
112
|
end
|
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.
|
4
|
+
version: 0.2.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: 2014-07-
|
11
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -40,11 +40,12 @@ files:
|
|
40
40
|
- alpha_card.gemspec
|
41
41
|
- lib/alpha_card.rb
|
42
42
|
- lib/alpha_card/account.rb
|
43
|
-
- lib/alpha_card/alpha_card_error.rb
|
44
43
|
- lib/alpha_card/alpha_card_object.rb
|
45
44
|
- lib/alpha_card/alpha_card_response.rb
|
46
45
|
- lib/alpha_card/billing.rb
|
47
|
-
- lib/alpha_card/data/
|
46
|
+
- lib/alpha_card/data/credit_card_codes.yml
|
47
|
+
- lib/alpha_card/errors/alpha_card_error.rb
|
48
|
+
- lib/alpha_card/errors/api_connection_error.rb
|
48
49
|
- lib/alpha_card/order.rb
|
49
50
|
- lib/alpha_card/sale.rb
|
50
51
|
- lib/alpha_card/shipping.rb
|