cardknox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.template +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/lib/cardknox/agent.rb +32 -0
- data/lib/cardknox/api.rb +32 -0
- data/lib/cardknox/configuration.rb +10 -0
- data/lib/cardknox/error.rb +16 -0
- data/lib/cardknox/version.rb +5 -0
- data/lib/cardknox.rb +18 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c53c7db0e62bc7bd4799ff878f81554ed381dda6d9989a7054197d73028de198
|
4
|
+
data.tar.gz: ea882b0a1b4a94dd801d6a755907d4047d9017bbaf8010f0c89373a282d27634
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbdedf3526d79d36f7c0eea2e6473b6de996e93764bb38654995fb6972e8b2ca3503fc3c69d7e6e26037c861d2cb35d65430ad414037e22ca77f88c6fb04babe
|
7
|
+
data.tar.gz: a53cf4567ee92d3c840bcc7013e02fab89336fd67003c692956ab3957e55b404fe3bb1943bc7812f52d3ac7cd8a90bd5619c6e904dd8c23b10c78352a7dcdf14
|
data/.env.template
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
API_KEY=API_KEY
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
inherit_gem:
|
6
|
+
rubocop-shopify: rubocop.yml
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
NewCops: enable
|
10
|
+
TargetRubyVersion: 3.0
|
11
|
+
|
12
|
+
Gemspec/RequireMFA:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/StringLiterals:
|
19
|
+
EnforcedStyle: double_quotes
|
20
|
+
|
21
|
+
Style/StringLiteralsInInterpolation:
|
22
|
+
EnforcedStyle: double_quotes
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Algonauti
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Cardknox
|
2
|
+
|
3
|
+
A lightweight Ruby client for interacting with the Cardknox API, built using `faraday`. It provides an easy and minimal setup for handling payments and other operations via Cardknox.
|
4
|
+
|
5
|
+
![CI](https://github.com/algonauti/cardknox/actions/workflows/ci.yml/badge.svg)
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'cardknox'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
api = Cardknox::API::Client.new('your_api_key') do |config|
|
21
|
+
config.gateway_version = "5.0.0"
|
22
|
+
config.software_name = "CardKnox Ruby client"
|
23
|
+
config.software_version = Cardknox::VERSION
|
24
|
+
end
|
25
|
+
|
26
|
+
response = api.transaction("cc:Sale", {
|
27
|
+
xCardNum: "4111111111111111",
|
28
|
+
xExp: "1225",
|
29
|
+
xAmount: "999"
|
30
|
+
})
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/algonauti/cardknox.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cardknox
|
4
|
+
class Agent
|
5
|
+
def initialize(endpoint)
|
6
|
+
@conn = Faraday.new(endpoint) do |config|
|
7
|
+
config.response(:raise_error)
|
8
|
+
config.request(:json)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(path, params = {})
|
13
|
+
parse(@conn.get(path, params))
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(path, body = {})
|
17
|
+
parse(@conn.post(path, body))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse(response)
|
23
|
+
JSON.parse(response.body, symbolize_names: true).tap do |payload|
|
24
|
+
if payload[:xStatus] != "Approved"
|
25
|
+
raise Error::TransactionFailure.new(payload[:xError], response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rescue JSON::ParserError
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cardknox/api.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cardknox
|
4
|
+
module API
|
5
|
+
class Client
|
6
|
+
attr_reader :agent
|
7
|
+
attr_accessor :config
|
8
|
+
|
9
|
+
def initialize(key)
|
10
|
+
@agent = Agent.new(Cardknox::BASE_URL)
|
11
|
+
@config = Cardknox::Configuration.new.tap do |config|
|
12
|
+
config.api_key = key
|
13
|
+
end
|
14
|
+
yield(config) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def transaction(command, params = {})
|
18
|
+
@agent.post("/gatewayjson", params.merge({
|
19
|
+
xKey: config.api_key,
|
20
|
+
xVersion: config.gateway_version,
|
21
|
+
xSoftwareName: config.software_name,
|
22
|
+
xSoftwareVersion: config.software_version,
|
23
|
+
xCommand: command,
|
24
|
+
}))
|
25
|
+
end
|
26
|
+
|
27
|
+
def status
|
28
|
+
@agent.get("/status")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cardknox
|
4
|
+
class Error < StandardError
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
def initialize(exception = nil, response = nil)
|
8
|
+
@response = response
|
9
|
+
|
10
|
+
super(exception)
|
11
|
+
end
|
12
|
+
|
13
|
+
class TransactionFailure < self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/cardknox.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "zeitwerk"
|
5
|
+
require_relative "cardknox/version"
|
6
|
+
|
7
|
+
module Cardknox
|
8
|
+
BASE_URL = "https://x1.cardknox.com"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def loader
|
12
|
+
@loader ||= Zeitwerk::Loader.for_gem.tap do |loader|
|
13
|
+
loader.inflector.inflect("api" => "API")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
loader.setup
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cardknox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Algonauti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zeitwerk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
41
|
+
description: Provides a ruby interface to interact with the cardknow API
|
42
|
+
email:
|
43
|
+
- devel@algonauti.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".env.template"
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/cardknox.rb
|
55
|
+
- lib/cardknox/agent.rb
|
56
|
+
- lib/cardknox/api.rb
|
57
|
+
- lib/cardknox/configuration.rb
|
58
|
+
- lib/cardknox/error.rb
|
59
|
+
- lib/cardknox/version.rb
|
60
|
+
homepage: https://github.com/algonauti/cardknow
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.0.0
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.5.16
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: ruby client for easy integration with cardknow API.
|
83
|
+
test_files: []
|