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 +4 -4
- data/CHANGELOG.md +2 -1
- data/lib/generators/tamara/templates/tamara.rb +1 -0
- data/lib/tamara/api/payments.rb +1 -1
- data/lib/tamara/configuration.rb +1 -1
- data/lib/tamara/json_schemas/amount.rb +2 -2
- data/lib/tamara/json_schemas/capture_optional_keys.rb +11 -0
- data/lib/tamara/json_schemas/orders/create.rb +1 -1
- data/lib/tamara/json_schemas/payments/capture.rb +12 -9
- data/lib/tamara/json_schemas/shipping_info.rb +17 -0
- data/lib/tamara/version.rb +1 -1
- data/lib/tamara.rb +2 -0
- metadata +7 -6
- data/lib/tamara/hmac.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ed7326a6fecdfbe8f4ec879bf4064b9938daa536a65ff24a5587ba6839fe61
|
4
|
+
data.tar.gz: 657cda1b6f8c53b7f745dca87f34568cd9c0b0e6cc436bf6657309fa7cc2ff70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '015448abe6000bedf98c6ef38c02549c498f04c67e4d2062ab7359e9c2b79e65fa32d78cd368e65cdbed4d50424f5ffbb5ebca991f86aa2979bb54a903549d4d'
|
7
|
+
data.tar.gz: a26f9e25c4c7d677c34455ea1198a92a0ac16373ff280a821610301e0e1290682415760330a8a4095b2e99fac8aa3640f93d5b2250b9fbb3c296ceea1e73cc9e
|
data/CHANGELOG.md
CHANGED
data/lib/tamara/api/payments.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Tamara
|
2
2
|
module Payments
|
3
|
-
def self.capture(order_id:, total_amount:, shipping_info
|
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,
|
data/lib/tamara/configuration.rb
CHANGED
@@ -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:
|
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:
|
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
|
data/lib/tamara/version.rb
CHANGED
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.
|
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-
|
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://
|
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://
|
160
|
-
source_code_uri: https://
|
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
|