bckbn 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a998e53954c06ebed88798f74e96ca31f07cc7101d0f6f2ef3977eeb993cbac5
4
- data.tar.gz: 4e1650c6ba365f4fcf3f09fec35755593e7ee0c780c433f17495a9d43bf6cc6b
3
+ metadata.gz: 17f59a2d0a76520c2ce364ef1bcfd8ca46e9a20f51026cb2613f9d66482ae278
4
+ data.tar.gz: 51458c020327baffec1803bb3dc0fe6b8e890c771a9dd4cd7d604940b26f0aed
5
5
  SHA512:
6
- metadata.gz: 8046e28f4a9793a33049f63964b87afe600cc6e9fcbae5252d99789f00dde42e7a57a3bdea96019a4478ca93d0a0788b1f7e48994394018511f6749db9c81bf9
7
- data.tar.gz: 5ceb54a6645ac7d44952b12bb5d5ca6c8d3cb385093666632a315d8d8a77f0370af8173634eb194030a1b45efd25e5a66c58781b90bbcff80c0610bdc639c790
6
+ metadata.gz: 63c67a32658b11f8b6f05cae841cf3feca56863a9528c158b29ec74e852f259f7fa0832112dbc0bdf611132d2207a7b9dcc8762ac972ab247194b1b4c5ac9dcd
7
+ data.tar.gz: f5fe4a59cd73013bef9277a4c3f5255a6a89e934fa25fe643d4f5747d8e310a06f1865ffcb80d71c97a8d7affdb4ec2fcb7b942197a22da581def1465063429d
data/.irbrc CHANGED
@@ -76,3 +76,66 @@ Bckbn.merchant_id = "101"
76
76
  "order_id": "5234234",
77
77
  "order_source": "ecommerce"
78
78
  }.freeze
79
+
80
+ @charge = {
81
+ amount: 500_000_000,
82
+ description: "JulyFees",
83
+ source: {
84
+ type: "bank",
85
+ bank: {
86
+ routing_number: "021200339",
87
+ account_number: "6546543213",
88
+ account_type: "Checking",
89
+ name: "Glenn Quagmire"
90
+ }
91
+ }
92
+ }
93
+
94
+ @payout = {
95
+ amount: 2500,
96
+ description: "JulyFees",
97
+ destination: {
98
+ type: "bank",
99
+ bank: {
100
+ routing_number: "021200339",
101
+ account_number: "6546543213",
102
+ account_type: "Checking",
103
+ name: "Glenn Quagmire"
104
+ }
105
+ }
106
+ }
107
+
108
+ # @originate_batch_body = {
109
+ # "payments": [{
110
+ # "account_number": "2654377916",
111
+ # "receiver": {
112
+ # "routing_number": "021200339",
113
+ # "account_number": "6546543213",
114
+ # "account_type": "Checking",
115
+ # "name": "Glenn Quagmire",
116
+ # "identification": "XYZ123"
117
+ # },
118
+ # "sec_code": "PPD",
119
+ # "description": "JulyFees",
120
+ # "transaction_type": "Push",
121
+ # "amount": 25_000,
122
+ # "purpose": "sample payment",
123
+ # "service_type": "Standard"
124
+ # },
125
+ # {
126
+ # "account_number": "2654377916",
127
+ # "receiver": {
128
+ # "routing_number": "021200339",
129
+ # "account_number": "6546543213",
130
+ # "account_type": "Checking",
131
+ # "name": "Pam Anderson",
132
+ # "identification": "ABCDEFG"
133
+ # },
134
+ # "sec_code": "PPD",
135
+ # "description": "JulyFees",
136
+ # "transaction_type": "Push",
137
+ # "amount": 33_333,
138
+ # "purpose": "sample payment",
139
+ # "service_type": "Standard"
140
+ # }]
141
+ # }
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.1
2
+
3
+ - Add first iteration of charge resource
4
+
1
5
  ## 0.2.0
2
6
 
3
7
  - Add support for `debug` and `error` log levels
data/Gemfile.lock CHANGED
@@ -1,40 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bckbn (2.0.0)
4
+ bckbn (2.1.1)
5
+ addressable (~> 2.8.5)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- addressable (2.8.5)
10
+ addressable (2.8.6)
10
11
  public_suffix (>= 2.0.2, < 6.0)
11
12
  ast (2.4.2)
12
- base64 (0.1.1)
13
13
  coderay (1.1.3)
14
14
  concurrent-ruby (1.2.2)
15
15
  crack (0.4.5)
16
16
  rexml
17
17
  diff-lcs (1.5.0)
18
- faker (3.2.1)
18
+ faker (3.2.2)
19
19
  i18n (>= 1.8.11, < 2)
20
- hashdiff (1.0.1)
20
+ hashdiff (1.1.0)
21
21
  i18n (1.14.1)
22
22
  concurrent-ruby (~> 1.0)
23
- json (2.6.3)
23
+ json (2.7.1)
24
24
  language_server-protocol (3.17.0.3)
25
25
  method_source (1.0.0)
26
- parallel (1.23.0)
27
- parser (3.2.2.4)
26
+ parallel (1.24.0)
27
+ parser (3.3.0.2)
28
28
  ast (~> 2.4.1)
