tamara 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edbc1e81e1dfb04e02c29172d32de538b96b94d60e4fdd804b949264f673d2a2
4
- data.tar.gz: 0c61bb924be56b120664eea9de485230455fb939e614196c598aab55937623b0
3
+ metadata.gz: 98690a89dd1b5601ff9c7c2da0643a0f8e0eb8da5da99b595cf72078f50cf220
4
+ data.tar.gz: 7ae0059eaf3df407a9a3461b96282007d074ffc2c8e20de4d547aee0d17d674d
5
5
  SHA512:
6
- metadata.gz: c10cf6d155ecf1c9fff7319146939c4cb0983f02d016e6137590cfdbc65e874a3ea48ae494421cef342b3ec437f1833c86f8878777e5c2d2bec7d3b02ceb5eb8
7
- data.tar.gz: 224597005ae038a91d1eff545bcd2f994848f4f1052635582a4ee63f01155d449401614ffde12ff20fcd0267b421309845c66273bf3b2e6b385e13cce2488f5d
6
+ metadata.gz: c9f878121556e2b74a5a8e23951010db0419bb52213cc60bf9be85f0845845ada4e0f6729ce01c8e1a0a0f88eef9c2cf5c59fbaa7a2639c5c87b9d6917cb3c62
7
+ data.tar.gz: e12f3367f44da07961cca5ec2672fefb630ad9ad76272f9f2544c9a5820fff51db723b31ec73cb3a4a48fd995ca171e3d87e146217a1b1a63cafd9fb93c0e6bb
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ TAMARA_API_TOKEN=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-06-01
3
+ ## [0.1.0] - 2025-03-12
4
+ ## [0.1.1] - 2025-03-18
5
+ ## [0.1.2] - 2025-03-26
4
6
 
5
7
  - Initial release
data/Gemfile CHANGED
@@ -5,13 +5,18 @@ gemspec
5
5
 
6
6
  group :development, :test do
7
7
  gem "dotenv-rails"
8
+ gem "bundler-audit"
8
9
  gem "fuubar", "~> 2.5.1"
9
10
  gem "guard-rspec"
10
11
  gem "rake", "~> 13.2"
11
12
  gem "rspec", "~> 3.13"
13
+ gem "rspec_junit_formatter"
12
14
  gem "rubocop", "~> 1.50.2"
13
15
  gem "rubocop-performance", "~> 1.17.1"
14
16
  gem "rubocop-rails", "~> 2.19.1"
17
+ gem "rubocop-rake"
18
+ gem "rubocop-rspec"
19
+ gem "ruby_audit"
15
20
  end
16
21
 
17
22
  group :test do
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tamara (0.1.0)
4
+ tamara (0.1.2)
5
5
  activesupport (>= 5.2, < 7.0)
6
6
  concurrent-ruby (~> 1.2.2)
7
7
  faraday (~> 1.10.3)
@@ -35,6 +35,9 @@ GEM
35
35
  ast (2.4.2)
36
36
  bigdecimal (3.1.9)
37
37
  builder (3.3.0)
38
+ bundler-audit (0.9.2)
39
+ bundler (>= 1.2.0, < 3)
40
+ thor (~> 1.0)
38
41
  coderay (1.1.3)
39
42
  concurrent-ruby (1.2.3)
40
43
  crack (1.0.0)
@@ -118,6 +121,8 @@ GEM
118
121
  nokogiri (1.13.10)
119
122
  mini_portile2 (~> 2.8.0)
120
123
  racc (~> 1.4)
124
+ nokogiri (1.13.10-x86_64-linux)
125
+ racc (~> 1.4)
121
126
  notiffany (0.1.3)
122
127
  nenv (~> 0.1)
123
128
  shellany (~> 0.0)
@@ -166,6 +171,8 @@ GEM
166
171
  diff-lcs (>= 1.2.0, < 2.0)
167
172
  rspec-support (~> 3.13.0)
168
173
  rspec-support (3.13.2)
174
+ rspec_junit_formatter (0.6.0)
175
+ rspec-core (>= 2, < 4, != 2.12.0)
169
176
  rubocop (1.50.2)
170
177
  json (~> 2.3)
171
178
  parallel (~> 1.10)
