Module: Tamara::JsonSchemas::RiskAssessment

Extended by:
CheckoutOptionalKeys
Defined in:
lib/tamara/json_schemas/risk_assessment.rb

Constant Summary collapse

GENDERS =
%w[Male Female].freeze
REQUIRED_KEYS =
%w[
  customer_age customer_dob customer_gender customer_nationality
  is_premium_customer is_existing_customer is_guest_user
  account_creation_date platform_account_creation_date
  date_of_first_transaction is_card_on_file is_COD_customer
  has_delivered_order is_phone_verified is_fraudulent_customer
  total_ltv total_order_count order_amount_last3months
  order_count_last3months last_order_date last_order_amount
  reward_program_enrolled reward_program_points
].freeze

Class Method Summary collapse

Methods included from CheckoutOptionalKeys

checkout_optional_keys

Class Method Details

.filtered_keysObject

rubocop:enable Metrics/AbcSize



56
57
58
59
60
61
62
# File 'lib/tamara/json_schemas/risk_assessment.rb', line 56

def self.filtered_keys
  @filtered_keys ||= begin
    optional_keys = (checkout_optional_keys[:risk_assessment] || []).map(&:to_s)

    REQUIRED_KEYS - optional_keys
  end
end

.schema(allows_null: false, params: nil) ⇒ Object

rubocop:disable Metrics/AbcSize



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tamara/json_schemas/risk_assessment.rb', line 19

def self.schema(allows_null: false, params: nil)
  @params = params
  {
    "$schema": "http://json-schema.org/draft-06/schema",
    type: ["object", (allows_null ? "null" : nil)].compact,
    properties: {
      customer_age: Types::Integer.schema(min: 1, default: 21, allows_null: filtered_keys.exclude?("customer_age")),
      customer_dob: Types::Date.schema(default: "01-12-2000", allows_null: filtered_keys.exclude?("customer_dob")),
      customer_gender: Types::Enum.schema(values: GENDERS, default: "Female", allows_null: filtered_keys.exclude?("customer_gender")),
      customer_nationality: Types::Enum.schema(values: COUNTRY_CODES, default: "SA", allows_null: filtered_keys.exclude?("customer_nationality")),
      is_premium_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_premium_customer")),
      is_existing_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_existing_customer")),
      is_guest_user: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_guest_user")),
      is_card_on_file: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_card_on_file")),
      is_COD_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_COD_customer")),
      has_delivered_order: Types::Boolean.schema(default: true, allows_null: filtered_keys.exclude?("has_delivered_order")),
      is_phone_verified: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_phone_verified")),
      is_fraudulent_customer: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("is_fraudulent_customer")),
      reward_program_enrolled: Types::Boolean.schema(default: false, allows_null: filtered_keys.exclude?("reward_program_enrolled")),

      account_creation_date: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("account_creation_date")),
      platform_account_creation_date: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("platform_account_creation_date")),
      date_of_first_transaction: Types::Date.schema(default: "12-06-2020", allows_null: filtered_keys.exclude?("date_of_first_transaction")),
      last_order_date: Types::Date.schema(allows_null: filtered_keys.exclude?("last_order_date")),

      order_count_last3months: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("order_count_last3months")),
      total_order_count: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("total_order_count")),
      reward_program_points: Types::Integer.schema(min: 0, allows_null: filtered_keys.exclude?("reward_program_points")),
      total_ltv: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("total_ltv")),
      order_amount_last3months: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("order_amount_last3months")),
      last_order_amount: Types::Float.schema(min: 0, allows_null: filtered_keys.exclude?("last_order_amount"))
    },
    required: REQUIRED_KEYS
  }
end