tamara 0.1.0
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 +7 -0
- data/.rubocop.yml +114 -0
- data/.rubocop_todo.yml +21 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +227 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +290 -0
- data/Rakefile +19 -0
- data/lib/generators/tamara/install_generator.rb +15 -0
- data/lib/generators/tamara/templates/tamara.rb +8 -0
- data/lib/tamara/api/api_token.rb +14 -0
- data/lib/tamara/api/application_service.rb +48 -0
- data/lib/tamara/api/orders/authorize.rb +26 -0
- data/lib/tamara/api/orders/cancel.rb +38 -0
- data/lib/tamara/api/orders/create.rb +71 -0
- data/lib/tamara/api/orders/details/merchant_order.rb +28 -0
- data/lib/tamara/api/orders/details/tamara_order.rb +28 -0
- data/lib/tamara/api/orders.rb +56 -0
- data/lib/tamara/api/payment_options/check.rb +34 -0
- data/lib/tamara/api/payment_options.rb +13 -0
- data/lib/tamara/api/payment_types.rb +23 -0
- data/lib/tamara/api/payments/capture.rb +40 -0
- data/lib/tamara/api/payments.rb +16 -0
- data/lib/tamara/api/request.rb +49 -0
- data/lib/tamara/api/signature.rb +25 -0
- data/lib/tamara/api/webhooks.rb +28 -0
- data/lib/tamara/configuration.rb +5 -0
- data/lib/tamara/errors.rb +67 -0
- data/lib/tamara/hmac.rb +20 -0
- data/lib/tamara/json_schemas/address.rb +23 -0
- data/lib/tamara/json_schemas/amount.rb +19 -0
- data/lib/tamara/json_schemas/checkout_optional_keys.rb +11 -0
- data/lib/tamara/json_schemas/consumer.rb +21 -0
- data/lib/tamara/json_schemas/discount.rb +17 -0
- data/lib/tamara/json_schemas/item.rb +41 -0
- data/lib/tamara/json_schemas/merchant_url.rb +19 -0
- data/lib/tamara/json_schemas/orders/cancel.rb +30 -0
- data/lib/tamara/json_schemas/orders/create.rb +61 -0
- data/lib/tamara/json_schemas/payment_options/check.rb +25 -0
- data/lib/tamara/json_schemas/payment_types.rb +21 -0
- data/lib/tamara/json_schemas/payments/capture.rb +38 -0
- data/lib/tamara/json_schemas/risk_assessment.rb +65 -0
- data/lib/tamara/json_schemas/types/boolean.rb +15 -0
- data/lib/tamara/json_schemas/types/date.rb +17 -0
- data/lib/tamara/json_schemas/types/enum.rb +15 -0
- data/lib/tamara/json_schemas/types/float.rb +16 -0
- data/lib/tamara/json_schemas/types/integer.rb +17 -0
- data/lib/tamara/json_schemas/types/string.rb +21 -0
- data/lib/tamara/json_schemas/types/url.rb +15 -0
- data/lib/tamara/json_schemas/types/uuid.rb +19 -0
- data/lib/tamara/json_schemas/validator.rb +66 -0
- data/lib/tamara/json_schemas/webhook.rb +33 -0
- data/lib/tamara/json_schemas/webhook_event.rb +37 -0
- data/lib/tamara/version.rb +3 -0
- data/lib/tamara.rb +101 -0
- data/sig/tamara.rbs +4 -0
- metadata +181 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module RiskAssessment
|
|
4
|
+
extend CheckoutOptionalKeys
|
|
5
|
+
|
|
6
|
+
GENDERS = %w[Male Female].freeze
|
|
7
|
+
REQUIRED_KEYS = %w[
|
|
8
|
+
customer_age customer_dob customer_gender customer_nationality
|
|
9
|
+
is_premium_customer is_existing_customer is_guest_user
|
|
10
|
+
account_creation_date platform_account_creation_date
|
|
11
|
+
date_of_first_transaction is_card_on_file is_COD_customer
|
|
12
|
+
has_delivered_order is_phone_verified is_fraudulent_customer
|
|
13
|
+
total_ltv total_order_count order_amount_last3months
|
|
14
|
+
order_count_last3months last_order_date last_order_amount
|
|
15
|
+
reward_program_enrolled reward_program_points
|
|
16
|
+
].freeze
|
|
17
|
+
|
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
|
19
|
+
def self.schema(allows_null: false, params: nil)
|
|
20
|
+
@params = params
|
|
21
|
+
{
|
|
22
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
23
|
+
type: ["object", (allows_null ? "null" : nil)].compact,
|
|
24
|
+
properties: {
|
|
25
|
+
customer_age: Types::Integer.schema(min: 1, default: 21, allows_null: filtered_keys.exclude?("customer_age")),
|
|
26
|
+
customer_dob: Types::Date.schema(default: "01-12-2000", allows_null: filtered_keys.exclude?("customer_dob")),
|
|
27
|
+
customer_gender: Types::Enum.schema(values: GENDERS, default: "Female", allows_null: filtered_keys.exclude?("customer_gender")),
|
|
28
|
+
customer_nationality: Types::Enum.schema(values: COUNTRY_CODES, default: "SA", allows_null: filtered_keys.exclude?("customer_nationality")),
|
|
29
|
+
is_premium_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_premium_customer")),
|
|
30
|
+
is_existing_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_existing_customer")),
|
|
31
|
+
is_guest_user: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_guest_user")),
|
|
32
|
+
is_card_on_file: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_card_on_file")),
|
|
33
|
+
is_COD_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_COD_customer")),
|
|
34
|
+
has_delivered_order: Types::Boolean.schema(default: true, allows_null: filtered_keys.exclude?("has_delivered_order")),
|
|
35
|
+
is_phone_verified: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_phone_verified")),
|
|
36
|
+
is_fraudulent_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_fraudulent_customer")),
|
|
37
|
+
reward_program_enrolled: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("reward_program_enrolled")),
|
|
38
|
+
|
|
39
|
+
account_creation_date: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("account_creation_date")),
|
|
40
|
+
platform_account_creation_date: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("platform_account_creation_date")),
|
|
41
|
+
date_of_first_transaction: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("date_of_first_transaction")),
|
|
42
|
+
last_order_date: Types::Date.schema(allows_null: filtered_keys.exclude?("last_order_date")),
|
|
43
|
+
|
|
44
|
+
order_count_last3months: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("order_count_last3months")),
|
|
45
|
+
total_order_count: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("total_order_count")),
|
|
46
|
+
reward_program_points: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("reward_program_points")),
|
|
47
|
+
total_ltv: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("total_ltv")),
|
|
48
|
+
order_amount_last3months: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("order_amount_last3months")),
|
|
49
|
+
last_order_amount: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("last_order_amount"))
|
|
50
|
+
},
|
|
51
|
+
required: REQUIRED_KEYS
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
# rubocop:enable Metrics/AbcSize
|
|
55
|
+
|
|
56
|
+
def self.filtered_keys
|
|
57
|
+
@filtered_keys ||= begin
|
|
58
|
+
optional_keys = (checkout_optional_keys[:risk_assessment] || []).map(&:to_s)
|
|
59
|
+
|
|
60
|
+
REQUIRED_KEYS - optional_keys
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Boolean
|
|
5
|
+
def self.schema(default: nil, allows_null: false)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["boolean", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
default: default
|
|
10
|
+
}.compact
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Date
|
|
5
|
+
def self.schema(allows_null: false, default: nil)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["string", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
pattern: "^\\d{2}-\\d{2}-\\d{4}$",
|
|
10
|
+
default: default,
|
|
11
|
+
maxLength: 10
|
|
12
|
+
}.compact
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Enum
|
|
5
|
+
def self.schema(values:, default: nil, allows_null: false)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
enum: allows_null ? [*values, nil] : values,
|
|
9
|
+
default: default
|
|
10
|
+
}.compact
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Float
|
|
5
|
+
def self.schema(allows_null: false, min: nil, max: nil)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["number", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
minimum: min,
|
|
10
|
+
maximum: max
|
|
11
|
+
}.compact
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Integer
|
|
5
|
+
def self.schema(allows_null: false, min: nil, max: nil, default: nil)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["integer", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
minimum: min,
|
|
10
|
+
maximum: max,
|
|
11
|
+
default: default
|
|
12
|
+
}.compact
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module String
|
|
5
|
+
def self.schema(allows_null: false, max_length: nil, default: nil)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["string", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
minLength: allows_null ? 0 : 1,
|
|
10
|
+
maxLength: max_length,
|
|
11
|
+
default: default
|
|
12
|
+
}.compact
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def schema
|
|
16
|
+
Tamara::JsonSchemas::Types::String.schema
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Url
|
|
5
|
+
def self.schema(allows_null: false)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["string", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
pattern: URI::DEFAULT_PARSER.make_regexp
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Types
|
|
4
|
+
module Uuid
|
|
5
|
+
def self.schema(allows_null: false)
|
|
6
|
+
{
|
|
7
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
8
|
+
type: ["string", (allows_null ? "null" : nil)].compact,
|
|
9
|
+
pattern: "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def schema
|
|
14
|
+
Tamara::JsonSchemas::Types::Uuid.schema
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Validator
|
|
4
|
+
ERROR_MESSAGES = {
|
|
5
|
+
Pattern: "%{property} has invalid format",
|
|
6
|
+
Type: "%{property} must be a %{type}",
|
|
7
|
+
Required: "%{property} is required",
|
|
8
|
+
Minimum: "%{property} is too small",
|
|
9
|
+
Maximum: "%{property} is too large",
|
|
10
|
+
MinLength: "%{property} is too short",
|
|
11
|
+
MaxLength: "%{property} is too long",
|
|
12
|
+
Format: "%{property} has invalid format",
|
|
13
|
+
AnyOf: "%{property} has invalid value",
|
|
14
|
+
Enum: "%{property} must be one of: %{allowed_values}"
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
def validate_params!
|
|
18
|
+
JSON::Validator.validate!(schema, api_params)
|
|
19
|
+
rescue JSON::Schema::ValidationError => e
|
|
20
|
+
handle_validation_error(e)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def handle_validation_error(error)
|
|
26
|
+
error_key = normalize_error_key(error)
|
|
27
|
+
property = extract_property_name(error)
|
|
28
|
+
error_params = extract_error_params(error)
|
|
29
|
+
|
|
30
|
+
raise InvalidRequestError.new(
|
|
31
|
+
format_error_message(error_key, property, error_params),
|
|
32
|
+
error.message
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def normalize_error_key(error)
|
|
37
|
+
error.failed_attribute.to_s
|
|
38
|
+
.split("::")
|
|
39
|
+
.last
|
|
40
|
+
.delete_suffix("Attribute")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def extract_property_name(error)
|
|
44
|
+
path = error.message[/'#\/([^']+)'/i, 1]
|
|
45
|
+
path&.humanize || "Field"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def extract_error_params(error)
|
|
49
|
+
schema_data = error.schema.instance_variable_get(:@schema)
|
|
50
|
+
{
|
|
51
|
+
type: schema_data["type"],
|
|
52
|
+
pattern: schema_data["pattern"],
|
|
53
|
+
allowed_values: Array(schema_data["enum"])&.join(", ")
|
|
54
|
+
}.compact
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def format_error_message(error_key, property, error_params)
|
|
58
|
+
format(
|
|
59
|
+
ERROR_MESSAGES.fetch(error_key.to_sym, "%{property} is invalid"),
|
|
60
|
+
property: property,
|
|
61
|
+
**error_params
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module Webhook
|
|
4
|
+
include Validator
|
|
5
|
+
|
|
6
|
+
ORDER = "order".freeze
|
|
7
|
+
DISPUTE = "dispute".freeze
|
|
8
|
+
|
|
9
|
+
TYPES = [ORDER, DISPUTE].freeze
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def schema
|
|
14
|
+
{
|
|
15
|
+
"$schema": "http://json-schema.org/draft-06/schema",
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
type: Types::Enum.schema(values: TYPES),
|
|
19
|
+
events: {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: {
|
|
22
|
+
type: "string"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
url: Types::Url.schema
|
|
26
|
+
},
|
|
27
|
+
required: %w[type events url],
|
|
28
|
+
oneOf: Tamara::JsonSchemas::WebhookEvent.schema
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Tamara
|
|
2
|
+
module JsonSchemas
|
|
3
|
+
module WebhookEvent
|
|
4
|
+
EVENTS = {
|
|
5
|
+
Tamara::JsonSchemas::Webhook::ORDER =>
|
|
6
|
+
%w[order_approved order_authorised order_canceled order_updated order_captured order_refunded].freeze,
|
|
7
|
+
Tamara::JsonSchemas::Webhook::DISPUTE =>
|
|
8
|
+
%w[OrderDisputeAwaitingMerchantResponse OrderDisputeClosedMerchantAcceptedClaim
|
|
9
|
+
OrderDisputeClosedTamaraAcceptedClaim OrderDisputeClosedTamaraAcceptedAndMerchantRefundedClaim
|
|
10
|
+
OrderDisputeClosedClaimCancelled OrderDisputeWasUpdated].freeze
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
def self.schema
|
|
14
|
+
[
|
|
15
|
+
{
|
|
16
|
+
properties: {
|
|
17
|
+
type: { const: Tamara::JsonSchemas::Webhook::ORDER },
|
|
18
|
+
events: {
|
|
19
|
+
type: "array",
|
|
20
|
+
items: Types::Enum.schema(values: EVENTS[Tamara::JsonSchemas::Webhook::ORDER])
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
properties: {
|
|
26
|
+
type: { const: Tamara::JsonSchemas::Webhook::DISPUTE },
|
|
27
|
+
events: {
|
|
28
|
+
type: "array",
|
|
29
|
+
items: Types::Enum.schema(values: EVENTS[Tamara::JsonSchemas::Webhook::DISPUTE])
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/tamara.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require "logger"
|
|
2
|
+
require "active_support"
|
|
3
|
+
require "active_support/core_ext"
|
|
4
|
+
require "faraday"
|
|
5
|
+
require "json-schema"
|
|
6
|
+
|
|
7
|
+
require_relative "tamara/version"
|
|
8
|
+
|
|
9
|
+
# API resource support classes
|
|
10
|
+
require "tamara/errors"
|
|
11
|
+
require "tamara/configuration"
|
|
12
|
+
|
|
13
|
+
# JSON schemas
|
|
14
|
+
require "tamara/json_schemas/checkout_optional_keys"
|
|
15
|
+
require "tamara/json_schemas/validator"
|
|
16
|
+
|
|
17
|
+
# Primitive types
|
|
18
|
+
require "tamara/json_schemas/types/boolean"
|
|
19
|
+
require "tamara/json_schemas/types/date"
|
|
20
|
+
require "tamara/json_schemas/types/enum"
|
|
21
|
+
require "tamara/json_schemas/types/float"
|
|
22
|
+
require "tamara/json_schemas/types/integer"
|
|
23
|
+
require "tamara/json_schemas/types/string"
|
|
24
|
+
require "tamara/json_schemas/types/url"
|
|
25
|
+
require "tamara/json_schemas/types/uuid"
|
|
26
|
+
|
|
27
|
+
require "tamara/json_schemas/address"
|
|
28
|
+
require "tamara/json_schemas/amount"
|
|
29
|
+
require "tamara/json_schemas/consumer"
|
|
30
|
+
require "tamara/json_schemas/discount"
|
|
31
|
+
require "tamara/json_schemas/item"
|
|
32
|
+
require "tamara/json_schemas/merchant_url"
|
|
33
|
+
require "tamara/json_schemas/orders/cancel"
|
|
34
|
+
require "tamara/json_schemas/orders/create"
|
|
35
|
+
require "tamara/json_schemas/payments/capture"
|
|
36
|
+
require "tamara/json_schemas/payment_options/check"
|
|
37
|
+
require "tamara/json_schemas/payment_types"
|
|
38
|
+
require "tamara/json_schemas/risk_assessment"
|
|
39
|
+
require "tamara/json_schemas/webhook"
|
|
40
|
+
require "tamara/json_schemas/webhook_event"
|
|
41
|
+
|
|
42
|
+
# API operations
|
|
43
|
+
require "tamara/api/request"
|
|
44
|
+
require "tamara/api/application_service"
|
|
45
|
+
require "tamara/api/api_token"
|
|
46
|
+
require "tamara/api/orders/authorize"
|
|
47
|
+
require "tamara/api/orders/cancel"
|
|
48
|
+
require "tamara/api/orders/create"
|
|
49
|
+
require "tamara/api/orders/details/merchant_order"
|
|
50
|
+
require "tamara/api/orders/details/tamara_order"
|
|
51
|
+
require "tamara/api/payment_options/check"
|
|
52
|
+
require "tamara/api/payments/capture"
|
|
53
|
+
require "tamara/api/orders"
|
|
54
|
+
require "tamara/api/payments"
|
|
55
|
+
require "tamara/api/payment_options"
|
|
56
|
+
require "tamara/api/payment_types"
|
|
57
|
+
require "tamara/api/signature"
|
|
58
|
+
require "tamara/api/webhooks"
|
|
59
|
+
|
|
60
|
+
module Tamara
|
|
61
|
+
SANDBOX_URI = "https://api-sandbox.tamara.co".freeze
|
|
62
|
+
PRODUCTION_URI = "https://api.tamara.co".freeze
|
|
63
|
+
|
|
64
|
+
COUNTRY_CODES = %w[SA AE BH KW OM].freeze
|
|
65
|
+
|
|
66
|
+
class << self
|
|
67
|
+
attr_accessor :api_token, :notification_token, :public_key
|
|
68
|
+
|
|
69
|
+
def base_uri
|
|
70
|
+
if defined?(Rails) && Rails.respond_to?(:env)
|
|
71
|
+
Rails.env.production? ? PRODUCTION_URI : SANDBOX_URI
|
|
72
|
+
else
|
|
73
|
+
SANDBOX_URI
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def checkout_uri
|
|
78
|
+
"#{base_uri}/checkout"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def orders_uri
|
|
82
|
+
"#{base_uri}/orders"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def payments_uri
|
|
86
|
+
"#{base_uri}/payments"
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def webhooks_uri
|
|
90
|
+
"#{base_uri}/webhooks"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def configure
|
|
94
|
+
yield configuration
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def configuration
|
|
98
|
+
@configuration ||= Configuration.new
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
data/sig/tamara.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tamara
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Youssef Ossama
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-03-12 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.2'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '7.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '5.2'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '7.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: concurrent-ruby
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.2.2
|
|
40
|
+
type: :runtime
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 1.2.2
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: faraday
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.10.3
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 1.10.3
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: json-schema
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 4.3.1
|
|
68
|
+
type: :runtime
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 4.3.1
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: jwt
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 2.2.1
|
|
82
|
+
type: :runtime
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 2.2.1
|
|
89
|
+
description:
|
|
90
|
+
email:
|
|
91
|
+
- y.ossama@qoyod.com
|
|
92
|
+
executables: []
|
|
93
|
+
extensions: []
|
|
94
|
+
extra_rdoc_files: []
|
|
95
|
+
files:
|
|
96
|
+
- ".rubocop.yml"
|
|
97
|
+
- ".rubocop_todo.yml"
|
|
98
|
+
- ".ruby-version"
|
|
99
|
+
- CHANGELOG.md
|
|
100
|
+
- Gemfile
|
|
101
|
+
- Gemfile.lock
|
|
102
|
+
- Guardfile
|
|
103
|
+
- LICENSE.txt
|
|
104
|
+
- README.md
|
|
105
|
+
- Rakefile
|
|
106
|
+
- lib/generators/tamara/install_generator.rb
|
|
107
|
+
- lib/generators/tamara/templates/tamara.rb
|
|
108
|
+
- lib/tamara.rb
|
|
109
|
+
- lib/tamara/api/api_token.rb
|
|
110
|
+
- lib/tamara/api/application_service.rb
|
|
111
|
+
- lib/tamara/api/orders.rb
|
|
112
|
+
- lib/tamara/api/orders/authorize.rb
|
|
113
|
+
- lib/tamara/api/orders/cancel.rb
|
|
114
|
+
- lib/tamara/api/orders/create.rb
|
|
115
|
+
- lib/tamara/api/orders/details/merchant_order.rb
|
|
116
|
+
- lib/tamara/api/orders/details/tamara_order.rb
|
|
117
|
+
- lib/tamara/api/payment_options.rb
|
|
118
|
+
- lib/tamara/api/payment_options/check.rb
|
|
119
|
+
- lib/tamara/api/payment_types.rb
|
|
120
|
+
- lib/tamara/api/payments.rb
|
|
121
|
+
- lib/tamara/api/payments/capture.rb
|
|
122
|
+
- lib/tamara/api/request.rb
|
|
123
|
+
- lib/tamara/api/signature.rb
|
|
124
|
+
- lib/tamara/api/webhooks.rb
|
|
125
|
+
- lib/tamara/configuration.rb
|
|
126
|
+
- lib/tamara/errors.rb
|
|
127
|
+
- lib/tamara/hmac.rb
|
|
128
|
+
- lib/tamara/json_schemas/address.rb
|
|
129
|
+
- lib/tamara/json_schemas/amount.rb
|
|
130
|
+
- lib/tamara/json_schemas/checkout_optional_keys.rb
|
|
131
|
+
- lib/tamara/json_schemas/consumer.rb
|
|
132
|
+
- lib/tamara/json_schemas/discount.rb
|
|
133
|
+
- lib/tamara/json_schemas/item.rb
|
|
134
|
+
- lib/tamara/json_schemas/merchant_url.rb
|
|
135
|
+
- lib/tamara/json_schemas/orders/cancel.rb
|
|
136
|
+
- lib/tamara/json_schemas/orders/create.rb
|
|
137
|
+
- lib/tamara/json_schemas/payment_options/check.rb
|
|
138
|
+
- lib/tamara/json_schemas/payment_types.rb
|
|
139
|
+
- lib/tamara/json_schemas/payments/capture.rb
|
|
140
|
+
- lib/tamara/json_schemas/risk_assessment.rb
|
|
141
|
+
- lib/tamara/json_schemas/types/boolean.rb
|
|
142
|
+
- lib/tamara/json_schemas/types/date.rb
|
|
143
|
+
- lib/tamara/json_schemas/types/enum.rb
|
|
144
|
+
- lib/tamara/json_schemas/types/float.rb
|
|
145
|
+
- lib/tamara/json_schemas/types/integer.rb
|
|
146
|
+
- lib/tamara/json_schemas/types/string.rb
|
|
147
|
+
- lib/tamara/json_schemas/types/url.rb
|
|
148
|
+
- lib/tamara/json_schemas/types/uuid.rb
|
|
149
|
+
- lib/tamara/json_schemas/validator.rb
|
|
150
|
+
- lib/tamara/json_schemas/webhook.rb
|
|
151
|
+
- lib/tamara/json_schemas/webhook_event.rb
|
|
152
|
+
- lib/tamara/version.rb
|
|
153
|
+
- sig/tamara.rbs
|
|
154
|
+
homepage: https://github.com/autocloud/tamara-rails
|
|
155
|
+
licenses:
|
|
156
|
+
- MIT
|
|
157
|
+
metadata:
|
|
158
|
+
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
|
+
rubygems_mfa_required: 'true'
|
|
162
|
+
post_install_message:
|
|
163
|
+
rdoc_options: []
|
|
164
|
+
require_paths:
|
|
165
|
+
- lib
|
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
|
+
requirements:
|
|
168
|
+
- - ">="
|
|
169
|
+
- !ruby/object:Gem::Version
|
|
170
|
+
version: 2.6.1
|
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
|
+
requirements:
|
|
173
|
+
- - ">="
|
|
174
|
+
- !ruby/object:Gem::Version
|
|
175
|
+
version: '0'
|
|
176
|
+
requirements: []
|
|
177
|
+
rubygems_version: 3.2.3
|
|
178
|
+
signing_key:
|
|
179
|
+
specification_version: 4
|
|
180
|
+
summary: Rails integration for Tamara payment solution.
|
|
181
|
+
test_files: []
|