-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from pajohns/master
Resolve issue #45 - PinchApiOptions to be readonly
- Loading branch information
Showing
4 changed files
with
65 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,3 +280,6 @@ $RECYCLE.BIN/ | |
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# JetBrains Rider files | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> 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; } | ||
|
||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public string ApiVersion { get; set; } | ||
public string ApiVersion { get; } | ||
|
||
/// <summary> | ||
/// Set this Merchant ID to impersonate a different merchant. | ||
/// </summary> | ||
public string ImpersonateMerchantId { get; set; } | ||
public string ImpersonateMerchantId { get; } | ||
|
||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public int WebhookVerificationClockSkewThreshold { get; set; } = 300; // 5 minutes | ||
public int WebhookVerificationClockSkewThreshold { get; } | ||
|
||
/// <summary> | ||
/// List of additional scopes to request | ||
/// </summary> | ||
public List<string> AdditionalScopes { get; set; } | ||
public List<string> AdditionalScopes { get; } | ||
} | ||
} |