using System; namespace IOL.VippsEcommerce.Models; /// /// Configuration fields for the vipps api and integration. /// public class VippsConfiguration { /// /// Url for the vipps api. This property is required. /// https://apitest.vipps.no /// https://api.vipps.no /// Corresponding environment variable name: VIPPS_API_URL /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.API_URL)] public string ApiUrl { get; set; } /// /// Client ID for the merchant (the "username"). This property is required. /// Corresponding environment variable name: VIPPS_CLIENT_ID /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.CLIENT_ID)] public string ClientId { get; set; } /// /// Client Secret for the merchant (the "password"). This property is required. /// Corresponding environment variable name: VIPPS_CLIENT_SECRET /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.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. /// Either primary subscription key or secondary subscription key is required. /// Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_PRIMARY /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.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. /// Either primary subscription key or secondary subscription key is required. /// Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_SECONDARY /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.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.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.SYSTEM_NAME)] public string SystemName { get; set; } /// /// The version number of the ecommerce solution. /// Corresponding environment variable name: VIPPS_SYSTEM_VERSION /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.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.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.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.CACHE_PATH)] public string CacheDirectoryPath { get; set; } /// /// Optional key for AES encryption of the credential cache file. /// Corresponding environment variable name: VIPPS_CACHE_KEY /// [VippsConfigurationKeyName(VippsConfigurationKeyNames.CACHE_KEY)] public string CacheEncryptionKey { get; set; } /// /// Ensure that the configuration can be used to issue requests to the vipps api. /// Throws if a required value is null or whitespace. /// public void Verify() { if (ApiUrl.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(ApiUrl), "VippsEcommerceService: ApiUrl is not provided in configuration."); } if (ClientId.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(ClientId), "VippsEcommerceService: ClientId is not provided in configuration."); } if (ClientSecret.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(ClientSecret), "VippsEcommerceService: ClientSecret is not provided in configuration."); } if (PrimarySubscriptionKey.IsNullOrWhiteSpace() && SecondarySubscriptionKey.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(PrimarySubscriptionKey) + nameof(SecondarySubscriptionKey), "VippsEcommerceService: Neither PrimarySubscriptionKey nor SecondarySubscriptionKey was provided in configuration."); } } }