bckbn 0.2.0 → 1.1.0

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: 18497553fb0efdfc5eabb1f3893f41cfd6d5bcb32e5d6f8b5fe0f29552ba1807
4
- data.tar.gz: 6850ef4da956af91bb09b0208bf4023689e9ac4a88c493c460f2468d17446565
3
+ metadata.gz: 9ce61a5d5dbf67fe50d53a332c58bb41fb24caec50bb82289e81a09d7de5d1f1
4
+ data.tar.gz: dfc489712b87783ccff600946ab527bb70cc807fe30b59020ec5cd5e591f940d
5
5
  SHA512:
6
- metadata.gz: 657681ad26592ebdc309d65410843b6e0301140157a08a60da6a853850d917bf1f38222fe4ddd0b33841d3e3f9372b46e902e6cca9a3c02e8700cfdcb33c41a2
7
- data.tar.gz: c989abe10cccc89833d898c5fa9e01e687071b9d43169034e0918b72cf172c78723a8788c642b51c3d0fe49e257b6b40ad9ca07e7e4d031c9be0c2a214ccba1e
6
+ metadata.gz: 80c6362a1c47f111eb2e06317b43429498f31e5aa48d4137ad1ee2251848186e2871014ebd17f3407976a83486661cdbad39e384b52fd7050701807b42582a45
7
+ data.tar.gz: 8b197ce98933239f240138cef09edf68b2a5ba9dcb09d970bfae50aad3d99bacd984fdcc3d8f571619c2dca1757db1cb93dfe10ad726603b8758a5ac02c6333b
data/.irbrc CHANGED
@@ -4,77 +4,75 @@ Bckbn.api_base = "http://localhost:8080"
4
4
  Bckbn.access_token = "foobar"
5
5
  Bckbn.merchant_id = "101"
6
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
7
+ @auth_body = {
8
+ amount: 5000,
9
+ bill_to_address: {
10
+ name: "John Doe",
11
+ address_line_1: "123 Main St",
12
+ city: "Boston",
13
+ state: "MA",
14
+ country: "US",
15
+ zip: "12345",
16
+ email: "jsmith@someaddress.com",
17
+ phone: "555-123-4567"
18
+ },
19
+ card: {
20
+ type: "MC",
21
+ number: "{{1234567890123456}}",
22
+ exp_date: "1223"
23
+ },
24
+ id: "12345",
25
+ order_id: "5234234",
26
+ order_source: "ecommerce",
27
+ partial: false,
28
+ report_group: "ABC Division"
29
+ }.freeze
31
30
 
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
31
+ @sale_body = {
32
+ id: "12345",
33
+ report_group: "ABC Division",
34
+ amount: 5000,
35
+ "card": {
36
+ "type": "VI",
37
+ "number": "{{1234567890123456}}",
38
+ "exp_date": "1223",
39
+ "card_validation_num": "123"
40
+ },
41
+ "bill_to_address": {
42
+ "name": "John Doe",
43
+ "address_line_1": "123 Main St",
44
+ "city": "Boston",
45
+ "state": "MA",
46
+ "country": "US",
47
+ "zip": "12345",
48
+ "email": "jsmith@someaddress.com",
49
+ "phone": "555-123-4567"
50
+ },
51
+ partial: false,
52
+ order_id: "5234234",
53
+ order_source: "ecommerce"
54
+ }.freeze
56
55
 
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
56
+ @echeck_sale_body = {
57
+ "echeck": {
58
+ "acc_type": "Checking",
59
+ "acc_num": "5186005800001012",
60
+ "routing_num": "000010101",
61
+ "check_num": nil
62
+ },
63
+ "bill_to_address": {
64
+ "name": "John Doe",
65
+ "address_line_1": "123 Main St",
66
+ "city": "Boston",
67
+ "state": "MA",
68
+ "country": "US",
69
+ "zip": "12345",
70
+ "email": "jsmith@someaddress.com",
71
+ "phone": "555-123-4567"
72
+ },
73
+ "amount": 5000,
74
+ "id": "12345",
75
+ "report_group": "ABC Division",
76
+ "order_id": "5234234",
77
+ "order_source": "ecommerce"
78
+ }.freeze
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
- ## [Unreleased]
1
+ ## 0.2.0
2
2
 
3
- ## [0.1.0] - 2023-08-18
3
+ - Add support for `debug` and `error` log levels
4
4
 
