diff --git a/.gitignore b/.gitignore index 5eed833..0df093c 100644 --- a/.gitignore +++ b/.gitignore @@ -280,3 +280,6 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# JetBrains Rider files +.idea/ diff --git a/src/Pinch.SDK.WebSample/Controllers/BaseController.cs b/src/Pinch.SDK.WebSample/Controllers/BaseController.cs index 4364e6f..d3fd8c2 100644 --- a/src/Pinch.SDK.WebSample/Controllers/BaseController.cs +++ b/src/Pinch.SDK.WebSample/Controllers/BaseController.cs @@ -29,24 +29,23 @@ protected PinchApi GetApi() if (token != null) { - return new PinchApi(_settings.MerchantId, _settings.SecretKey, new PinchApiOptions(){ - IsLive = _settings.IsLive, - BaseUri = _settings.BaseUri, - AuthUri = _settings.AuthUri, - ApplicationId = _settings.ApplicationId, - AccessToken = token.AccessToken, - RefreshToken = token.RefreshToken, - ImpersonateMerchantId = ImpersonatedMerchantId - }); + return new PinchApi(_settings.MerchantId, _settings.SecretKey, new PinchApiOptions( + isLive: _settings.IsLive, + baseUri: _settings.BaseUri, + authUri: _settings.AuthUri, + applicationId: _settings.ApplicationId, + accessToken: token.AccessToken, + refreshToken: token.RefreshToken, + impersonateMerchantId: ImpersonatedMerchantId + )); } - return new PinchApi(_settings.MerchantId, _settings.SecretKey, new PinchApiOptions() - { - IsLive = _settings.IsLive, - BaseUri = _settings.BaseUri, - AuthUri = _settings.AuthUri, - ImpersonateMerchantId = ImpersonatedMerchantId - }); + return new PinchApi(_settings.MerchantId, _settings.SecretKey, new PinchApiOptions( + isLive: _settings.IsLive, + baseUri: _settings.BaseUri, + authUri: _settings.AuthUri, + impersonateMerchantId: ImpersonatedMerchantId + )); } } } diff --git a/src/Pinch.SDK/PinchApi.cs b/src/Pinch.SDK/PinchApi.cs index ccaad95..0329eeb 100644 --- a/src/Pinch.SDK/PinchApi.cs +++ b/src/Pinch.SDK/PinchApi.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Pinch.SDK.Agreements; @@ -77,9 +75,7 @@ public class PinchApi /// Your Secret Key /// Set to false to use the sandbox test system. Set to true to perform live production transactions. public PinchApi(string merchantId, string secretKey, bool isLive) - :this(merchantId, secretKey, new PinchApiOptions() { - IsLive = isLive - }) + :this(merchantId, secretKey, new PinchApiOptions(isLive: isLive)) { } @@ -93,22 +89,6 @@ public PinchApi(string merchantId, string secretKey, bool isLive) public PinchApi(string merchantId, string secretKey, PinchApiOptions options, Func httpClientFactory = null) { _httpClientFactory = httpClientFactory; - - options.ApiVersion = !string.IsNullOrEmpty(options.ApiVersion) - ? options.ApiVersion - : Settings.LatestApiVersion; - - if (!string.IsNullOrEmpty(options.BaseUri)) - { - options.BaseUri = $"{options.BaseUri.TrimEnd('/')}/{(options.IsLive ? "live" : "test")}/"; - } - else - { - options.BaseUri = options.IsLive ? Settings.ApiBaseUri_Production : Settings.ApiBaseUri_Test; - } - - options.AuthUri = !string.IsNullOrEmpty(options.AuthUri) ? options.AuthUri : Settings.AuthBaseUri_Production; - _secretKey = secretKey; _clientId = merchantId; _accessToken = options.AccessToken; diff --git a/src/Pinch.SDK/PinchApiOptions.cs b/src/Pinch.SDK/PinchApiOptions.cs index 83ed229..49cea9d 100644 --- a/src/Pinch.SDK/PinchApiOptions.cs +++ b/src/Pinch.SDK/PinchApiOptions.cs @@ -1,39 +1,71 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Pinch.SDK { public class PinchApiOptions { - public bool IsLive { get; set; } - public string BaseUri { get; set; } - public string AuthUri { get; set; } - public string AccessToken { get; set; } - public string RefreshToken { get; set; } - public string ApplicationId { get; set; } + public PinchApiOptions( + bool? isLive = null, + string baseUri = null, + string authUri = null, + string accessToken = null, + string refreshToken = null, + string applicationId = null, + string apiVersion = null, + string impersonateMerchantId = null, + int? webhookVerificationClockSkewThreshold = null, + List additionalScopes = null) + { + IsLive = isLive ?? false; + ApiVersion = !string.IsNullOrEmpty(apiVersion) + ? apiVersion + : Settings.LatestApiVersion; + + if (!string.IsNullOrEmpty(baseUri)) + { + BaseUri = $"{baseUri.TrimEnd('/')}/{(IsLive ? "live" : "test")}/"; + } + else + { + BaseUri = IsLive ? Settings.ApiBaseUri_Production : Settings.ApiBaseUri_Test; + } + + AuthUri = !string.IsNullOrEmpty(authUri) ? authUri : Settings.AuthBaseUri_Production; + AccessToken = accessToken; + RefreshToken = refreshToken; + ApplicationId = applicationId; + ImpersonateMerchantId = impersonateMerchantId; + WebhookVerificationClockSkewThreshold = webhookVerificationClockSkewThreshold ?? 300; // Defaults to 5 minutes + AdditionalScopes = additionalScopes; + } + + public bool IsLive { get; } + public string BaseUri { get; } + public string AuthUri { get; } + public string AccessToken { get; } + public string RefreshToken { get; } + public string ApplicationId { get; } /// /// Set this to specify which version of the API you have coded against. Omitting this in the SDK is fine as we'll /// use the most recent version. Used for backwards compatibility. /// - public string ApiVersion { get; set; } + public string ApiVersion { get; } /// /// Set this Merchant ID to impersonate a different merchant. /// - public string ImpersonateMerchantId { get; set; } + public string ImpersonateMerchantId { get; } /// /// The maximum difference in seconds between the current time and the webhook timestamp. /// Used to verify authenticity of webhook requests and to avoid replay attacks. /// - public int WebhookVerificationClockSkewThreshold { get; set; } = 300; // 5 minutes + public int WebhookVerificationClockSkewThreshold { get; } /// /// List of additional scopes to request /// - public List AdditionalScopes { get; set; } + public List AdditionalScopes { get; } } }