cardconnect 1.0.0
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +154 -0
- data/Rakefile +178 -0
- data/cardconnect.gemspec +25 -0
- data/lib/cardconnect.rb +49 -0
- data/lib/cardconnect/configuration.rb +13 -0
- data/lib/cardconnect/connection.rb +35 -0
- data/lib/cardconnect/error.rb +3 -0
- data/lib/cardconnect/services/authorization/authorization.rb +17 -0
- data/lib/cardconnect/services/authorization/authorization_request.rb +51 -0
- data/lib/cardconnect/services/authorization/authorization_response.rb +41 -0
- data/lib/cardconnect/services/capture/capture.rb +17 -0
- data/lib/cardconnect/services/capture/capture_request.rb +50 -0
- data/lib/cardconnect/services/capture/capture_response.rb +24 -0
- data/lib/cardconnect/services/deposit/deposit.rb +17 -0
- data/lib/cardconnect/services/deposit/deposit_request.rb +64 -0
- data/lib/cardconnect/services/deposit/deposit_response.rb +40 -0
- data/lib/cardconnect/services/inquire/inquire.rb +17 -0
- data/lib/cardconnect/services/inquire/inquire_request.rb +44 -0
- data/lib/cardconnect/services/inquire/inquire_response.rb +31 -0
- data/lib/cardconnect/services/refund/refund.rb +16 -0
- data/lib/cardconnect/services/refund/refund_request.rb +50 -0
- data/lib/cardconnect/services/refund/refund_response.rb +40 -0
- data/lib/cardconnect/services/service_endpoint.rb +69 -0
- data/lib/cardconnect/services/settlement_status/settlement_status.rb +17 -0
- data/lib/cardconnect/services/settlement_status/settlement_status_request.rb +64 -0
- data/lib/cardconnect/services/settlement_status/settlement_status_response.rb +39 -0
- data/lib/cardconnect/services/void/void.rb +16 -0
- data/lib/cardconnect/services/void/void_request.rb +50 -0
- data/lib/cardconnect/services/void/void_response.rb +40 -0
- data/lib/cardconnect/utils.rb +22 -0
- data/lib/cardconnect/version.rb +3 -0
- data/test/api_request_stubs.rb +83 -0
- data/test/api_response_stubs.rb +120 -0
- data/test/cardconnect/configuration_test.rb +28 -0
- data/test/cardconnect/connection_test.rb +36 -0
- data/test/cardconnect/services/authorization/authorization_request_test.rb +141 -0
- data/test/cardconnect/services/authorization/authorization_response_test.rb +93 -0
- data/test/cardconnect/services/authorization/authorization_test.rb +59 -0
- data/test/cardconnect/services/capture/capture_request_test.rb +65 -0
- data/test/cardconnect/services/capture/capture_response_test.rb +39 -0
- data/test/cardconnect/services/capture/capture_test.rb +58 -0
- data/test/cardconnect/services/deposit/deposit_request_test.rb +65 -0
- data/test/cardconnect/services/deposit/deposit_response_test.rb +75 -0
- data/test/cardconnect/services/deposit/deposit_test.rb +55 -0
- data/test/cardconnect/services/inquire/inquire_request_test.rb +45 -0
- data/test/cardconnect/services/inquire/inquire_response_test.rb +59 -0
- data/test/cardconnect/services/inquire/inquire_test.rb +56 -0
- data/test/cardconnect/services/refund/refund_request_test.rb +49 -0
- data/test/cardconnect/services/refund/refund_response_test.rb +73 -0
- data/test/cardconnect/services/refund/refund_test.rb +57 -0
- data/test/cardconnect/services/settlement_status/settlement_status_request_test.rb +65 -0
- data/test/cardconnect/services/settlement_status/settlement_status_response_test.rb +47 -0
- data/test/cardconnect/services/settlement_status/settlement_status_test.rb +55 -0
- data/test/cardconnect/services/void/void_request_test.rb +49 -0
- data/test/cardconnect/services/void/void_response_test.rb +77 -0
- data/test/cardconnect/services/void/void_test.rb +57 -0
- data/test/cardconnect_test.rb +14 -0
- data/test/test_helper.rb +33 -0
- metadata +179 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module CardConnect
|
5
|
+
class Connection
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@config = CardConnect.configuration
|
9
|
+
@headers = {user_agent: "CardConnectRubyGem/#{CardConnect::VERSION}"}
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection
|
13
|
+
@connection ||= Faraday.new(url: @config.endpoint, headers: @headers, ssl: {verify: false}) do |faraday|
|
14
|
+
faraday.request :basic_auth, @config.api_username, @config.api_password
|
15
|
+
faraday.request :json
|
16
|
+
|
17
|
+
faraday.response :json, :content_type => /\bjson$/
|
18
|
+
faraday.response :raise_error
|
19
|
+
|
20
|
+
faraday.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def ping_server
|
25
|
+
begin
|
26
|
+
connection.get('/cardconnect/rest/')
|
27
|
+
rescue Faraday::ResourceNotFound => e
|
28
|
+
return e
|
29
|
+
rescue Faraday::ClientError => e
|
30
|
+
return e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class Authorization < ServiceEndpoint
|
4
|
+
|
5
|
+
# Initializes an Authorization Service
|
6
|
+
#
|
7
|
+
# @param connection [CardConnect::Connection]
|
8
|
+
# @return CardConnect::Service::Authorization
|
9
|
+
def initialize(connection = CardConnect.connection)
|
10
|
+
super(connection)
|
11
|
+
@resource_name = '/auth'
|
12
|
+
@rest_method = 'put'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class AuthorizationRequest
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
REQUIRED_FIELDS = [:merchid, :account, :expiry, :amount, :currency]
|
7
|
+
|
8
|
+
OPTIONAL_FIELDS = [:accttype, :name, :address, :city, :region, :country, :phone,
|
9
|
+
:postal, :email, :ecomind, :cvv2, :orderid, :track, :bankaba,
|
10
|
+
:tokenize, :termid, :capture, :ssnl4, :license, :profile, :userfields]
|
11
|
+
|
12
|
+
FIELDS = REQUIRED_FIELDS + OPTIONAL_FIELDS
|
13
|
+
|
14
|
+
attr_accessor *FIELDS
|
15
|
+
attr_reader :errors
|
16
|
+
|
17
|
+
# Initializes a new Authorization Request
|
18
|
+
#
|
19
|
+
# @param attrs [Hash]
|
20
|
+
# @return CardConnect::AuthorizationRequest
|
21
|
+
def initialize(attrs = {})
|
22
|
+
@errors = []
|
23
|
+
set_attributes(attrs, FIELDS)
|
24
|
+
validate_required_fields
|
25
|
+
end
|
26
|
+
|
27
|
+
# Indicates that the request is valid once it is built.
|
28
|
+
def valid?
|
29
|
+
errors.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
# Builds the request payload
|
33
|
+
def payload
|
34
|
+
payload = {}
|
35
|
+
FIELDS.each do |field|
|
36
|
+
payload.merge!({field => send(field)})
|
37
|
+
end
|
38
|
+
payload
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def validate_required_fields
|
44
|
+
REQUIRED_FIELDS.each do |field|
|
45
|
+
value = send(field)
|
46
|
+
value.nil? || value.empty? ? errors.push("#{field.capitalize} is missing") : next
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class AuthorizationResponse
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
FIELDS = [:respstat, :retref, :account, :token, :amount, :merchid, :respcode,
|
7
|
+
:resptext, :respproc, :avsresp, :cvvresp, :authcode, :commcard]
|
8
|
+
|
9
|
+
attr_accessor *FIELDS
|
10
|
+
attr_reader :errors
|
11
|
+
|
12
|
+
STATUS_APPROVED = 'A'
|
13
|
+
STATUS_RETRY = 'B'
|
14
|
+
STATUS_DECLINED = 'C'
|
15
|
+
|
16
|
+
def initialize(response)
|
17
|
+
set_attributes(response, FIELDS)
|
18
|
+
@errors = []
|
19
|
+
process_errors
|
20
|
+
end
|
21
|
+
|
22
|
+
def success?
|
23
|
+
errors.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def body
|
27
|
+
body = {}
|
28
|
+
FIELDS.each do |attr|
|
29
|
+
body.merge!({attr => send(attr)})
|
30
|
+
end
|
31
|
+
body
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def process_errors
|
37
|
+
@errors << resptext if [STATUS_RETRY, STATUS_DECLINED].include?(respstat)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class Capture < ServiceEndpoint
|
4
|
+
|
5
|
+
# Initializes a Capture Service
|
6
|
+
#
|
7
|
+
# @param connection [CardConnect::Connection]
|
8
|
+
# @return CardConnect::Service::Capture
|
9
|
+
def initialize(connection = CardConnect.connection)
|
10
|
+
super(connection)
|
11
|
+
@resource_name = '/capture'
|
12
|
+
@rest_method = 'put'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class CaptureRequest
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
REQUIRED_FIELDS = [:merchid, :retref]
|
7
|
+
|
8
|
+
OPTIONAL_FIELDS = [:authcode, :amount, :invoiceid, :ponumber, :taxamnt]
|
9
|
+
|
10
|
+
FIELDS = REQUIRED_FIELDS + OPTIONAL_FIELDS
|
11
|
+
|
12
|
+
attr_accessor *FIELDS
|
13
|
+
attr_reader :errors
|
14
|
+
|
15
|
+
# Initializes a new Capture Request
|
16
|
+
#
|
17
|
+
# @param attrs [Hash]
|
18
|
+
# @return CardConnect::CaptureRequest
|
19
|
+
def initialize(attrs = {})
|
20
|
+
@errors = []
|
21
|
+
set_attributes(attrs, FIELDS)
|
22
|
+
validate_required_fields
|
23
|
+
end
|
24
|
+
|
25
|
+
# Indicates that the request is valid once it is built.
|
26
|
+
def valid?
|
27
|
+
errors.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Builds the request payload
|
31
|
+
def payload
|
32
|
+
payload = {}
|
33
|
+
FIELDS.each do |field|
|
34
|
+
payload.merge!({field => send(field)})
|
35
|
+
end
|
36
|
+
payload
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def validate_required_fields
|
42
|
+
REQUIRED_FIELDS.each do |field|
|
43
|
+
value = send(field)
|
44
|
+
value.nil? || value.empty? ? errors.push("#{field.capitalize} is missing") : next
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class CaptureResponse
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
FIELDS = [:merchid, :account, :amount, :retref, :setlstat]
|
7
|
+
|
8
|
+
attr_accessor *FIELDS
|
9
|
+
|
10
|
+
def initialize(response)
|
11
|
+
set_attributes(response, FIELDS)
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
body = {}
|
16
|
+
FIELDS.each do |attr|
|
17
|
+
body.merge!({attr => send(attr)})
|
18
|
+
end
|
19
|
+
body
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class Deposit < ServiceEndpoint
|
4
|
+
|
5
|
+
# Initializes a Deposit Service
|
6
|
+
#
|
7
|
+
# @param connection [CardConnect::Connection]
|
8
|
+
# @return CardConnect::Service::Deposit
|
9
|
+
def initialize(connection = CardConnect.connection)
|
10
|
+
super(connection)
|
11
|
+
@resource_name = '/deposit'
|
12
|
+
@rest_method = 'get'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module CardConnect
|
4
|
+
module Service
|
5
|
+
class DepositRequest
|
6
|
+
include Utils
|
7
|
+
|
8
|
+
REQUIRED_FIELDS = [:merchid, :date]
|
9
|
+
|
10
|
+
FIELDS = REQUIRED_FIELDS
|
11
|
+
|
12
|
+
attr_accessor *FIELDS
|
13
|
+
attr_reader :errors
|
14
|
+
|
15
|
+
# Initializes a new Deposit Request
|
16
|
+
#
|
17
|
+
# @param attrs [Hash]
|
18
|
+
# @return CardConnect::DepositRequest
|
19
|
+
def initialize(attrs = {})
|
20
|
+
@errors = []
|
21
|
+
set_attributes(attrs, FIELDS)
|
22
|
+
validate_required_fields
|
23
|
+
end
|
24
|
+
|
25
|
+
# Indicates that the request is valid once it is built.
|
26
|
+
def valid?
|
27
|
+
errors.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
# Builds the request payload
|
31
|
+
def payload
|
32
|
+
payload = "?"
|
33
|
+
FIELDS.each do |field|
|
34
|
+
payload += "#{field}=#{send(field)}&"
|
35
|
+
end
|
36
|
+
payload
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def validate_required_fields
|
42
|
+
validate_presence_of_required_fields
|
43
|
+
validate_date_format unless date.nil? || date.empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_presence_of_required_fields
|
47
|
+
REQUIRED_FIELDS.each do |field|
|
48
|
+
value = send(field)
|
49
|
+
value.nil? || value.empty? ? errors.push("#{field.capitalize} is missing") : next
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_date_format
|
54
|
+
begin
|
55
|
+
raise if date.length != 4
|
56
|
+
Date.parse(date, '%m%d')
|
57
|
+
rescue => e
|
58
|
+
errors.push("Date format is invalid. Please use MMDD format")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class DepositResponse
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
FIELDS = [:depositid, :merchid, :respproc, :accttype, :action, :actdate,
|
7
|
+
:postdate, :currency, :amount, :feeamnt, :cbakamnt, :resptext, :txns]
|
8
|
+
|
9
|
+
attr_accessor *FIELDS
|
10
|
+
attr_reader :errors
|
11
|
+
|
12
|
+
def initialize(response)
|
13
|
+
response = response.empty? ? response : response.first
|
14
|
+
set_attributes(response, FIELDS)
|
15
|
+
parse_transactions
|
16
|
+
@errors = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
errors.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def body
|
24
|
+
body = {}
|
25
|
+
FIELDS.each do |attr|
|
26
|
+
body.merge!({attr => send(attr)})
|
27
|
+
end
|
28
|
+
body
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse_transactions
|
34
|
+
return if txns.nil?
|
35
|
+
txns.each_with_index { |txn, i| self.txns[i] = symbolize_keys(txn) }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class Inquire < ServiceEndpoint
|
4
|
+
|
5
|
+
# Initializes a Inquire Service
|
6
|
+
#
|
7
|
+
# @param connection [CardConnect::Connection]
|
8
|
+
# @return CardConnect::Service::Inquire
|
9
|
+
def initialize(connection = CardConnect.connection)
|
10
|
+
super(connection)
|
11
|
+
@resource_name = '/inquire'
|
12
|
+
@rest_method = 'get'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CardConnect
|
2
|
+
module Service
|
3
|
+
class InquireRequest
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
REQUIRED_FIELDS = [:merchid, :retref]
|
7
|
+
|
8
|
+
FIELDS = REQUIRED_FIELDS
|
9
|
+
|
10
|
+
attr_accessor *FIELDS
|
11
|
+
attr_reader :errors
|
12
|
+
|
13
|
+
# Initializes a new Inquire Request
|
14
|
+
#
|
15
|
+
# @param attrs [Hash]
|
16
|
+
# @return CardConnect::InquireRequest
|
17
|
+
def initialize(attrs = {})
|
18
|
+
@errors = []
|
19
|
+
set_attributes(attrs, FIELDS)
|
20
|
+
validate_required_fields
|
21
|
+
end
|
22
|
+
|
23
|
+
# Indicates that the request is valid once it is built.
|
24
|
+
def valid?
|
25
|
+
errors.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
# Builds the request payload
|
29
|
+
def payload
|
30
|
+
"/#{retref}/#{merchid}"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate_required_fields
|
36
|
+
REQUIRED_FIELDS.each do |field|
|
37
|
+
value = send(field)
|
38
|
+
value.nil? || value.empty? ? errors.push("#{field.capitalize} is missing") : next
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|