@@ -178,6 +185,8 @@ GEM
178
185
  unicode-display_width (>= 2.4.0, < 3.0)
179
186
  rubocop-ast (1.30.0)
180
187
  parser (>= 3.2.1.0)
188
+ rubocop-capybara (2.18.0)
189
+ rubocop (~> 1.41)
181
190
  rubocop-performance (1.17.1)
182
191
  rubocop (>= 1.7.0, < 2.0)
183
192
  rubocop-ast (>= 0.4.0)
@@ -185,8 +194,15 @@ GEM
185
194
  activesupport (>= 4.2.0)
186
195
  rack (>= 1.1)
187
196
  rubocop (>= 1.33.0, < 2.0)
197
+ rubocop-rake (0.6.0)
198
+ rubocop (~> 1.0)
199
+ rubocop-rspec (2.20.0)
200
+ rubocop (~> 1.33)
201
+ rubocop-capybara (~> 2.17)
188
202
  ruby-progressbar (1.13.0)
189
203
  ruby2_keywords (0.0.5)
204
+ ruby_audit (2.3.1)
205
+ bundler-audit (~> 0.9.0)
190
206
  shellany (0.0.1)
191
207
  simplecov (0.22.0)
192
208
  docile (~> 1.1)
@@ -207,17 +223,23 @@ GEM
207
223
 
208
224
  PLATFORMS
209
225
  -darwin-22
226
+ x86_64-linux
210
227
 
211
228
  DEPENDENCIES
229
+ bundler-audit
212
230
  dotenv-rails
213
231
  fuubar (~> 2.5.1)
214
232
  generator_spec
215
233
  guard-rspec
216
234
  rake (~> 13.2)
217
235
  rspec (~> 3.13)
236
+ rspec_junit_formatter
218
237
  rubocop (~> 1.50.2)
219
238
  rubocop-performance (~> 1.17.1)
220
239
  rubocop-rails (~> 2.19.1)
240
+ rubocop-rake
241
+ rubocop-rspec
242
+ ruby_audit
221
243
  simplecov (~> 0.22.0)
222
244
  tamara!
223
245
  vcr
@@ -5,4 +5,5 @@ Tamara.configure do |config|
5
5
  # config.notification_token = ""
6
6
  # config.public_key = ""
7
7
  config.checkout_optional_keys = {}
8
+ config.capture_optional_keys = {}
8
9
  end
@@ -1,6 +1,6 @@
1
1
  module Tamara
2
2
  module Payments