5
- - Initial release
5
+ ## 1.0.0
6
+
7
+ - Update local config to override global config where both present
8
+ - Add idempotency key header
9
+
10
+ ## 1.0.1
11
+
12
+ - Allow http scheme
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bckbn (0.2.0)
4
+ bckbn (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -9,6 +9,9 @@ gem install bckbn
9
9
  ```
10
10
 
11
11
  ## Configuration
12
+ Local configuration will override global configuration where
13
+ they conflict. Some config can only be set locally, like an
14
+ `idempotency_key`.
12
15
 
13
16
  ### Global
14
17
 
@@ -26,7 +29,7 @@ Bckbn::Transaction.capture({
26
29
  })
27
30
  ```
28
31
 
29
- ### Per Request
32
+ ### Local
30
33
 
31
34
  ```ruby
32
35
  require "bckbn"
@@ -34,6 +37,7 @@ require "bckbn"
34
37
  api_base = "..."
35
38
  access_token = "..."
36
39
  merchant_id = "..."
40
+ idempotency_key = "..."
37
41
 
38
42
  Bckbn::Transaction.capture(
39
43
  {
@@ -42,13 +46,19 @@ Bckbn::Transaction.capture(
42
46
  report_group: "ABC Division"
43
47
  },
44
48
  {
45
- api_base:,
46
- access_token:,
47
- merchant_id:
49
+ api_base: api_base,
50
+ access_token: access_token,
51
+ merchant_id: merchant_id,
52
+ idempotency_key: idempotency_key
48
53
  }
49
54
  )
50
55
  ```
51
56
 
57
+ ### Idempotency
58
+ An idempotency key can be added to allow retries without creating duplicate transactions.
59
+ Successful POST requests will return a cached response. New requests can be issued
60
+ by changing the request body or the idempotency key.
61
+
52
62
  ## Documentation
53
63
 
54
64
  ```
@@ -9,6 +9,7 @@ module Bckbn
9
9
  log_level
10
10
  merchant_id
11
11
  source_ip_address
12
+ idempotency_key
12
13
  ].freeze
13
14
 
14
15
  Configuration = Struct.new(*CONFIG_OPTIONS, keyword_init: true) do
@@ -23,26 +23,22 @@ module Bckbn
23
23
  Net::HTTPServiceUnavailable => HttpServiceUnavailable
24
24
  }.freeze
25
25
 
26
- def initialize(config)
27
- @config = config.empty? ? Bckbn.config : Bckbn::Configuration.new(**config)
26
+ def initialize(per_req_config)
27
+ global_config = Bckbn.config.to_h
28
+ config = global_config.merge(per_req_config)
29
+
30
+ @config = Bckbn::Configuration.new(**config)
28
31
  @logs = []
29
32
  end
30
33
 
31
34
  def post_to_api(path, body, klass)
32
35
  log(:debug, "POST #{path}\n\nData: #{body.to_json}")
33
36
 
34
- headers = {
35
- "Content-Type" => "application/json",
36
- "Authorization" => "Bearer #{config.access_token}",
37
- "X-Api-Version" => config.api_version,
38
- "X-Merchant-Id" => config.merchant_id,
39
- "X-Source-Ip-Address" => config.source_ip_address
40
- }
41
-
42
37
  url = URI.parse(config.api_base + path)
43
38
  request = Net::HTTP::Post.new(url.path)
44
- headers.reject! { |_, v| v.nil? || v == "" }
45
- headers.each { |k, v| request[k] = v }
39
+ bckbn_headers = headers(config)
40
+ bckbn_headers.reject! { |_, v| v.nil? || v == "" }
41
+ bckbn_headers.each { |k, v| request[k] = v }
46
42
  request.body = body.to_json
47
43
 
48
44
  response_handler(url, request) do |response, rbody|
@@ -68,7 +64,7 @@ module Bckbn
68
64
 
69
65
  def response_handler(url, request)
70
66
  http = Net::HTTP.new(url.host, url.port)
71
- http.use_ssl = true
67
+ http.use_ssl = url.scheme == "https"
72
68
 
73
69
  response, body = begin
74
70
  r = http.request(request)
@@ -86,6 +82,17 @@ module Bckbn
86
82
  end
87
83
  end
88
84
 
85
+ def headers(config)
86
+ {
87
+ "Content-Type" => "application/json",
88
+ "Authorization" => "Bearer #{config.access_token}",
89
+ "X-Api-Version" => config.api_version,
90
+ "X-Merchant-Id" => config.merchant_id,
91
+ "X-Source-Ip-Address" => config.source_ip_address,
92
+ "X-Idempotency-Key" => config.idempotency_key
93
+ }
94
+ end
95
+
89
96
  def log(level, message)
90
97
  return if LOG_LEVEL_RANKING[config.log_level] > LOG_LEVEL_RANKING[level]
91
98
 
data/lib/bckbn/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bckbn
4
- VERSION = "0.2.0"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bckbn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.1.0
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-05 00:00:00.000000000 Z
11
+ date: 2023-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker