summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2021-04-18 23:26:06 +0200
committerivarlovlie <git@ivarlovlie.no>2021-04-18 23:26:06 +0200
commit84ccd406ed7584bcedb71dca68113a58e9072f82 (patch)
treeac4d3bcaf074d2c25beaa421b41859a815b66709 /src
parent1426d12bc26bdfad06d8ac8118d43c3a066e303d (diff)
downloaddotnet-vipps-ecommerce-84ccd406ed7584bcedb71dca68113a58e9072f82.tar.xz
dotnet-vipps-ecommerce-84ccd406ed7584bcedb71dca68113a58e9072f82.zip
Rename VippsConfigurationKeyNames.cs internally, formatting
Diffstat (limited to 'src')
-rw-r--r--src/IOL.VippsEcommerce.Tests/ConfigurationTests.cs3
-rw-r--r--src/IOL.VippsEcommerce.Tests/Helpers.cs2
-rw-r--r--src/IOL.VippsEcommerce/Helpers.cs13
-rw-r--r--src/IOL.VippsEcommerce/IVippsEcommerceService.cs40
-rw-r--r--src/IOL.VippsEcommerce/Models/VippsConfiguration.cs36
-rw-r--r--src/IOL.VippsEcommerce/Models/VippsConfigurationKeyNames.cs26
-rw-r--r--src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs25
-rw-r--r--src/IOL.VippsEcommerce/VippsEcommerceService.cs148
8 files changed, 146 insertions, 147 deletions
diff --git a/src/IOL.VippsEcommerce.Tests/ConfigurationTests.cs b/src/IOL.VippsEcommerce.Tests/ConfigurationTests.cs
index aa05a7d..41c0342 100644
--- a/src/IOL.VippsEcommerce.Tests/ConfigurationTests.cs
+++ b/src/IOL.VippsEcommerce.Tests/ConfigurationTests.cs
@@ -1,5 +1,4 @@
using IOL.VippsEcommerce.Models;
-using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
@@ -51,4 +50,4 @@ namespace IOL.VippsEcommerce.Tests
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce.Tests/Helpers.cs b/src/IOL.VippsEcommerce.Tests/Helpers.cs
index 9f89c1a..6c70cd8 100644
--- a/src/IOL.VippsEcommerce.Tests/Helpers.cs
+++ b/src/IOL.VippsEcommerce.Tests/Helpers.cs
@@ -19,4 +19,4 @@ namespace IOL.VippsEcommerce.Tests
return vippsEcommerceService;
}
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/Helpers.cs b/src/IOL.VippsEcommerce/Helpers.cs
index 8d6fb50..f7645a5 100644
--- a/src/IOL.VippsEcommerce/Helpers.cs
+++ b/src/IOL.VippsEcommerce/Helpers.cs
@@ -16,10 +16,9 @@ namespace IOL.VippsEcommerce
public static bool IsDirectoryWritable(this string dirPath, bool throwIfFails = false) {
try {
- using (var fs = File.Create(
- Path.Combine(dirPath, Path.GetRandomFileName()),
- 1,
- FileOptions.DeleteOnClose)
+ using (var fs = File.Create(Path.Combine(dirPath, Path.GetRandomFileName()),
+ 1,
+ FileOptions.DeleteOnClose)
) { }
return true;
@@ -41,7 +40,7 @@ namespace IOL.VippsEcommerce
using var encryptor = aes.CreateEncryptor(key, iv);
var cipherText = encryptor
- .TransformFinalBlock(plainText, 0, plainText.Length);
+ .TransformFinalBlock(plainText, 0, plainText.Length);
var result = new byte[iv.Length + cipherText.Length];
iv.CopyTo(result, 0);
@@ -67,7 +66,7 @@ namespace IOL.VippsEcommerce
using var decryptor = aes.CreateDecryptor(key, iv);
var decryptedBytes = decryptor
- .TransformFinalBlock(cipherText, 0, cipherText.Length);
+ .TransformFinalBlock(cipherText, 0, cipherText.Length);
return Encoding.UTF8.GetString(decryptedBytes);
}
@@ -83,4 +82,4 @@ namespace IOL.VippsEcommerce
return randomBytes;
}
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/IVippsEcommerceService.cs b/src/IOL.VippsEcommerce/IVippsEcommerceService.cs
index e21514d..a93080b 100644
--- a/src/IOL.VippsEcommerce/IVippsEcommerceService.cs
+++ b/src/IOL.VippsEcommerce/IVippsEcommerceService.cs
@@ -10,43 +10,43 @@ namespace IOL.VippsEcommerce
public VippsConfiguration Configuration { get; }
public Task<VippsInitiatePaymentResponse> InitiatePaymentAsync(
- VippsInitiatePaymentRequest payload,
- CancellationToken ct = default
+ VippsInitiatePaymentRequest payload,
+ CancellationToken ct = default
);
public Task<VippsPaymentActionResponse> CapturePaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
);
public Task<VippsPaymentActionResponse> CancelPaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
);
public Task<VippsPaymentActionResponse> AuthorizePaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
);
public Task<VippsPaymentActionResponse> RefundPaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
);
public Task<bool> ForceApprovePaymentAsync(
- string orderId,
- VippsForceApproveRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsForceApproveRequest payload,
+ CancellationToken ct = default
);
public Task<VippsGetPaymentDetailsResponse> GetPaymentDetailsAsync(
- string orderId,
- CancellationToken ct = default
+ string orderId,
+ CancellationToken ct = default
);
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs b/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs
index 2fcc91a..584ff2b 100644
--- a/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs
+++ b/src/IOL.VippsEcommerce/Models/VippsConfiguration.cs
@@ -13,21 +13,21 @@ namespace IOL.VippsEcommerce.Models
/// <example>https://api.vipps.no</example>
/// <para>Corresponding environment variable name: VIPPS_API_URL</para>
/// </summary>
- [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_API_URL)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.API_URL)]
public string ApiUrl { get; set; }
/// <summary>
/// Client ID for the merchant (the "username"). This property is required.
/// <para>Corresponding environment variable name: VIPPS_CLIENT_ID</para>
/// </summary>
- [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_ID)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.CLIENT_ID)]
public string ClientId { get; set; }
/// <summary>
/// Client Secret for the merchant (the "password"). This property is required.
/// <para>Corresponding environment variable name: VIPPS_CLIENT_SECRET</para>
/// </summary>
- [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_CLIENT_SECRET)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.CLIENT_SECRET)]
public string ClientSecret { get; set; }
/// <summary>
@@ -36,7 +36,7 @@ namespace IOL.VippsEcommerce.Models
/// <para>Either primary subscription key or secondary subscription key is required.</para>
/// <para>Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_PRIMARY</para>
/// </summary>
- [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_PRIMARY)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.SUBSCRIPTION_KEY_PRIMARY)]
public string PrimarySubscriptionKey { get; set; }
/// <summary>
@@ -45,56 +45,56 @@ namespace IOL.VippsEcommerce.Models
/// <para>Either primary subscription key or secondary subscription key is required.</para>
/// <para>Corresponding environment variable name: VIPPS_SUBSCRIPTION_KEY_SECONDARY</para>
/// </summary>
- [VippsConfigurationKeyName(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_SECONDARY)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.CACHE_PATH)]
public string CacheDirectoryPath { 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)]
+ [VippsConfigurationKeyName(VippsConfigurationKeyNames.CACHE_KEY)]
public string CacheEncryptionKey { get; set; }
/// <summary>
@@ -127,23 +127,23 @@ namespace IOL.VippsEcommerce.Models
/// <exception cref="ArgumentNullException">Throws if a required value is null or whitespace.</exception>
/// </summary>
public void Verify() {
- if (GetValue(VippsConfigurationKeyNames.VIPPS_API_URL).IsNullOrWhiteSpace()) {
+ if (GetValue(VippsConfigurationKeyNames.API_URL).IsNullOrWhiteSpace()) {
throw new ArgumentNullException(nameof(ApiUrl),
"VippsEcommerceService: ApiUrl is not provided in configuration.");
}
- if (GetValue(VippsConfigurationKeyNames.VIPPS_CLIENT_ID).IsNullOrWhiteSpace()) {
+ if (GetValue(VippsConfigurationKeyNames.CLIENT_ID).IsNullOrWhiteSpace()) {
throw new ArgumentNullException(nameof(ClientId),
"VippsEcommerceService: ClientId is not provided in configuration.");
}
- if (GetValue(VippsConfigurationKeyNames.VIPPS_CLIENT_SECRET).IsNullOrWhiteSpace()) {
+ if (GetValue(VippsConfigurationKeyNames.CLIENT_SECRET).IsNullOrWhiteSpace()) {
throw new ArgumentNullException(nameof(ClientSecret),
"VippsEcommerceService: ClientSecret is not provided in configuration.");
}
- if (GetValue(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_PRIMARY).IsNullOrWhiteSpace()
- && GetValue(VippsConfigurationKeyNames.VIPPS_SUBSCRIPTION_KEY_SECONDARY).IsNullOrWhiteSpace()) {
+ if (GetValue(VippsConfigurationKeyNames.SUBSCRIPTION_KEY_PRIMARY).IsNullOrWhiteSpace()
+ && GetValue(VippsConfigurationKeyNames.SUBSCRIPTION_KEY_SECONDARY).IsNullOrWhiteSpace()) {
throw new ArgumentNullException(nameof(PrimarySubscriptionKey)
+ nameof(SecondarySubscriptionKey),
"VippsEcommerceService: Neither PrimarySubscriptionKey nor SecondarySubscriptionKey was provided in configuration.");
@@ -182,4 +182,4 @@ namespace IOL.VippsEcommerce.Models
return default;
}
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/Models/VippsConfigurationKeyNames.cs b/src/IOL.VippsEcommerce/Models/VippsConfigurationKeyNames.cs
index 4b25c7d..c966762 100644
--- a/src/IOL.VippsEcommerce/Models/VippsConfigurationKeyNames.cs
+++ b/src/IOL.VippsEcommerce/Models/VippsConfigurationKeyNames.cs
@@ -2,17 +2,17 @@ namespace IOL.VippsEcommerce.Models
{
public static class VippsConfigurationKeyNames
{
- public const string VIPPS_API_URL = "VIPPS_API_URL";
- public const string VIPPS_CLIENT_ID = "VIPPS_CLIENT_ID";
- public const string VIPPS_CLIENT_SECRET = "VIPPS_CLIENT_SECRET";
- public const string VIPPS_SUBSCRIPTION_KEY_PRIMARY = "VIPPS_SUBSCRIPTION_KEY_PRIMARY";
- public const string VIPPS_SUBSCRIPTION_KEY_SECONDARY = "VIPPS_SUBSCRIPTION_KEY_SECONDARY";
- public const string VIPPS_MSN = "VIPPS_MSN";
- public const string VIPPS_SYSTEM_NAME = "VIPPS_SYSTEM_NAME";
- public const string VIPPS_SYSTEM_VERSION = "VIPPS_SYSTEM_VERSION";
- public const string VIPPS_SYSTEM_PLUGIN_NAME = "VIPPS_SYSTEM_PLUGIN_NAME";
- public const string VIPPS_SYSTEM_PLUGIN_VERSION = "VIPPS_SYSTEM_PLUGIN_VERSION";
- public const string VIPPS_CACHE_PATH = "VIPPS_CACHE_PATH";
- public const string VIPPS_CACHE_KEY = "VIPPS_CACHE_KEY";
+ public const string API_URL = "VIPPS_API_URL";
+ public const string CLIENT_ID = "VIPPS_CLIENT_ID";
+ public const string CLIENT_SECRET = "VIPPS_CLIENT_SECRET";
+ public const string SUBSCRIPTION_KEY_PRIMARY = "VIPPS_SUBSCRIPTION_KEY_PRIMARY";
+ public const string SUBSCRIPTION_KEY_SECONDARY = "VIPPS_SUBSCRIPTION_KEY_SECONDARY";
+ public const string MSN = "VIPPS_MSN";
+ public const string SYSTEM_NAME = "VIPPS_SYSTEM_NAME";
+ public const string SYSTEM_VERSION = "VIPPS_SYSTEM_VERSION";
+ public const string SYSTEM_PLUGIN_NAME = "VIPPS_SYSTEM_PLUGIN_NAME";
+ public const string SYSTEM_PLUGIN_VERSION = "VIPPS_SYSTEM_PLUGIN_VERSION";
+ public const string CACHE_PATH = "VIPPS_CACHE_PATH";
+ public const string CACHE_KEY = "VIPPS_CACHE_KEY";
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs b/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs
index 1637dc9..57f1833 100644
--- a/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs
+++ b/src/IOL.VippsEcommerce/ServiceCollectionExtensions.cs
@@ -13,13 +13,17 @@ namespace IOL.VippsEcommerce
/// <param name="configuration"></param>
/// <returns></returns>
public static IServiceCollection AddVippsEcommerceService(
- this IServiceCollection services,
- Action<VippsConfiguration> configuration
+ this IServiceCollection services,
+ Action<VippsConfiguration> configuration
) {
- if (services == null)
+ if (services == null) {
throw new ArgumentNullException(nameof(services));
- if (configuration == null)
+ }
+
+ if (configuration == null) {
throw new ArgumentNullException(nameof(configuration));
+ }
+
services.Configure(configuration);
services.AddHttpClient<IVippsEcommerceService, VippsEcommerceService>();
services.AddScoped<IVippsEcommerceService, VippsEcommerceService>();
@@ -31,16 +35,15 @@ namespace IOL.VippsEcommerce
/// </summary>
/// <param name="services">Servicecollection to add VippsEcommerceService to.</param>
/// <returns></returns>
- public static IServiceCollection AddVippsEcommerceService(
- this IServiceCollection services
- ) {
- if (services == null)
+ public static IServiceCollection AddVippsEcommerceService(this IServiceCollection services) {
+ if (services == null) {
throw new ArgumentNullException(nameof(services));
- services.Configure(new Action<VippsConfiguration>(o => o.ConfigurationMode =
- VippsConfigurationMode.ONLY_ENVIRONMENT));
+ }
+
+ services.Configure(new Action<VippsConfiguration>(o => o.ConfigurationMode = VippsConfigurationMode.ONLY_ENVIRONMENT));
services.AddHttpClient<IVippsEcommerceService, VippsEcommerceService>();
services.AddScoped<IVippsEcommerceService, VippsEcommerceService>();
return services;
}
}
-} \ No newline at end of file
+}
diff --git a/src/IOL.VippsEcommerce/VippsEcommerceService.cs b/src/IOL.VippsEcommerce/VippsEcommerceService.cs
index 291899d..91229ef 100644
--- a/src/IOL.VippsEcommerce/VippsEcommerceService.cs
+++ b/src/IOL.VippsEcommerce/VippsEcommerceService.cs
@@ -27,7 +27,7 @@ namespace IOL.VippsEcommerce
private readonly string _cacheDirectoryPath;
private readonly JsonSerializerOptions _requestJsonSerializerOptions = new() {
- IgnoreNullValues = true
+ IgnoreNullValues = true
};
private const string VIPPS_CACHE_FILE_NAME = "vipps_ecommerce_credentials.json";
@@ -36,52 +36,50 @@ namespace IOL.VippsEcommerce
public VippsConfiguration Configuration { get; }
public VippsEcommerceService(
- HttpClient client,
- ILogger<VippsEcommerceService> logger,
- IOptions<VippsConfiguration> options
+ HttpClient client,
+ ILogger<VippsEcommerceService> logger,
+ IOptions<VippsConfiguration> options
) {
Configuration = options.Value;
Configuration.Verify();
- var vippsApiUrl = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_API_URL);
+ var vippsApiUrl = Configuration.GetValue(VippsConfigurationKeyNames.API_URL);
client.BaseAddress = new Uri(vippsApiUrl);
_client = client;
_logger = logger;
- _vippsClientId = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_CLIENT_ID);
- _vippsClientSecret = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_CLIENT_SECRET);
+ _vippsClientId = Configuration.GetValue(VippsConfigurationKeyNames.CLIENT_ID);
+ _vippsClientSecret = Configuration.GetValue(VippsConfigurationKeyNames.CLIENT_SECRET);
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key",
- Configuration.GetValue(VippsConfigurationKeyNames
- .VIPPS_SUBSCRIPTION_KEY_PRIMARY)
- ?? Configuration.GetValue(VippsConfigurationKeyNames
- .VIPPS_SUBSCRIPTION_KEY_SECONDARY));
+ Configuration.GetValue(VippsConfigurationKeyNames.SUBSCRIPTION_KEY_PRIMARY)
+ ?? Configuration.GetValue(VippsConfigurationKeyNames.SUBSCRIPTION_KEY_SECONDARY));
- var msn = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_MSN);
+ var msn = Configuration.GetValue(VippsConfigurationKeyNames.MSN);
if (msn.IsPresent()) {
client.DefaultRequestHeaders.Add("Merchant-Serial-Number", msn);
_vippsMsn = msn;
}
- var systemName = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_SYSTEM_NAME);
+ var systemName = Configuration.GetValue(VippsConfigurationKeyNames.SYSTEM_NAME);
if (systemName.IsPresent()) {
client.DefaultRequestHeaders.Add("Vipps-System-Name", systemName);
}
- var systemVersion = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_SYSTEM_VERSION);
+ var systemVersion = Configuration.GetValue(VippsConfigurationKeyNames.SYSTEM_VERSION);
if (systemVersion.IsPresent()) {
client.DefaultRequestHeaders.Add("Vipps-System-Version", systemVersion);
}
- var systemPluginName = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_NAME);
+ var systemPluginName = Configuration.GetValue(VippsConfigurationKeyNames.SYSTEM_PLUGIN_NAME);
if (systemPluginName.IsPresent()) {
client.DefaultRequestHeaders.Add("Vipps-System-Plugin-Name", systemPluginName);
}
- var systemPluginVersion = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_SYSTEM_PLUGIN_VERSION);
+ var systemPluginVersion = Configuration.GetValue(VippsConfigurationKeyNames.SYSTEM_PLUGIN_VERSION);
if (systemPluginVersion.IsPresent()) {
client.DefaultRequestHeaders.Add("Vipps-System-Plugin-Version", systemPluginVersion);
}
- _cacheEncryptionKey = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_CACHE_KEY);
- _cacheDirectoryPath = Configuration.GetValue(VippsConfigurationKeyNames.VIPPS_CACHE_PATH);
+ _cacheEncryptionKey = Configuration.GetValue(VippsConfigurationKeyNames.CACHE_KEY);
+ _cacheDirectoryPath = Configuration.GetValue(VippsConfigurationKeyNames.CACHE_PATH);
if (_cacheDirectoryPath.IsPresent()) {
if (!_cacheDirectoryPath.IsDirectoryWritable()) {
_logger.LogError("Could not write to cache file directory ("
@@ -105,8 +103,8 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
private async Task<VippsAuthorizationTokenResponse> GetAuthorizationTokenAsync(
- bool forceRefresh = false,
- CancellationToken ct = default
+ bool forceRefresh = false,
+ CancellationToken ct = default
) {
if (!forceRefresh && _cacheDirectoryPath.IsPresent() && File.Exists(CacheFilePath)) {
var fileContents = await File.ReadAllTextAsync(CacheFilePath, ct);
@@ -120,7 +118,7 @@ namespace IOL.VippsEcommerce
try {
var decryptedContents = fileContents.DecryptWithAes(_cacheEncryptionKey);
credentials =
- JsonSerializer.Deserialize<VippsAuthorizationTokenResponse>(decryptedContents);
+ JsonSerializer.Deserialize<VippsAuthorizationTokenResponse>(decryptedContents);
} catch {
// ignored
}
@@ -141,15 +139,15 @@ namespace IOL.VippsEcommerce
}
var requestMessage = new HttpRequestMessage {
- Headers = {
- {
- "client_id", _vippsClientId
- }, {
- "client_secret", _vippsClientSecret
+ Headers = {
+ {
+ "client_id", _vippsClientId
+ }, {
+ "client_secret", _vippsClientSecret
+ },
},
- },
- RequestUri = new Uri(_client.BaseAddress + "accesstoken/get"),
- Method = HttpMethod.Post
+ RequestUri = new Uri(_client.BaseAddress + "accesstoken/get"),
+ Method = HttpMethod.Post
};
var response = await _client.SendAsync(requestMessage, ct);
@@ -160,8 +158,8 @@ namespace IOL.VippsEcommerce
if (_cacheDirectoryPath.IsPresent()) {
await File.WriteAllTextAsync(CacheFilePath,
_cacheEncryptionKey.IsPresent()
- ? credentials.EncryptWithAes(_cacheEncryptionKey)
- : credentials,
+ ? credentials.EncryptWithAes(_cacheEncryptionKey)
+ : credentials,
ct);
}
@@ -175,7 +173,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(GetAuthorizationTokenAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -201,13 +199,13 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsInitiatePaymentResponse> InitiatePaymentAsync(
- VippsInitiatePaymentRequest payload,
- CancellationToken ct = default
+ VippsInitiatePaymentRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
var response = await _client.PostAsJsonAsync("ecomm/v2/payments",
@@ -230,7 +228,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(InitiatePaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -254,20 +252,20 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsPaymentActionResponse> CapturePaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
if (payload.MerchantInfo?.MerchantSerialNumber.IsNullOrWhiteSpace() ?? false) {
payload.MerchantInfo = new TMerchantInfoPayment {
- MerchantSerialNumber = _vippsMsn
+ MerchantSerialNumber = _vippsMsn
};
}
@@ -290,7 +288,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(CapturePaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -312,19 +310,19 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsPaymentActionResponse> CancelPaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
if (payload.MerchantInfo?.MerchantSerialNumber.IsNullOrWhiteSpace() ?? false) {
payload.MerchantInfo = new TMerchantInfoPayment {
- MerchantSerialNumber = _vippsMsn
+ MerchantSerialNumber = _vippsMsn
};
}
@@ -347,7 +345,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(CancelPaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -367,19 +365,19 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsPaymentActionResponse> AuthorizePaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
if (payload.MerchantInfo?.MerchantSerialNumber.IsNullOrWhiteSpace() ?? false) {
payload.MerchantInfo = new TMerchantInfoPayment {
- MerchantSerialNumber = _vippsMsn
+ MerchantSerialNumber = _vippsMsn
};
}
@@ -402,7 +400,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(AuthorizePaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -426,19 +424,19 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsPaymentActionResponse> RefundPaymentAsync(
- string orderId,
- VippsPaymentActionRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsPaymentActionRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
if (payload.MerchantInfo?.MerchantSerialNumber.IsNullOrWhiteSpace() ?? false) {
payload.MerchantInfo = new TMerchantInfoPayment {
- MerchantSerialNumber = _vippsMsn
+ MerchantSerialNumber = _vippsMsn
};
}
@@ -460,7 +458,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(RefundPaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -483,22 +481,22 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<bool> ForceApprovePaymentAsync(
- string orderId,
- VippsForceApproveRequest payload,
- CancellationToken ct = default
+ string orderId,
+ VippsForceApproveRequest payload,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
var response =
- await _client.PostAsJsonAsync("ecomm/v2/integration-test/payments/" + orderId + "/approve",
- payload,
- _requestJsonSerializerOptions,
- ct);
+ await _client.PostAsJsonAsync("ecomm/v2/integration-test/payments/" + orderId + "/approve",
+ payload,
+ _requestJsonSerializerOptions,
+ ct);
try {
response.EnsureSuccessStatusCode();
@@ -514,7 +512,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(ForceApprovePaymentAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -533,13 +531,13 @@ namespace IOL.VippsEcommerce
/// <returns></returns>
/// <exception cref="HttpRequestException">Throws if the api returns unsuccessfully</exception>
public async Task<VippsGetPaymentDetailsResponse> GetPaymentDetailsAsync(
- string orderId,
- CancellationToken ct = default
+ string orderId,
+ CancellationToken ct = default
) {
if (_client.DefaultRequestHeaders.Authorization?.Parameter.IsNullOrWhiteSpace() ?? true) {
var credentials = await GetAuthorizationTokenAsync(false, ct);
_client.DefaultRequestHeaders.Authorization =
- new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
+ new AuthenticationHeaderValue("Bearer", credentials.AccessToken);
}
var response = await _client.GetAsync("ecomm/v2/payments/" + orderId + "/details", ct);
@@ -550,7 +548,7 @@ namespace IOL.VippsEcommerce
+ ": Successfully issued a request to "
+ response.RequestMessage?.RequestUri);
return await
- response.Content.ReadFromJsonAsync<VippsGetPaymentDetailsResponse>(cancellationToken: ct);
+ response.Content.ReadFromJsonAsync<VippsGetPaymentDetailsResponse>(cancellationToken: ct);
} catch (Exception e) {
var exception = new VippsRequestException(nameof(GetPaymentDetailsAsync) + " failed.", e);
if (e is not HttpRequestException) {
@@ -559,7 +557,7 @@ namespace IOL.VippsEcommerce
try {
exception.ErrorResponse =
- await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
+ await response.Content.ReadFromJsonAsync<VippsErrorResponse>(cancellationToken: ct);
_logger.LogError(nameof(GetPaymentDetailsAsync)
+ " Api error response: "
+ JsonSerializer.Serialize(response.Content));
@@ -571,4 +569,4 @@ namespace IOL.VippsEcommerce
}
}
}
-} \ No newline at end of file
+}