# Script to seed MF919-specific parameter definitions # Run with: mix run priv/repo/seeds/mf919_parameter_definitions.exs # # Prerequisite: mf919_parameter_categories.exs must have been run first so that # all mf919_* category codes are present in the database. Mix.Task.run("app.start") require Logger alias DaProductApp.Repo alias DaProductApp.ParameterManagement.{ParameterCategory, ParameterDefinition} # Helper: fetch a required category by code; halt with a clear error if missing. get_category! = fn code -> case Repo.get_by(ParameterCategory, code: code) do nil -> Logger.error( "Category '#{code}' not found. Run mf919_parameter_categories.exs first." ) System.halt(1) cat -> cat end end base_cat = get_category!.("mf919_base") merchant_cat = get_category!.("mf919_merchant") comm_cat = get_category!.("mf919_comm") trans_cat = get_category!.("mf919_transactions") print_cat = get_category!.("mf919_printing") pinpad_cat = get_category!.("mf919_pinpad") scanner_cat = get_category!.("mf919_scanner") security_cat = get_category!.("mf919_security") # --------------------------------------------------------------------------- # Parameter definitions # Format: {key, name, description, category, data_type, default_value, # is_required, validation_rules, display_order} # --------------------------------------------------------------------------- definitions = [ # --- Merchant overlay (per-terminal values, applied as overrides) --- { "MERCHANT_ID", "Merchant ID", "MID assigned to the terminal", merchant_cat.id, "string", nil, false, %{"max_length" => 15}, 1 }, { "TERMINAL_ID", "Terminal ID", "TID assigned to the terminal", merchant_cat.id, "string", nil, false, %{"max_length" => 8}, 2 }, { "BATCH_NO", "Batch Number", "Initial / current batch number for the terminal", merchant_cat.id, "string", "000001", false, %{"max_length" => 6, "pattern" => "^\\d{6}$"}, 3 }, # --- Base / Merchant Defaults --- { "BASE_MERCHANT_NAME", "Merchant Name", "Display name of the merchant shown on receipts", base_cat.id, "string", "Demo Merchant", false, %{"max_length" => 64}, 1 }, { "BASE_TRACE_NO", "Trace Number", "Starting transaction trace / sequence number", base_cat.id, "string", "000001", false, %{"max_length" => 6, "pattern" => "^\\d{1,6}$"}, 2 }, { "BASE_MAX_REFUND_AMOUNT", "Max Refund Amount", "Maximum refund amount in cents", base_cat.id, "integer", "1000000", false, %{"min" => 0}, 3 }, { "BASE_CURRENCY_CODE", "Currency Code", "ISO 4217 numeric currency code (e.g. 784 for AED, 840 for USD)", base_cat.id, "string", "784", false, %{"max_length" => 3, "pattern" => "^\\d{3}$"}, 4 }, { "BASE_MAX_TRANS_COUNT", "Max Transaction Count", "Maximum number of transactions stored in batch", base_cat.id, "integer", "500", false, %{"min" => 1, "max" => 9999}, 5 }, # --- PINPAD / External Device --- { "PINPAD_MASTER_KEY_INDEX", "PINPAD Master Key Index", "Index of the master key used by the PINPAD", pinpad_cat.id, "integer", "0", false, %{"min" => 0}, 1 }, { "PINPAD_ALGORITHM_TYPE", "PINPAD Algorithm Type", "Key derivation algorithm: 0 = DUKPT, 1 = MKSK", pinpad_cat.id, "select", "0", false, %{"options" => ["0", "1"]}, 2 }, { "PINPAD_TIMEOUT", "PINPAD Entry Timeout", "PIN entry timeout in seconds", pinpad_cat.id, "integer", "60", false, %{"min" => 1, "max" => 300}, 3 }, { "EXTERNAL_PINPAD_YSDK", "Enable YSDK PINPAD", "Enable YSDK external PINPAD integration (1 = YES, 0 = NO)", pinpad_cat.id, "boolean", "true", false, nil, 4 }, { "EXTERNAL_PINPAD", "Enable External PINPAD", "Enable external PINPAD hardware (1 = YES, 0 = NO)", pinpad_cat.id, "boolean", "false", false, nil, 5 }, { "EXTERNAL_PINPAD_CONNECT_MODE", "External PINPAD Connect Mode", "Connection mode: 0=Serial, 1=USB, 10=Dock Serial, 11=Dock USB1, 12=Dock USB2", pinpad_cat.id, "select", "0", false, %{"options" => ["0", "1", "10", "11", "12"]}, 6 }, # --- Printing --- { "PRINT_COUNT", "Print Count", "Number of receipt copies to print per transaction", print_cat.id, "integer", "2", false, %{"min" => 0, "max" => 9}, 1 }, { "PRINT_EXTERNAL", "Enable External Printer", "Use an external printer (1 = YES, 0 = NO)", print_cat.id, "boolean", "false", false, nil, 2 }, { "PRINT_EXTERNAL_CONNECT_MODE", "External Printer Connect Mode", "Connection mode: 0=Serial, 1=USB, 2=Bluetooth, 10=Dock Serial, 11=Dock USB1, 12=Dock USB2", print_cat.id, "select", "1", false, %{"options" => ["0", "1", "2", "10", "11", "12"]}, 3 }, { "PRINT_EXTERNAL_SERIAL_BAUDRATE", "External Printer Serial Baud Rate", "Baud rate for serial-connected external printer", print_cat.id, "integer", "115200", false, %{"min" => 1200}, 4 }, { "PRINT_REMARKS", "Print Remarks", "Custom footer text printed at the bottom of receipts", print_cat.id, "string", "Thank you, Visit Again", false, %{"max_length" => 128}, 5 }, # --- Transaction Toggles --- { "TRANS_SALE", "Enable Sale", "Allow sale transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 1 }, { "TRANS_VOID", "Enable Void", "Allow void transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 2 }, { "TRANS_REFUND", "Enable Refund", "Allow refund transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 3 }, { "TRANS_BALANCE", "Enable Balance Inquiry", "Allow balance inquiry transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 4 }, { "TRANS_PREAUTH", "Enable Pre-Auth", "Allow pre-authorisation transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 5 }, { "TRANS_MOBILE_PAY", "Enable Mobile Pay", "Allow mobile payment transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 6 }, { "TRANS_INSTALLMENT", "Enable Installment", "Allow installment payment transactions (1 = YES, 0 = NO)", trans_cat.id, "boolean", "true", false, nil, 7 }, # --- Communication --- { "COMM_USE_SSL", "Use SSL", "Enable SSL/TLS for host communication (1 = YES, 0 = NO)", comm_cat.id, "boolean", "false", false, nil, 1 }, { "COMM_TIMEOUT", "Communication Timeout", "Host communication timeout in seconds", comm_cat.id, "integer", "60", false, %{"min" => 1, "max" => 300}, 2 }, { "COMM_TPDU", "TPDU", "Transport Protocol Data Unit header value", comm_cat.id, "string", "6000782000", false, %{"max_length" => 20}, 3 }, { "COMM_SERVER_ADDRESS", "Server Address", "Host / acquirer server IP address or hostname", comm_cat.id, "string", "40.120.104.51", false, %{"max_length" => 255}, 4 }, { "COMM_PORT", "Server Port", "Host / acquirer server TCP port", comm_cat.id, "integer", "80", false, %{"min" => 1, "max" => 65535}, 5 }, { "COMM_NII", "NII", "Network International Identifier used in ISO 8583 messages", comm_cat.id, "string", "782", false, %{"max_length" => 3, "pattern" => "^\\d{1,3}$"}, 6 }, # --- Signature / Scanner --- { "ELECSIGN_IS_SUPPORT", "Enable Electronic Signature", "Support electronic signature capture (1 = YES, 0 = NO)", scanner_cat.id, "boolean", "false", false, nil, 1 }, { "SCAN_PRIORITY_SCANNER", "Priority Scanner", "Preferred scanner: 0 = Front, 1 = Back, 2 = External", scanner_cat.id, "select", "1", false, %{"options" => ["0", "1", "2"]}, 2 }, { "SCAN_EXTERN_CONNECT_MODE", "External Scanner Connect Mode", "Connection mode: 0=Serial, 1=USB, 10=Dock Serial, 11=Dock USB1, 12=Dock USB2", scanner_cat.id, "select", "0", false, %{"options" => ["0", "1", "10", "11", "12"]}, 3 }, { "SCAN_EXTERN_USB_WAIT_TIME", "External Scanner USB Wait Time", "Milliseconds to wait for USB scan box receipt completion", scanner_cat.id, "integer", "300", false, %{"min" => 0}, 4 }, { "SCAN_EXTERN_SERIAL_BAUDRATE", "External Scanner Serial Baud Rate", "Baud rate for serial-connected external scanner", scanner_cat.id, "integer", "115200", false, %{"min" => 1200}, 5 }, # --- Security / Operational Flags --- { "PASSWORD_ADMIN", "Admin Password", "Administrator access password for the device", security_cat.id, "string", "123456", false, %{"max_length" => 32}, 1 }, { "PASSWORD_SYSTEM_ADMIN", "System Admin Password", "System-level administrator password for the device", security_cat.id, "string", "000000", false, %{"max_length" => 32}, 2 }, { "PASSWORD_SECURITY", "Security Password", "Security access password for the device", security_cat.id, "string", "888888", false, %{"max_length" => 32}, 3 }, { "TOMS_FLY_PARAMETERS", "TOMS Fly Parameters", "Enable parameter update notification (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 4 }, { "TOMS_FLY_RECEIPT", "TOMS Fly Receipt", "Enable electronic receipt via TOMS (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 5 }, { "NFC_RECEIPT", "NFC / Digital Receipt", "Enable digital receipt delivery (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 6 }, { "OTHER_TIP_INPUT", "Enable Tip Input", "Support tip amount entry during a sale (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 7 }, { "OTHER_THRID_BILL_SHOW", "Third-Party Bill Result", "Show transaction result to third-party billing apps (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 8 }, { "OTHER_VOID_CARD", "Void Requires Card", "Require card tap/swipe to complete a void transaction (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 9 }, { "OTHER_VOID_PIN", "Void Requires PIN", "Require PIN entry to complete a void transaction (1 = YES, 0 = NO)", security_cat.id, "boolean", "false", false, nil, 10 } ] Enum.each(definitions, fn {key, name, description, category_id, data_type, default_value, is_required, validation_rules, display_order} -> case Repo.get_by(ParameterDefinition, key: key) do nil -> attrs = %{ key: key, name: name, description: description, category_id: category_id, data_type: data_type, default_value: default_value, is_required: is_required, validation_rules: validation_rules, display_order: display_order, is_active: true } changeset = ParameterDefinition.changeset(%ParameterDefinition{}, attrs) case Repo.insert(changeset) do {:ok, param} -> Logger.info("Created parameter definition: #{param.key} (ID: #{param.id})") {:error, reason} -> Logger.error("Failed to create parameter definition #{key}: #{inspect(reason)}") end existing -> Logger.info("Parameter definition already exists: #{existing.key} (ID: #{existing.id})") end end) Logger.info("MF919 parameter definitions seeding completed!")