29
29
  racc
30
30
  pry (0.14.2)
31
31
  coderay (~> 1.1)
32
32
  method_source (~> 1.0)
33
- public_suffix (5.0.3)
34
- racc (1.7.1)
33
+ public_suffix (5.0.4)
34
+ racc (1.7.3)
35
35
  rainbow (3.1.1)
36
- rake (13.0.6)
37
- regexp_parser (2.8.1)
36
+ rake (13.1.0)
37
+ regexp_parser (2.9.0)
38
38
  rexml (3.2.6)
39
39
  rspec (3.12.0)
40
40
  rspec-core (~> 3.12.0)
@@ -49,19 +49,18 @@ GEM
49
49
  diff-lcs (>= 1.2.0, < 2.0)
50
50
  rspec-support (~> 3.12.0)
51
51
  rspec-support (3.12.1)
52
- rubocop (1.56.4)
53
- base64 (~> 0.1.1)
52
+ rubocop (1.59.0)
54
53
  json (~> 2.3)
55
54
  language_server-protocol (>= 3.17.0)
56
55
  parallel (~> 1.10)
57
- parser (>= 3.2.2.3)
56
+ parser (>= 3.2.2.4)
58
57
  rainbow (>= 2.2.2, < 4.0)
59
58
  regexp_parser (>= 1.8, < 3.0)
60
59
  rexml (>= 3.2.5, < 4.0)
61
- rubocop-ast (>= 1.28.1, < 2.0)
60
+ rubocop-ast (>= 1.30.0, < 2.0)
62
61
  ruby-progressbar (~> 1.7)
63
62
  unicode-display_width (>= 2.4.0, < 3.0)
64
- rubocop-ast (1.29.0)
63
+ rubocop-ast (1.30.0)
65
64
  parser (>= 3.2.1.0)
66
65
  ruby-progressbar (1.13.0)
67
66
  unicode-display_width (2.5.0)
@@ -41,6 +41,31 @@ module Bckbn
41
41
  bckbn_headers.each { |k, v| request[k] = v }
42
42
  request.body = body.to_json
43
43
 
44
+ response_handler(url, request) do |response, rbody|
45
+ case response
46
+ when Net::HTTPSuccess
47
+ data = rbody.fetch("data")
48
+ log(:debug, "\nResponse: #{data.to_json}")
49
+ klass.new(**data, logs: @logs)
50
+ else
51
+ err_klass = ERRORS[response.class]
52
+ message = "Error: #{rbody ? rbody["errors"] : "Unknown"}"
53
+ log(:error, message)
54
+ err = err_klass.new(message, @logs)
55
+ raise err
56
+ end
57
+ end
58
+ end
59
+
60
+ def get_from_api(path, klass)
61
+ log(:debug, "GET #{path}\n")
62
+
63
+ url = URI.parse(config.api_base + path)
64
+ request = Net::HTTP::Get.new(url.path)
65
+ bckbn_headers = headers(config)
66
+ bckbn_headers.reject! { |_, v| v.nil? || v == "" }
67
+ bckbn_headers.each { |k, v| request[k] = v }
68
+
44
69
  response_handler(url, request) do |response, rbody|
45
70
  case response
46
71
  when Net::HTTPSuccess
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bckbn
4
+ module Charge
5
+ ENDPOINTS = {
6
+ all: "/charges",
7
+ create: "/charges",
8
+ get: "/charges/{id}"
9
+ }.freeze
10
+ private_constant :ENDPOINTS
11
+
12
+ def self.all(config = {})
13
+ path = ENDPOINTS.fetch(__method__)
14
+ @conn = Bckbn::Connection.new(config)
15
+ @conn.get_from_api(path, ChargesResponse)
16
+ end
17
+
18
+ def self.create(body, config = {})
19
+ body = CreateChargeRequest.new(body)
20
+ @conn = Bckbn::Connection.new(config)
21
+ @conn.post_to_api(ENDPOINTS.fetch(__method__), body.to_h, ChargeResponse)
22
+ end
23
+
24
+ def self.get(id, config = {})
25
+ path = Addressable::Template.new(ENDPOINTS.fetch(__method__)).expand(id: id)
26
+ @conn = Bckbn::Connection.new(config)
27
+ @conn.get_from_api(path, ChargeResponse)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bckbn
4
+ module Charge
5
+ CREATE_CHARGE_REQUEST_MEMBERS = %i[
6
+ amount
7
+ description
8
+ source
9
+ ].freeze
10
+
11
+ CreateChargeRequest = Struct.new(*CREATE_CHARGE_REQUEST_MEMBERS, keyword_init: true)
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bckbn
4
+ module Charge
5
+ using Bckbn::CoreExt::StringExt
6
+
7
+ CHARGE_RESPONSE_MEMBERS = %i[
8
+ id
9
+ amount
10
+ direction
11
+ posting
12
+ posting_code
13
+ posting_type
14
+ status
15
+ transaction_type
16
+ logs
17
+ ].freeze
18
+
19
+ CHARGES_RESPONSE_MEMBERS = %i[
20
+ charges
21
+ page_number
22
+ page_size
23
+ has_previous_page
24
+ has_next_page
25
+ logs
26
+ ].freeze
27
+
28
+ private_constant :CHARGE_RESPONSE_MEMBERS
29
+
30
+ ChargeResponse = Struct.new(*CHARGE_RESPONSE_MEMBERS, keyword_init: true)
31
+
32
+ ChargesResponse = Struct.new(*CHARGES_RESPONSE_MEMBERS, keyword_init: true) do
33
+ def initialize(**opts)
34
+ charges = opts.delete("charges")
35
+ super(opts)
36
+ self.charges = charges.map { |c| ChargeResponse.new(c) }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -14,52 +14,46 @@ module Bckbn
14
14
  }.freeze
