diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-03-31 18:00:22 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-03-31 18:00:22 +0200 |
| commit | e6ca7a484d9cc213fb00c34ebf7cb55ace892c04 (patch) | |
| tree | e885d823c224d55503286b1dab207fcc7c5c68d1 /src/IOL.VippsEcommerce/Models/VippsConfiguration.cs | |
| download | dotnet-vipps-ecommerce-e6ca7a484d9cc213fb00c34ebf7cb55ace892c04.tar.xz dotnet-vipps-ecommerce-e6ca7a484d9cc213fb00c34ebf7cb55ace892c04.zip | |
Initial commit
Diffstat (limited to 'src/IOL.VippsEcommerce/Models/VippsConfiguration.cs')
| -rw-r--r-- | src/IOL.VippsEcommerce/Models/VippsConfiguration.cs | 130 |
1 files changed, 130 insertions, 0 deletions
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 +{ + /// <summary> + /// Configuration fields for the vipps api and integration. + /// </summary> + public class VippsConfiguration + { + /// <summary> + /// Url for the vipps api. + /// <example>https://apitest.vipps.no</example> + /// <example>https://api.vipps.no</example> + /// <para>Corresponding environment variable name: VIPPS_API_URL</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_API_URL)] + public string ApiUrl { get; set; } + + /// <summary> + /// Client ID for the merchant (the "username") + /// <para>Corresponding environment variable name: VIPPS_CLIENT_ID</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_ID)] + public string ClientId { get; set; } + + /// <summary> + /// Client Secret for the merchant (the "password") + /// <para>Corresponding environment variable name: VIPPS_CLIENT_SECRET</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_SECRET)] + public string ClientSecret { get; set; } + + /// <summary> + /// Primary subscription key for the API product. The primary subscription key take precedence over the secondary subscription key. + /// <para>Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_PRIMARY</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_PRIMARY)] + public string PrimarySubscriptionKey { get; set; } + + /// <summary> + /// Secondary subscription key for the API product. The primary subscription key take precedence over the secondary subscription key. + /// <para>Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_SECONDARY</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_SECONDARY)] + public string SecondarySubscriptionKey { get; set; } + + /// <summary> + /// The Merchant Serial Number (MSN) is a unique id for the sale unit that this payment is made for. + /// <para>Corresponding environment variable name: VIPPS_MSN</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_MSN)] + public string MerchantSerialNumber { get; set; } + + /// <summary> + /// The name of the ecommerce solution. One word in lowercase letters is good. + /// <para>Corresponding environment variable name: VIPPS_SYSTEM_NAME</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_NAME)] + public string SystemName { get; set; } + + /// <summary> + /// The version number of the ecommerce solution. + /// <para>Corresponding environment variable name: VIPPS_SYSTEM_VERSION</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_VERSION)] + public string SystemVersion { get; set; } + + /// <summary> + /// The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + /// <para>Corresponding environment variable name: VIPPS_SYSTEM_PLUGIN_NAME</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_NAME)] + public string SystemPluginName { get; set; } + + /// <summary> + /// The version number of the ecommerce plugin (if applicable). + /// <para>Corresponding environment variable name: VIPPS_SYSTEM_PLUGIN_VERSION</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_VERSION)] + public string SystemPluginVersion { get; set; } + + /// <summary> + /// Optional path to a writable directory wherein a credential cache file can be placed. + /// <para>Corresponding environment variable name: VIPPS_CACHE_PATH</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CACHE_PATH)] + public string CredentialsCacheFilePath { get; set; } + + /// <summary> + /// Optional key for AES encryption of the credential cache file. + /// <para>Corresponding environment variable name: VIPPS_CACHE_KEY</para> + /// </summary> + [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CACHE_KEY)] + public string CacheEncryptionKey { get; set; } + + /// <summary> + /// Use environment variables for configuration. + /// <para>If this is true, all requested properties are looked for in the environment.</para> + /// </summary> + public bool UseEnvironment { get; set; } + + /// <summary> + /// Get value from configuration, either from Dependency injection or from the environment. + /// </summary> + /// <param name="key">Configuration key.</param> + /// <param name="fallback">Fallback value if the key is not found or empty.</param> + /// <returns>A string containing the configuration value (or a fallback).</returns> + 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 |
