Class: RedsysRuby::Configuration
- Inherits:
-
Object
- Object
- RedsysRuby::Configuration
- Includes:
- ActiveModel::Model, ActiveModel::Validations
- Defined in:
- app/models/redsys_ruby/configuration.rb
Constant Summary collapse
- CONFIG_PATH =
Rails.root.join("config", "redsys.yml")
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#merchant_code ⇒ Object
Returns the value of attribute merchant_code.
-
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
-
#terminal ⇒ Object
Returns the value of attribute terminal.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'app/models/redsys_ruby/configuration.rb', line 8 def environment @environment end |
#merchant_code ⇒ Object
Returns the value of attribute merchant_code.
8 9 10 |
# File 'app/models/redsys_ruby/configuration.rb', line 8 def merchant_code @merchant_code end |
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
8 9 10 |
# File 'app/models/redsys_ruby/configuration.rb', line 8 def merchant_key @merchant_key end |
#terminal ⇒ Object
Returns the value of attribute terminal.
8 9 10 |
# File 'app/models/redsys_ruby/configuration.rb', line 8 def terminal @terminal end |
Class Method Details
.load ⇒ Object
17 18 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 |
# File 'app/models/redsys_ruby/configuration.rb', line 17 def self.load config = {} if File.exist?(CONFIG_PATH) config = (YAML.safe_load_file(CONFIG_PATH, aliases: true) || {})[Rails.env] || {} end creds = (Rails.application.credentials.redsys rescue {}) || {} env = ENV["REDSYS_ENVIRONMENT"] || creds[:environment] || config["environment"] || "test" key = ENV["REDSYS_MERCHANT_KEY"] || creds[:merchant_key] || config["merchant_key"] code = ENV["REDSYS_MERCHANT_CODE"] || creds[:merchant_code] || config["merchant_code"] term = ENV["REDSYS_TERMINAL"] || creds[:terminal] || config["terminal"] if env == "test" key ||= "sq7HjmUOBfKmC576ILgskD5srU870gJ7" code ||= "999008881" term ||= "001" end new( merchant_key: key, merchant_code: code, terminal: term, environment: env ) end |
Instance Method Details
#attributes ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/models/redsys_ruby/configuration.rb', line 66 def attributes { "merchant_key" => merchant_key, "merchant_code" => merchant_code, "terminal" => terminal, "environment" => environment } end |
#merchant_key_from_secure_source? ⇒ Boolean
45 46 47 |
# File 'app/models/redsys_ruby/configuration.rb', line 45 def merchant_key_from_secure_source? ENV["REDSYS_MERCHANT_KEY"].present? || (Rails.application.credentials.redsys&.dig(:merchant_key).present? rescue false) end |
#save ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/redsys_ruby/configuration.rb', line 49 def save return false unless valid? config_data = {} if File.exist?(CONFIG_PATH) config_data = YAML.safe_load_file(CONFIG_PATH, aliases: true) || {} end # We exclude merchant_key from the YAML file for security reasons. # Secrets should be managed via environment variables or encrypted credentials. data_to_save = attributes.except("merchant_key") config_data[Rails.env] = data_to_save File.write(CONFIG_PATH, config_data.to_yaml) true end |