3
- def self.capture(order_id:, total_amount:, shipping_info:, items: [], shipping_amount: nil, tax_amount: nil, discount_amount: nil, opts: {})
3
+ def self.capture(order_id:, total_amount:, shipping_info: nil, items: [], shipping_amount: nil, tax_amount: nil, discount_amount: nil, opts: {})
4
4
  Tamara::Payments::Capture.call(
5
5
  order_id: order_id,
6
6
  total_amount: total_amount,
@@ -1,5 +1,5 @@
1
1
  module Tamara
2
2
  class Configuration
3
- attr_accessor :api_token, :notification_token, :public_key, :checkout_optional_keys
3
+ attr_accessor :api_token, :notification_token, :public_key, :checkout_optional_keys, :capture_optional_keys
4
4
  end
5
5
  end
@@ -3,12 +3,12 @@ module Tamara
3
3
  module Amount
4
4
  CURRENCIES = %w[SAR AED BHD KWD OMR].freeze
5
5
 
6
- def self.schema(allows_null: false)
6
+ def self.schema(allows_null: false, min: 0.1)
7
7
  {
8
8
  "$schema": "http://json-schema.org/draft-06/schema",
9
9
  type: ["object", (allows_null ? "null" : nil)].compact,
10
10
  properties: {
11
- amount: Types::Float.schema(min: 0.1),
11
+ amount: Types::Float.schema(min: min),
12
12
  currency: Types::Enum.schema(values: CURRENCIES, default: "SAR")
13
13
  },
14
14
  required: %w[amount currency]
@@ -0,0 +1,11 @@
1
+ module Tamara
2
+ module JsonSchemas
3
+ module CaptureOptionalKeys
4
+ def capture_optional_keys
5
+ @params ||= {}
6
+ capture_optional_keys = @params.dig(:opts, :capture_optional_keys) || Tamara.configuration.capture_optional_keys
7
+ capture_optional_keys.is_a?(Hash) ? capture_optional_keys : {}
8
+ end
9
+ end
10
+ end
11
+ end
@@ -20,7 +20,7 @@ module Tamara
20
20
  item_url: Types::Url.schema(allows_null: filtered_keys.exclude?("item_url")),
21
21
  image_url: Types::Url.schema(allows_null: filtered_keys.exclude?("image_url")),
22
22
  unit_price: Amount.schema(allows_null: filtered_keys.exclude?("unit_price")),
23
- tax_amount: Amount.schema(allows_null: filtered_keys.exclude?("tax_amount")),
23
+ tax_amount: Amount.schema(allows_null: filtered_keys.exclude?("tax_amount"), min: 0.0),
24
24
  discount_amount: Amount.schema(allows_null: filtered_keys.exclude?("discount_amount")),
25
25
  total_amount: Amount.schema(allows_null: filtered_keys.exclude?("total_amount"))
26
26
  },
@@ -23,8 +23,8 @@ module Tamara
23
23
  country_code: Types::Enum.schema(values: COUNTRY_CODES, default: "SA"),
24
24
  description: Types::String.schema(max_length: 256, allows_null: filtered_keys.exclude?("description")),
25
25
  total_amount: Amount.schema(allows_null: filtered_keys.exclude?("total_amount")),
26
- shipping_amount: Amount.schema(allows_null: filtered_keys.exclude?("shipping_amount")),
27
- tax_amount: Amount.schema(allows_null: filtered_keys.exclude?("tax_amount")),
26
+ shipping_amount: Amount.schema(allows_null: filtered_keys.exclude?("shipping_amount"), min: 0.0),
27
+ tax_amount: Amount.schema(allows_null: filtered_keys.exclude?("tax_amount"), min: 0.0),
28
28
  consumer: Consumer.schema(allows_null: filtered_keys.exclude?("consumer")),
29
29
  items: {
30
30
  type: "array",
@@ -2,8 +2,11 @@ module Tamara
2
2
  module JsonSchemas
3
3
  module Payments
4
4
  module Capture
5
+ include CaptureOptionalKeys
5
6
  include Validator
6
7
 
8
+ REQUIRED_KEYS = %w[order_id total_amount shipping_info].freeze
9
+
7
10
  private
8
11
 
9
12
  def schema
@@ -13,14 +16,7 @@ module Tamara
13
16
  properties: {
14
17
  order_id: Types::Uuid.schema,
15
18
  total_amount: Amount.schema,
16
- shipping_info: {
17
- type: "object",
18
- properties: {
19
- shipped_at: Types::String.schema,
20
- shipping_company: Types::String.schema
21
- },
22
- required: %w[shipped_at shipping_company]
23
- },
19
+ shipping_info: ShippingInfo.schema(allows_null: filtered_keys.exclude?("shipping_info")),
24
20
  items: {
25
21
  type: "array",
26
22
  items: Item.schema
@@ -29,9 +25,16 @@ module Tamara
29
25
  tax_amount: Amount.schema(allows_null: true),
30
26
  discount_amount: Amount.schema(allows_null: true)
31
27
  },
32
- required: %w[order_id total_amount shipping_info]
28
+ required: REQUIRED_KEYS
33
29
  }
34
30
  end
31
+
32
+ def filtered_keys
33
+ @filtered_keys ||= begin
34
+ optional_keys = capture_optional_keys.select { |_k, v| v.empty? }.keys.map(&:to_s)
35
+ REQUIRED_KEYS - optional_keys
36
+ end
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -0,0 +1,17 @@
1
+ module Tamara
2
+ module JsonSchemas
3
+ module ShippingInfo
4
+ def self.schema(allows_null: false)
5
+ {
6
+ "$schema": "http://json-schema.org/draft-06/schema",
7
+ type: ["object", (allows_null ? "null" : nil)].compact,
8
+ properties: {
9
+ shipped_at: Types::String.schema,
10
+ shipping_company: Types::String.schema
11
+ },
12
+ required: %w[shipped_at shipping_company]
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Tamara
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
data/lib/tamara.rb CHANGED
@@ -11,6 +11,7 @@ require "tamara/errors"
11
11
  require "tamara/configuration"
12
12
 
13
13
  # JSON schemas
14
+ require "tamara/json_schemas/capture_optional_keys"
14
15
  require "tamara/json_schemas/checkout_optional_keys"
15
16
  require "tamara/json_schemas/validator"
16
17
 
@@ -36,6 +37,7 @@ require "tamara/json_schemas/payments/capture"
36
37
  require "tamara/json_schemas/payment_options/check"
37
38
  require "tamara/json_schemas/payment_types"
38
39
  require "tamara/json_schemas/risk_assessment"
40
+ require "tamara/json_schemas/shipping_info"
39
41
  require "tamara/json_schemas/webhook"
40
42
  require "tamara/json_schemas/webhook_event"
41
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tamara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Youssef Ossama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-12 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -93,6 +93,7 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
+ - ".env.example"
96
97
  - ".rubocop.yml"
97
98
  - ".rubocop_todo.yml"
98
99
  - ".ruby-version"
@@ -124,9 +125,9 @@ files:
124
125
  - lib/tamara/api/webhooks.rb
125
126
  - lib/tamara/configuration.rb
126
127
  - lib/tamara/errors.rb
127
- - lib/tamara/hmac.rb
128
128
  - lib/tamara/json_schemas/address.rb
129
129
  - lib/tamara/json_schemas/amount.rb
130
+ - lib/tamara/json_schemas/capture_optional_keys.rb
130
131
  - lib/tamara/json_schemas/checkout_optional_keys.rb
131
132
  - lib/tamara/json_schemas/consumer.rb
132
133
  - lib/tamara/json_schemas/discount.rb
@@ -138,6 +139,7 @@ files:
138
139
  - lib/tamara/json_schemas/payment_types.rb
139
140
  - lib/tamara/json_schemas/payments/capture.rb
140
141
  - lib/tamara/json_schemas/risk_assessment.rb
142
+ - lib/tamara/json_schemas/shipping_info.rb
141
143
  - lib/tamara/json_schemas/types/boolean.rb
142
144
  - lib/tamara/json_schemas/types/date.rb
143
145
  - lib/tamara/json_schemas/types/enum.rb
@@ -151,13 +153,13 @@ files:
151
153
  - lib/tamara/json_schemas/webhook_event.rb
152
154
  - lib/tamara/version.rb
153
155
  - sig/tamara.rbs
154
- homepage: https://github.com/autocloud/tamara-rails
156
+ homepage: https://gitlab.com/autocloud/tamara-rails
155
157
  licenses:
156
158
  - MIT
157
159
  metadata:
158
160
  allowed_push_host: https://rubygems.org
159
- homepage_uri: https://github.com/autocloud/tamara-rails
160
- source_code_uri: https://github.com/autocloud/tamara-rails
161
+ homepage_uri: https://gitlab.com/autocloud/tamara-rails
162
+ source_code_uri: https://gitlab.com/autocloud/tamara-rails
161
163
  rubygems_mfa_required: 'true'
162
164
  post_install_message:
163
165
  rdoc_options: []
data/lib/tamara/hmac.rb DELETED
@@ -1,20 +0,0 @@
1
- module Tamara
2
- module Hmac
3
- FILTERED_TRANSACTION_KEYS = %w[amount_cents created_at currency error_occured has_parent_transaction id
4
- integration_id is_3d_secure is_auth is_capture is_refunded is_standalone_payment
5
- is_voided order.id owner pending
6
- source_data.pansource_data.sub_type source_data.type success].freeze
7
-
8
- class << self
9
- def valid_signature?(tamara_response)
10
- digest = ::OpenSSL::Digest.new("sha512")
11
-
12
- concatenated_str = FILTERED_TRANSACTION_KEYS.map do |element|
13
- tamara_response.dig("obj", *element.split("."))
14
- end.join
15
- secure_hash = ::OpenSSL::HMAC.hexdigest(digest, Tamara.hmac_key, concatenated_str)
16
- secure_hash == tamara_response["hmac"]
17
- end
18
- end
19
- end
20
- end