From e6ca7a484d9cc213fb00c34ebf7cb55ace892c04 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 31 Mar 2021 18:00:22 +0200 Subject: Initial commit --- .../Models/VippsConfiguration.cs | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/IOL.VippsEcommerce/Models/VippsConfiguration.cs (limited to 'src/IOL.VippsEcommerce/Models/VippsConfiguration.cs') diff --git a/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs b/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs new file mode 100644 index 0000000..5411ebc --- /dev/null +++ b/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs @@ -0,0 +1,130 @@ +using System; + +namespace IOL.VippsEcommerce.Models +{ + /// + /// Configuration fields for the vipps api and integration. + /// + public class VippsConfiguration + { + /// + /// Url for the vipps api. + /// https://apitest.vipps.no + /// https://api.vipps.no + /// Corresponding environment variable name: VIPPS_API_URL + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_API_URL)] + public string ApiUrl { get; set; } + + /// + /// Client ID for the merchant (the "username") + /// Corresponding environment variable name: VIPPS_CLIENT_ID + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_ID)] + public string ClientId { get; set; } + + /// + /// Client Secret for the merchant (the "password") + /// Corresponding environment variable name: VIPPS_CLIENT_SECRET + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_SECRET)] + public string ClientSecret { get; set; } + + /// + /// Primary subscription key for the API product. The primary subscription key take precedence over the secondary subscription key. + /// Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_PRIMARY + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_PRIMARY)] + public string PrimarySubscriptionKey { get; set; } + + /// + /// Secondary subscription key for the API product. The primary subscription key take precedence over the secondary subscription key. + /// Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_SECONDARY + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_SECONDARY)] + public string SecondarySubscriptionKey { get; set; } + + /// + /// The Merchant Serial Number (MSN) is a unique id for the sale unit that this payment is made for. + /// Corresponding environment variable name: VIPPS_MSN + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_MSN)] + public string MerchantSerialNumber { get; set; } + + /// + /// The name of the ecommerce solution. One word in lowercase letters is good. + /// Corresponding environment variable name: VIPPS_SYSTEM_NAME + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_NAME)] + public string SystemName { get; set; } + + /// + /// The version number of the ecommerce solution. + /// Corresponding environment variable name: VIPPS_SYSTEM_VERSION + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_VERSION)] + public string SystemVersion { get; set; } + + /// + /// The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + /// Corresponding environment variable name: VIPPS_SYSTEM_PLUGIN_NAME + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_NAME)] + public string SystemPluginName { get; set; } + + /// + /// The version number of the ecommerce plugin (if applicable). + /// Corresponding environment variable name: VIPPS_SYSTEM_PLUGIN_VERSION + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_VERSION)] + public string SystemPluginVersion { get; set; } + + /// + /// Optional path to a writable directory wherein a credential cache file can be placed. + /// Corresponding environment variable name: VIPPS_CACHE_PATH + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CACHE_PATH)] + public string CredentialsCacheFilePath { get; set; } + + /// + /// Optional key for AES encryption of the credential cache file. + /// Corresponding environment variable name: VIPPS_CACHE_KEY + /// + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CACHE_KEY)] + public string CacheEncryptionKey { get; set; } + + /// + /// Use environment variables for configuration. + /// If this is true, all requested properties are looked for in the environment. + /// + public bool UseEnvironment { get; set; } + + /// + /// Get value from configuration, either from Dependency injection or from the environment. + /// + /// Configuration key. + /// Fallback value if the key is not found or empty. + /// A string containing the configuration value (or a fallback). + public string GetValue(string key, string fallback = default) { + if (UseEnvironment) { + return Environment.GetEnvironmentVariable(key) ?? fallback; + } + + foreach (var prop in typeof(VippsConfiguration).GetProperties()) { + foreach (var attribute in prop.CustomAttributes) { + foreach (var argument in attribute.ConstructorArguments) { + if (argument.Value as string == key) { + var value = prop.GetValue(this, null)?.ToString(); +#if DEBUG + Console.WriteLine("Key: " + key + " Value: " + value); +#endif + return value; + } + } + } + } + + return default; + } + } +} \ No newline at end of file -- cgit v1.3