bckbn 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/.irbrc +80 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +16 -0
- data/lib/bckbn/configuration.rb +24 -0
- data/lib/bckbn/connection.rb +71 -0
- data/lib/bckbn/core_ext.rb +19 -0
- data/lib/bckbn/resources/transaction/api.rb +65 -0
- data/lib/bckbn/resources/transaction/models/billing_address.rb +14 -0
- data/lib/bckbn/resources/transaction/models/card.rb +12 -0
- data/lib/bckbn/resources/transaction/models/cardholder_authentication.rb +14 -0
- data/lib/bckbn/resources/transaction/models/echeck.rb +12 -0
- data/lib/bckbn/resources/transaction/models/requests.rb +65 -0
- data/lib/bckbn/resources/transaction/models/responses.rb +73 -0
- data/lib/bckbn/version.rb +5 -0
- data/lib/bckbn.rb +33 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6329153faf6fb7c70ca05e66e1075e5290381ff2384f1bc0744d59b588f884ae
|
4
|
+
data.tar.gz: 9984bcb30241140e80e9bdd67955b5f98ca8c19e0e575f96d2dc38c5dfb6c2b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 330ee747a1bed11fad12cb44ddd2547da06926ef3d83752735ed3fdd4cb196a05d7cdf01e285ef6946e43969cc364f14f33a655b9f8963509f5cd773d7acd8a3
|
7
|
+
data.tar.gz: 2c1821d1217cdcd6ce676cca269c359852c2534dc00e609e2302104b13ad24905470910f8f86c954c0b4c68163a05c980828707aa60cb84750c7dbeb90c5fa56
|
data/.irbrc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Bckbn.api_base = "http://localhost:8080"
|
4
|
+
Bckbn.access_token = "foobar"
|
5
|
+
Bckbn.merchant_id = "101"
|
6
|
+
|
7
|
+
module Seeds
|
8
|
+
AUTH = {
|
9
|
+
amount: 5000,
|
10
|
+
bill_to_address: {
|
11
|
+
name: "John Doe",
|
12
|
+
address_line_1: "123 Main St",
|
13
|
+
city: "Boston",
|
14
|
+
state: "MA",
|
15
|
+
country: "US",
|
16
|
+
zip: "12345",
|
17
|
+
email: "jsmith@someaddress.com",
|
18
|
+
phone: "555-123-4567"
|
19
|
+
},
|
20
|
+
card: {
|
21
|
+
type: "MC",
|
22
|
+
number: "{{1234567890123456}}",
|
23
|
+
exp_date: "1223"
|
24
|
+
},
|
25
|
+
id: "12345",
|
26
|
+
order_id: "5234234",
|
27
|
+
order_source: "ecommerce",
|
28
|
+
partial: false,
|
29
|
+
report_group: "ABC Division"
|
30
|
+
}.freeze
|
31
|
+
|
32
|
+
SALE = {
|
33
|
+
id: "12345",
|
34
|
+
report_group: "ABC Division",
|
35
|
+
amount: 5000,
|
36
|
+
"card": {
|
37
|
+
"type": "VI",
|
38
|
+
"number": "{{1234567890123456}}",
|
39
|
+
"exp_date": "1223",
|
40
|
+
"card_validation_num": "123"
|
41
|
+
},
|
42
|
+
"bill_to_address": {
|
43
|
+
"name": "John Doe",
|
44
|
+
"address_line_1": "123 Main St",
|
45
|
+
"city": "Boston",
|
46
|
+
"state": "MA",
|
47
|
+
"country": "US",
|
48
|
+
"zip": "12345",
|
49
|
+
"email": "jsmith@someaddress.com",
|
50
|
+
"phone": "555-123-4567"
|
51
|
+
},
|
52
|
+
partial: false,
|
53
|
+
order_id: "5234234",
|
54
|
+
order_source: "ecommerce"
|
55
|
+
}.freeze
|
56
|
+
|
57
|
+
ECHECK_SALE = {
|
58
|
+
"echeck": {
|
59
|
+
"acc_type": "Checking",
|
60
|
+
"acc_num": "5186005800001012",
|
61
|
+
"routing_num": "000010101",
|
62
|
+
"check_num": nil
|
63
|
+
},
|
64
|
+
"bill_to_address": {
|
65
|
+
"name": "John Doe",
|
66
|
+
"address_line_1": "123 Main St",
|
67
|
+
"city": "Boston",
|
68
|
+
"state": "MA",
|
69
|
+
"country": "US",
|
70
|
+
"zip": "12345",
|
71
|
+
"email": "jsmith@someaddress.com",
|
72
|
+
"phone": "555-123-4567"
|
73
|
+
},
|
74
|
+
"amount": 5000,
|
75
|
+
"id": "12345",
|
76
|
+
"report_group": "ABC Division",
|
77
|
+
"order_id": "5234234",
|
78
|
+
"order_source": "ecommerce"
|
79
|
+
}.freeze
|
80
|
+
end
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Metrics:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Naming/VariableNumber:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bckbn (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.8.5)
|
10
|
+
public_suffix (>= 2.0.2, < 6.0)
|
11
|
+
ast (2.4.2)
|
12
|
+
base64 (0.1.1)
|
13
|
+
coderay (1.1.3)
|
14
|
+
concurrent-ruby (1.2.2)
|
15
|
+
crack (0.4.5)
|
16
|
+
rexml
|
17
|
+
diff-lcs (1.5.0)
|
18
|
+
faker (3.2.1)
|
19
|
+
i18n (>= 1.8.11, < 2)
|
20
|
+
hashdiff (1.0.1)
|
21
|
+
i18n (1.14.1)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
json (2.6.3)
|
24
|
+
language_server-protocol (3.17.0.3)
|
25
|
+
method_source (1.0.0)
|
26
|
+
parallel (1.23.0)
|
27
|
+
parser (3.2.2.3)
|
28
|
+
ast (~> 2.4.1)
|
29
|
+
racc
|
30
|
+
pry (0.14.2)
|
31
|
+
coderay (~> 1.1)
|
32
|
+
method_source (~> 1.0)
|
33
|
+
public_suffix (5.0.3)
|
34
|
+
racc (1.7.1)
|
35
|
+
rainbow (3.1.1)
|
36
|
+
rake (13.0.6)
|
37
|
+
regexp_parser (2.8.1)
|
38
|
+
rexml (3.2.6)
|
39
|
+
rspec (3.12.0)
|
40
|
+
rspec-core (~> 3.12.0)
|
41
|
+
rspec-expectations (~> 3.12.0)
|
42
|
+
rspec-mocks (~> 3.12.0)
|
43
|
+
rspec-core (3.12.2)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-expectations (3.12.3)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-mocks (3.12.6)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-support (3.12.1)
|
52
|
+
rubocop (1.56.2)
|
53
|
+
base64 (~> 0.1.1)
|
54
|
+
json (~> 2.3)
|
55
|
+
language_server-protocol (>= 3.17.0)
|
56
|
+
parallel (~> 1.10)
|
57
|
+
parser (>= 3.2.2.3)
|
58
|
+
rainbow (>= 2.2.2, < 4.0)
|
59
|
+
regexp_parser (>= 1.8, < 3.0)
|
60
|
+
rexml (>= 3.2.5, < 4.0)
|
61
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
62
|
+
ruby-progressbar (~> 1.7)
|
63
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
64
|
+
rubocop-ast (1.29.0)
|
65
|
+
parser (>= 3.2.1.0)
|
66
|
+
ruby-progressbar (1.13.0)
|
67
|
+
unicode-display_width (2.4.2)
|
68
|
+
webmock (3.19.1)
|
69
|
+
addressable (>= 2.8.0)
|
70
|
+
crack (>= 0.3.2)
|
71
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
72
|
+
yard (0.9.34)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
arm64-darwin-22
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
bckbn!
|
79
|
+
faker
|
80
|
+
pry
|
81
|
+
rake (~> 13.0)
|
82
|
+
rspec (~> 3.0)
|
83
|
+
rubocop (~> 1.21)
|
84
|
+
webmock
|
85
|
+
yard
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
2.4.13
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Bckbn
|
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,77 @@
|
|
1
|
+
# bckbn-ruby
|
2
|
+
|
3
|
+
> Ruby interface to the Bckbn API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install bckbn
|
9
|
+
```
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
### Global
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require "bckbn"
|
17
|
+
|
18
|
+
Bckbn.api_base = "..."
|
19
|
+
Bckbn.access_token = "..."
|
20
|
+
Bckbn.merchant_id = "..."
|
21
|
+
|
22
|
+
Bckbn::Transaction.capture({
|
23
|
+
litle_txn_id: "13254123434",
|
24
|
+
id: "12345",
|
25
|
+
report_group: "ABC Division"
|
26
|
+
})
|
27
|
+
```
|
28
|
+
|
29
|
+
### Per Request
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require "bckbn"
|
33
|
+
|
34
|
+
api_base = "..."
|
35
|
+
access_token = "..."
|
36
|
+
merchant_id = "..."
|
37
|
+
|
38
|
+
Bckbn::Transaction.capture(
|
39
|
+
{
|
40
|
+
litle_txn_id: "13254123434",
|
41
|
+
id: "12345",
|
42
|
+
report_group: "ABC Division"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
api_base:,
|
46
|
+
access_token:,
|
47
|
+
merchant_id:
|
48
|
+
}
|
49
|
+
)
|
50
|
+
```
|
51
|
+
|
52
|
+
## Documentation
|
53
|
+
|
54
|
+
```
|
55
|
+
open doc/index.html
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
Run specs
|
61
|
+
```bash
|
62
|
+
bundle exec rake spec
|
63
|
+
```
|
64
|
+
|
65
|
+
Regenerate docs
|
66
|
+
```bash
|
67
|
+
bundle exec rake yard
|
68
|
+
```
|
69
|
+
|
70
|
+
Run linter
|
71
|
+
```bash
|
72
|
+
bundle exec rake rubocop
|
73
|
+
```
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
require "yard"
|
10
|
+
|
11
|
+
RuboCop::RakeTask.new
|
12
|
+
YARD::Rake::YardocTask.new do |t|
|
13
|
+
t.files = ["lib/**/*.rb"]
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: %i[spec yard rubocop]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
API_VERSION = "0.1.0"
|
5
|
+
CONFIG_OPTIONS = %i[
|
6
|
+
access_token
|
7
|
+
api_version
|
8
|
+
api_base
|
9
|
+
log_level
|
10
|
+
merchant_id
|
11
|
+
source_ip_address
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
Configuration = Struct.new(*CONFIG_OPTIONS, keyword_init: true) do
|
15
|
+
def self.setup
|
16
|
+
new
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(**opts)
|
20
|
+
opts[:api_version] ||= API_VERSION
|
21
|
+
super(**opts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
class Connection
|
5
|
+
using Bckbn::CoreExt::StringExt
|
6
|
+
|
7
|
+
HttpBadRequest = Class.new(StandardError)
|
8
|
+
HttpInternalServerError = Class.new(StandardError)
|
9
|
+
HttpServiceUnavailable = Class.new(StandardError)
|
10
|
+
|
11
|
+
ERRORS = {
|
12
|
+
Net::HTTPBadRequest => HttpBadRequest,
|
13
|
+
Net::HTTPInternalServerError => HttpInternalServerError,
|
14
|
+
Net::HTTPServiceUnavailable => HttpServiceUnavailable
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize(config)
|
18
|
+
@config = config.empty? ? Bckbn.config : Bckbn::Configuration.new(**config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post_to_api(path, body, klass)
|
22
|
+
headers = {
|
23
|
+
"Content-Type" => "application/json",
|
24
|
+
"Authorization" => "Bearer #{config.access_token}",
|
25
|
+
"X-Api-Version" => config.api_version,
|
26
|
+
"X-Merchant-Id" => config.merchant_id,
|
27
|
+
"X-Source-Ip-Address" => config.source_ip_address
|
28
|
+
}
|
29
|
+
|
30
|
+
url = URI.parse(config.api_base + path)
|
31
|
+
request = Net::HTTP::Post.new(url.path)
|
32
|
+
headers.reject! { |_, v| v.nil? || v == "" }
|
33
|
+
headers.each { |k, v| request[k] = v }
|
34
|
+
request.body = body.to_json
|
35
|
+
|
36
|
+
response_handler(url, request) do |response, rbody|
|
37
|
+
case response
|
38
|
+
when Net::HTTPSuccess
|
39
|
+
data = rbody.dig("data", klass.name.split("::").last.underscore)
|
40
|
+
klass.new(data)
|
41
|
+
else
|
42
|
+
raise ERRORS[response.class], rbody ? rbody["errors"] : nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_reader :config
|
50
|
+
|
51
|
+
def response_handler(url, request)
|
52
|
+
http = Net::HTTP.new(url.host, url.port)
|
53
|
+
# http.use_ssl = true
|
54
|
+
|
55
|
+
response, body = begin
|
56
|
+
r = http.request(request)
|
57
|
+
[r, JSON.parse(r.body)]
|
58
|
+
rescue Errno::ECONNREFUSED => e
|
59
|
+
[Net::HTTPServiceUnavailable.new("1.1", "503", e.message), nil]
|
60
|
+
end
|
61
|
+
|
62
|
+
resp_obj = yield response, body
|
63
|
+
|
64
|
+
resp_obj.tap do |ro|
|
65
|
+
if ro.respond_to?(:fraud_result) && resp_obj.fraud_result
|
66
|
+
ro.fraud_result = ::Bckbn::Transaction::FraudResult.new(**resp_obj.fraud_result)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module CoreExt
|
5
|
+
module StringExt
|
6
|
+
refine String do
|
7
|
+
def underscore
|
8
|
+
copy = dup
|
9
|
+
copy.gsub("::", "/")
|
10
|
+
copy.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
|
11
|
+
(::Regexp.last_match(1) || ::Regexp.last_match(2)) << "_"
|
12
|
+
end
|
13
|
+
copy.tr!("-", "_")
|
14
|
+
copy.downcase!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
ENDPOINTS = {
|
6
|
+
authorization: "/transactions/authorization",
|
7
|
+
capture: "/transactions/capture",
|
8
|
+
credit: "/transactions/credit",
|
9
|
+
sale: "/transactions/sale",
|
10
|
+
void: "/transactions/void",
|
11
|
+
echeck_credit: "/transactions/echeck_credit",
|
12
|
+
echeck_sale: "/transactions/echeck_sale",
|
13
|
+
echeck_void: "/transactions/echeck_void"
|
14
|
+
}.freeze
|
15
|
+
private_constant :ENDPOINTS
|
16
|
+
|
17
|
+
def self.authorization(body, config = {})
|
18
|
+
body = AuthorizationRequest.new(body)
|
19
|
+
@conn = Bckbn::Connection.new(config)
|
20
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, AuthorizationResponse)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.capture(body, config = {})
|
24
|
+
body = CaptureRequest.new(body)
|
25
|
+
@conn = Bckbn::Connection.new(config)
|
26
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, CaptureResponse)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.credit(body, config = {})
|
30
|
+
body = CreditRequest.new(body)
|
31
|
+
@conn = Bckbn::Connection.new(config)
|
32
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, CreditResponse)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.sale(body, config = {})
|
36
|
+
body = SaleRequest.new(body)
|
37
|
+
@conn = Bckbn::Connection.new(config)
|
38
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, SaleResponse)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.void(body, config = {})
|
42
|
+
body = VoidRequest.new(body)
|
43
|
+
@conn = Bckbn::Connection.new(config)
|
44
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, VoidResponse)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.echeck_credit(body, config = {})
|
48
|
+
body = EcheckCreditRequest.new(body)
|
49
|
+
@conn = Bckbn::Connection.new(config)
|
50
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, EcheckCreditResponse)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.echeck_sale(body, config = {})
|
54
|
+
body = EcheckSaleRequest.new(body)
|
55
|
+
@conn = Bckbn::Connection.new(config)
|
56
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, EcheckSaleResponse)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.echeck_void(body, config = {})
|
60
|
+
body = EcheckVoidRequest.new(body)
|
61
|
+
@conn = Bckbn::Connection.new(config)
|
62
|
+
@conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, EcheckVoidResponse)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
BillingAddress = Struct.new(
|
6
|
+
*%i[name address_line_1 city state country zip email phone], keyword_init: true
|
7
|
+
) do
|
8
|
+
def initialize(opts)
|
9
|
+
valid_opts = opts.slice(*members)
|
10
|
+
valid_opts.each { |key, value| public_send("#{key}=", value) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
Card = Struct.new(*%i[type number exp_date card_validation_num], keyword_init: true) do
|
6
|
+
def initialize(opts)
|
7
|
+
valid_opts = opts.slice(*members)
|
8
|
+
valid_opts.each { |key, value| public_send("#{key}=", value) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
CardholderAuthentication = Struct.new(
|
6
|
+
*%i[authentication_value], keyword_init: true
|
7
|
+
) do
|
8
|
+
def initialize(opts)
|
9
|
+
valid_opts = opts.slice(*members)
|
10
|
+
valid_opts.each { |key, value| public_send("#{key}=", value) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
Echeck = Struct.new(*%i[acc_type acc_num routing_num check_num], keyword_init: true) do
|
6
|
+
def initialize(opts)
|
7
|
+
valid_opts = opts.slice(*members)
|
8
|
+
valid_opts.each { |key, value| public_send("#{key}=", value) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
REQUEST_BASE = %i[
|
6
|
+
id
|
7
|
+
report_group
|
8
|
+
].freeze
|
9
|
+
|
10
|
+
AUTHORIZATION_REQUEST_MEMBERS = [
|
11
|
+
*REQUEST_BASE,
|
12
|
+
:amount,
|
13
|
+
:bill_to_address,
|
14
|
+
:cardholder_authentication,
|
15
|
+
:card,
|
16
|
+
:order_id,
|
17
|
+
:order_source,
|
18
|
+
:partial
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
ECHECK_SALE_REQUEST_MEMBERS = [
|
22
|
+
*REQUEST_BASE,
|
23
|
+
:amount,
|
24
|
+
:bill_to_address,
|
25
|
+
:echeck,
|
26
|
+
:order_id,
|
27
|
+
:order_source
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
CAPTURE_REQUEST_MEMBERS = [*REQUEST_BASE, :litle_txn_id, :partial].freeze
|
31
|
+
VOID_REQUEST_MEMBERS = [*REQUEST_BASE, :litle_txn_id].freeze
|
32
|
+
CREDIT_REQUEST_MEMBERS = [*REQUEST_BASE, :litle_txn_id, :amount].freeze
|
33
|
+
|
34
|
+
module RequestShared
|
35
|
+
def initialize(opts)
|
36
|
+
valid_opts = opts.slice(*members)
|
37
|
+
valid_opts.each { |key, value| public_send("#{key}=", value) }
|
38
|
+
end
|
39
|
+
|
40
|
+
# use to_h for any necessary key formatting
|
41
|
+
def to_h
|
42
|
+
h = super
|
43
|
+
h.delete(:cardholder_authentication) if h[:cardholder_authentication].nil?
|
44
|
+
h
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
AuthorizationRequest = Struct.new(*AUTHORIZATION_REQUEST_MEMBERS, keyword_init: true)
|
49
|
+
SaleRequest = Struct.new(*AUTHORIZATION_REQUEST_MEMBERS, keyword_init: true)
|
50
|
+
CaptureRequest = Struct.new(*CAPTURE_REQUEST_MEMBERS, keyword_init: true)
|
51
|
+
CreditRequest = Struct.new(*CREDIT_REQUEST_MEMBERS, keyword_init: true)
|
52
|
+
EcheckCreditRequest = Struct.new(*CREDIT_REQUEST_MEMBERS, keyword_init: true)
|
53
|
+
VoidRequest = Struct.new(*VOID_REQUEST_MEMBERS, keyword_init: true)
|
54
|
+
EcheckVoidRequest = Struct.new(*VOID_REQUEST_MEMBERS, keyword_init: true)
|
55
|
+
EcheckSaleRequest = Struct.new(*ECHECK_SALE_REQUEST_MEMBERS, keyword_init: true)
|
56
|
+
[
|
57
|
+
AuthorizationRequest,
|
58
|
+
CaptureRequest,
|
59
|
+
CreditRequest,
|
60
|
+
EcheckSaleRequest,
|
61
|
+
SaleRequest,
|
62
|
+
VoidRequest
|
63
|
+
].each { |rc| rc.send(:include, RequestShared) }
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bckbn
|
4
|
+
module Transaction
|
5
|
+
using Bckbn::CoreExt::StringExt
|
6
|
+
|
7
|
+
RESPONSE_BASE = %i[
|
8
|
+
customer_id
|
9
|
+
id
|
10
|
+
litle_txn_id
|
11
|
+
message
|
12
|
+
post_date
|
13
|
+
report_group
|
14
|
+
response
|
15
|
+
response_time
|
16
|
+
account_updater
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
AUTHORIZATION_RESPONSE_MEMBERS = [
|
20
|
+
*RESPONSE_BASE,
|
21
|
+
:approved_amount,
|
22
|
+
:auth_code,
|
23
|
+
:network_transaction_id,
|
24
|
+
:order_id,
|
25
|
+
:fraud_result
|
26
|
+
].freeze
|
27
|
+
|
28
|
+
SALE_RESPONSE_MEMBERS = [
|
29
|
+
*RESPONSE_BASE,
|
30
|
+
:auth_code,
|
31
|
+
:network_transaction_id,
|
32
|
+
:order_id,
|
33
|
+
:fraud_result
|
34
|
+
].freeze
|
35
|
+
private_constant :RESPONSE_BASE,
|
36
|
+
:AUTHORIZATION_RESPONSE_MEMBERS,
|
37
|
+
:SALE_RESPONSE_MEMBERS
|
38
|
+
|
39
|
+
AuthorizationResponse = Struct.new(*AUTHORIZATION_RESPONSE_MEMBERS, keyword_init: true)
|
40
|
+
SaleResponse = Struct.new(*SALE_RESPONSE_MEMBERS, keyword_init: true)
|
41
|
+
|
42
|
+
%w[
|
43
|
+
CaptureResponse
|
44
|
+
CreditResponse
|
45
|
+
EcheckCreditResponse
|
46
|
+
EcheckVoidResponse
|
47
|
+
EcheckSaleResponse
|
48
|
+
VoidResponse
|
49
|
+
].each do |response|
|
50
|
+
Bckbn::Transaction.const_set(response, Struct.new(*RESPONSE_BASE, keyword_init: true))
|
51
|
+
end
|
52
|
+
|
53
|
+
module ResponseShared
|
54
|
+
def type
|
55
|
+
self.class.name.split("::").last =~ /(.*)Response/
|
56
|
+
::Regexp.last_match(1).underscore.downcase
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
[
|
61
|
+
AuthorizationResponse,
|
62
|
+
SaleResponse,
|
63
|
+
CaptureResponse,
|
64
|
+
CreditResponse,
|
65
|
+
EcheckCreditResponse,
|
66
|
+
EcheckVoidResponse,
|
67
|
+
EcheckSaleResponse,
|
68
|
+
VoidResponse
|
69
|
+
].each { |rc| rc.send(:include, ResponseShared) }
|
70
|
+
|
71
|
+
FraudResult = Struct.new(:avs_result, :card_validation_result, :authentication_result, keyword_init: true)
|
72
|
+
end
|
73
|
+
end
|
data/lib/bckbn.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "forwardable"
|
5
|
+
require "logger"
|
6
|
+
require "net/http"
|
7
|
+
require "bckbn/version"
|
8
|
+
require "bckbn/configuration"
|
9
|
+
require "bckbn/core_ext"
|
10
|
+
require "bckbn/connection"
|
11
|
+
require "bckbn/resources/transaction/api"
|
12
|
+
require "bckbn/resources/transaction/models/card"
|
13
|
+
require "bckbn/resources/transaction/models/echeck"
|
14
|
+
require "bckbn/resources/transaction/models/billing_address"
|
15
|
+
require "bckbn/resources/transaction/models/requests"
|
16
|
+
require "bckbn/resources/transaction/models/responses"
|
17
|
+
|
18
|
+
module Bckbn
|
19
|
+
@config = Bckbn::Configuration.setup
|
20
|
+
|
21
|
+
class << self
|
22
|
+
extend Forwardable
|
23
|
+
|
24
|
+
attr_reader :config
|
25
|
+
|
26
|
+
def_delegators :@config, :access_token, :access_token=
|
27
|
+
def_delegators :@config, :api_version, :api_version=
|
28
|
+
def_delegators :@config, :api_base, :api_base=
|
29
|
+
def_delegators :@config, :log_level, :log_level=
|
30
|
+
def_delegators :@config, :merchant_id, :merchant_id=
|
31
|
+
def_delegators :@config, :source_ip_address, :source_ip_address=
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bckbn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nikkypx
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faker
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby Bckbn client
|
84
|
+
email:
|
85
|
+
- npalaniuk+github@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".irbrc"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/bckbn.rb
|
100
|
+
- lib/bckbn/configuration.rb
|
101
|
+
- lib/bckbn/connection.rb
|
102
|
+
- lib/bckbn/core_ext.rb
|
103
|
+
- lib/bckbn/resources/transaction/api.rb
|
104
|
+
- lib/bckbn/resources/transaction/models/billing_address.rb
|
105
|
+
- lib/bckbn/resources/transaction/models/card.rb
|
106
|
+
- lib/bckbn/resources/transaction/models/cardholder_authentication.rb
|
107
|
+
- lib/bckbn/resources/transaction/models/echeck.rb
|
108
|
+
- lib/bckbn/resources/transaction/models/requests.rb
|
109
|
+
- lib/bckbn/resources/transaction/models/responses.rb
|
110
|
+
- lib/bckbn/version.rb
|
111
|
+
homepage: https://github.com/anedot/bckbn-ruby
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata:
|
115
|
+
homepage_uri: https://github.com/anedot/bckbn-ruby
|
116
|
+
changelog_uri: https://github.com/bckbn/bckbn-ruby/changelog.md
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.7'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.4.19
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Ruby Bckbn client
|
136
|
+
test_files: []
|