15
15
  private_constant :ENDPOINTS
16
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)
17
+ class << self
18
+ def authorization(body, config = {})
19
+ process_transaction(__method__, body, config, AuthorizationRequest, AuthorizationResponse)
20
+ end
21
+
22
+ def capture(body, config = {})
23
+ process_transaction(__method__, body, config, CaptureRequest, CaptureResponse)
24
+ end
25
+
26
+ def credit(body, config = {})
27
+ process_transaction(__method__, body, config, CreditRequest, CreditResponse)
28
+ end
29
+
30
+ def sale(body, config = {})
31
+ process_transaction(__method__, body, config, SaleRequest, SaleResponse)
32
+ end
33
+
34
+ def void(body, config = {})
35
+ process_transaction(__method__, body, config, VoidRequest, VoidResponse)
36
+ end
37
+
38
+ def echeck_credit(body, config = {})
39
+ process_transaction(__method__, body, config, EcheckCreditRequest, EcheckCreditResponse)
40
+ end
41
+
42
+ def echeck_sale(body, config = {})
43
+ process_transaction(__method__, body, config, EcheckSaleRequest, EcheckSaleResponse)
44
+ end
45
+
46
+ def echeck_void(body, config = {})
47
+ process_transaction(__method__, body, config, EcheckVoidRequest, EcheckVoidResponse)
48
+ end
49
+
50
+ private
51
+
52
+ def process_transaction(method, body, config, request_klass, response_klass)
53
+ request = request_klass.new(body)
54
+ conn = Bckbn::Connection.new(config)
55
+ conn.post_to_api(ENDPOINTS.fetch(method), request.to_h, response_klass)
56
+ end
63
57
  end
64
58
  end
65
59
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bckbn
4
+ module Transaction
5
+ MEMBERS = %i[
6
+ account_number
7
+ receiver
8
+ sec_code
9
+ description
10
+ transaction_type
11
+ amount
12
+ service_type
13
+ purpose
14
+ client_identifier
15
+ ].freeze
16
+
17
+ Payment = Struct.new(*MEMBERS, keyword_init: true) do
18
+ def initialize(opts)
19
+ valid_opts = opts.slice(*members)
20
+ valid_opts.each { |key, value| public_send("#{key}=", value) }
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/bckbn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bckbn
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.1"
5
5
  end
data/lib/bckbn.rb CHANGED
@@ -4,6 +4,7 @@ require "json"
4
4
  require "forwardable"
5
5
  require "logger"
6
6
  require "net/http"
7
+ require "addressable"
7
8
  require "bckbn/version"
8
9
  require "bckbn/configuration"
9
10
  require "bckbn/core_ext"
@@ -14,6 +15,11 @@ require "bckbn/resources/transaction/models/echeck"
14
15
  require "bckbn/resources/transaction/models/billing_address"
15
16
  require "bckbn/resources/transaction/models/requests"
16
17
  require "bckbn/resources/transaction/models/responses"
18
+ require "bckbn/resources/transaction/models/payment"
19
+
20
+ require "bckbn/resources/charge/api"
21
+ require "bckbn/resources/charge/models/requests"
22
+ require "bckbn/resources/charge/models/responses"
17
23
 
18
24
  module Bckbn
19
25
  @config = Bckbn::Configuration.setup
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bckbn
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nikkypx
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faker
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,11 +114,15 @@ files:
100
114
  - lib/bckbn/configuration.rb
101
115
  - lib/bckbn/connection.rb
102
116
  - lib/bckbn/core_ext.rb
117
+ - lib/bckbn/resources/charge/api.rb
118
+ - lib/bckbn/resources/charge/models/requests.rb
119
+ - lib/bckbn/resources/charge/models/responses.rb
103
120
  - lib/bckbn/resources/transaction/api.rb
104
121
  - lib/bckbn/resources/transaction/models/billing_address.rb
105
122
  - lib/bckbn/resources/transaction/models/card.rb
106
123
  - lib/bckbn/resources/transaction/models/cardholder_authentication.rb
107
124
  - lib/bckbn/resources/transaction/models/echeck.rb
125
+ - lib/bckbn/resources/transaction/models/payment.rb
108
126
  - lib/bckbn/resources/transaction/models/requests.rb
109
127
  - lib/bckbn/resources/transaction/models/responses.rb
110
128
  - lib/bckbn/version.rb