tamara 0.1.0 → 0.1.1

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: 61ed7326a6fecdfbe8f4ec879bf4064b9938daa536a65ff24a5587ba6839fe61
4
+ data.tar.gz: 657cda1b6f8c53b7f745dca87f34568cd9c0b0e6cc436bf6657309fa7cc2ff70
5
5
  SHA512:
6
- metadata.gz: c10cf6d155ecf1c9fff7319146939c4cb0983f02d016e6137590cfdbc65e874a3ea48ae494421cef342b3ec437f1833c86f8878777e5c2d2bec7d3b02ceb5eb8
7
- data.tar.gz: 224597005ae038a91d1eff545bcd2f994848f4f1052635582a4ee63f01155d449401614ffde12ff20fcd0267b421309845c66273bf3b2e6b385e13cce2488f5d
6
+ metadata.gz: '015448abe6000bedf98c6ef38c02549c498f04c67e4d2062ab7359e9c2b79e65fa32d78cd368e65cdbed4d50424f5ffbb5ebca991f86aa2979bb54a903549d4d'
7
+ data.tar.gz: a26f9e25c4c7d677c34455ea1198a92a0ac16373ff280a821610301e0e1290682415760330a8a4095b2e99fac8aa3640f93d5b2250b9fbb3c296ceea1e73cc9e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
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
4
5
 
5
6
  - Initial release
@@ -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
@@ -23,7 +23,7 @@ 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")),
26
+ shipping_amount: Amount.schema(allows_null: filtered_keys.exclude?("shipping_amount"), min: 0.0),
27
27
  tax_amount: Amount.schema(allows_null: filtered_keys.exclude?("tax_amount")),
28
28
  consumer: Consumer.schema(allows_null: filtered_keys.exclude?("consumer")),
29
29
  items: {
@@ -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.1".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.1
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-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -124,9 +124,9 @@ files:
124
124
  - lib/tamara/api/webhooks.rb
125
125
  - lib/tamara/configuration.rb
126
126
  - lib/tamara/errors.rb
127
- - lib/tamara/hmac.rb
128
127
  - lib/tamara/json_schemas/address.rb
129
128
  - lib/tamara/json_schemas/amount.rb
129
+ - lib/tamara/json_schemas/capture_optional_keys.rb
130
130
  - lib/tamara/json_schemas/checkout_optional_keys.rb
131
131
  - lib/tamara/json_schemas/consumer.rb
132
132
  - lib/tamara/json_schemas/discount.rb
@@ -138,6 +138,7 @@ files:
138
138
  - lib/tamara/json_schemas/payment_types.rb
139
139
  - lib/tamara/json_schemas/payments/capture.rb
140
140
  - lib/tamara/json_schemas/risk_assessment.rb
141
+ - lib/tamara/json_schemas/shipping_info.rb
141
142
  - lib/tamara/json_schemas/types/boolean.rb
142
143
  - lib/tamara/json_schemas/types/date.rb
143
144
  - lib/tamara/json_schemas/types/enum.rb
@@ -151,13 +152,13 @@ files:
151
152
  - lib/tamara/json_schemas/webhook_event.rb
152
153
  - lib/tamara/version.rb
153
154
  - sig/tamara.rbs
154
- homepage: https://github.com/autocloud/tamara-rails
155
+ homepage: https://gitlab.com/autocloud/tamara-rails
155
156
  licenses:
156
157
  - MIT
157
158
  metadata:
158
159
  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
160
+ homepage_uri: https://gitlab.com/autocloud/tamara-rails
161
+ source_code_uri: https://gitlab.com/autocloud/tamara-rails
161
162
  rubygems_mfa_required: 'true'
162
163
  post_install_message:
163
164
  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