Skip to content

Commit

Permalink
Amazon Pay SDK (.NET) 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
akshitaWaldia committed Apr 4, 2023
1 parent f1e7913 commit 094aea6
Show file tree
Hide file tree
Showing 51 changed files with 2,285 additions and 182 deletions.
21 changes: 21 additions & 0 deletions Amazon.Pay.API.SDK.Tests/ApiConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ public void CanInstantiateApiConfiguration()
payConfig.PrivateKey.Should().StartWith("-----BEGIN RSA");
}

[Test]
public void CanInstantiateApiConfigurationWithAlgorithm()
{
var payConfig = new ApiConfiguration
(
region: Region.UnitedStates,
environment: Environment.Sandbox,
publicKeyId: "foo",
privateKey: "-----BEGIN RSA PRIVATE KEY-----", // fake a private key ..);
algorithm: AmazonSignatureAlgorithm.V2
);
Assert.NotNull(payConfig);
Assert.AreEqual(Region.UnitedStates, payConfig.Region);
Assert.AreEqual(Environment.Sandbox, payConfig.Environment);
Assert.AreEqual("foo", payConfig.PublicKeyId);
Assert.AreEqual(3, payConfig.MaxRetries);
Assert.AreEqual(Constants.ApiVersion, payConfig.ApiVersion);
payConfig.PrivateKey.Should().StartWith("-----BEGIN RSA");
Assert.AreEqual(AmazonSignatureAlgorithm.V2, payConfig.Algorithm);
}

[Test]
public void CanSetMaxRetries()
{
Expand Down
226 changes: 142 additions & 84 deletions Amazon.Pay.API.SDK.Tests/ApiUrlBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Amazon.Pay.API.Tests
public class ApiUrlBuilderTests
{
private ApiUrlBuilder apiUrlBuilder;
private ApiUrlBuilder apiUrlBuilderWithAlgorithm;
private ApiConfiguration payConfig;
private ApiConfiguration payConfigWithAlgorithm;
// Fake Public keys
private const string livePublicKeyId = "LIVE-XXXXXXXXXXXXXXXXXXXXXXXX";
private const string sandboxPublicKeyId = "SANDBOX-XXXXXXXXXXXXXXXXXXXXXXXX";
Expand All @@ -25,130 +27,71 @@ public void SetUp()
publicKeyId: "foo",
privateKey: "-----BEGIN RSA PRIVATE KEY-----" // fake a private key ..);
);

payConfigWithAlgorithm = new ApiConfiguration
(
region: Region.Europe,
environment: Environment.Live,
publicKeyId: "foo",
privateKey: "-----BEGIN RSA PRIVATE KEY-----", // fake a private key ..);
algorithm: AmazonSignatureAlgorithm.V2
);
}

[Test]
public void GetApiEndPointBaseUrlForUnitedStatesLive()
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Live;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/live/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
GetApiEndPointBaseUrlForUnitedStatesLive(payConfig);
GetApiEndPointBaseUrlForUnitedStatesLive(payConfigWithAlgorithm);
}

[Test]
public void GetApiEndPointBaseUrlForUnitedStatesSandbox()
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
GetApiEndPointBaseUrlForUnitedStatesSandbox(payConfig);
GetApiEndPointBaseUrlForUnitedStatesSandbox(payConfigWithAlgorithm);
}

[Test]
public void GetApiEndPointBaseUrlForEuropeSandbox()
{
// arrange
payConfig.Region = Region.Europe;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.eu/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
GetApiEndPointBaseUrlForEuropeSandbox(payConfig);
GetApiEndPointBaseUrlForEuropeSandbox(payConfigWithAlgorithm);
}

[Test]
public void GetApiEndPointBaseUrlForJapanSandbox()
{
// arrange
payConfig.Region = Region.Japan;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.jp/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
GetApiEndPointBaseUrlForJapanSandbox(payConfig);
GetApiEndPointBaseUrlForJapanSandbox(payConfigWithAlgorithm);
}

[Test]
public void GetFullPathForInStoreApiService()
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/in-store/merchantScan/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.InStore, Constants.Resources.InStore.MerchantScan);

// assert
Assert.AreEqual(expectedURL, actualURL);
GetFullPathForInStoreApiService(payConfig);
GetFullPathForInStoreApiService(payConfigWithAlgorithm);
}

[Test]
public void GetFullPathForDeliveryTrackerApiService()
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/deliveryTrackers/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.Default, Constants.Resources.DeliveryTracker);

// assert
Assert.AreEqual(expectedURL, actualURL);
GetFullPathForDeliveryTrackerApiService(payConfig);
GetFullPathForDeliveryTrackerApiService(payConfigWithAlgorithm);
}

[Test]
public void GetFullPathForTokenExchangeApi()
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/authorizationTokens/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.Default, Constants.Resources.TokenExchange);

// assert
Assert.AreEqual(expectedURL, actualURL);
GetFullPathForTokenExchangeApi(payConfig);
GetFullPathForTokenExchangeApi(payConfigWithAlgorithm);
}

[Test]
public void GetApiUnifiedEndPointBaseUrlForUnitedStates()
{
string expectedURL = "https://pay-api.amazon.com/";

// Scenario 1 : Testing Unified endpoint base URL by passing Live specific PublicKeyId for UnitedStates
VerifyUnifiedEndpointBaseURL(Region.UnitedStates, livePublicKeyId, expectedURL);

// Scenario 2 : Testing Unified endpoint base URL by passing Sandbox specific PublicKeyId for UnitedStates
VerifyUnifiedEndpointBaseURL(Region.UnitedStates, sandboxPublicKeyId, expectedURL);
GetFullPathForTokenExchangeApi(payConfig);
GetFullPathForTokenExchangeApi(payConfigWithAlgorithm);
}

[Test]
Expand Down Expand Up @@ -181,14 +124,19 @@ public void VerifyUnifiedEndpointBaseURL(Region region, string publicKeyId, stri
// Configuration
payConfig.Region = region;
payConfig.PublicKeyId = publicKeyId;
payConfigWithAlgorithm.Region = region;
payConfigWithAlgorithm.PublicKeyId = publicKeyId;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
apiUrlBuilderWithAlgorithm = new ApiUrlBuilder(payConfigWithAlgorithm);

// Building URL
Uri expectedURL = new Uri(url);
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();
Uri actualURLWithAlgorithm = apiUrlBuilderWithAlgorithm.GetApiEndPointBaseUrl();

// Assertion
Assert.AreEqual(expectedURL, actualURL);
Assert.AreEqual(expectedURL, actualURLWithAlgorithm);
}

[Test]
Expand Down Expand Up @@ -281,14 +229,124 @@ public void VerifyUnifiedEndpointFullPath(Region region, string publicKeyId, str
// Configuration
payConfig.Region = region;
payConfig.PublicKeyId = publicKeyId;
payConfigWithAlgorithm.Region = region;
payConfigWithAlgorithm.PublicKeyId = publicKeyId;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
apiUrlBuilderWithAlgorithm = new ApiUrlBuilder(payConfigWithAlgorithm);

// Building URL
Uri expectedURL = new Uri(url);
Uri actualURL = apiUrlBuilder.BuildFullApiPath(apiService, resource);
Uri actualURLWithAlgorithm = apiUrlBuilderWithAlgorithm.BuildFullApiPath(apiService, resource);

// Assertion
Assert.AreEqual(expectedURL, actualURL);
Assert.AreEqual(expectedURL, actualURLWithAlgorithm);
}

public void GetApiEndPointBaseUrlForUnitedStatesLive(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Live;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/live/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetApiEndPointBaseUrlForUnitedStatesSandbox(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetApiEndPointBaseUrlForEuropeSandbox(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.Europe;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.eu/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetApiEndPointBaseUrlForJapanSandbox(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.Japan;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.jp/sandbox/");

// act
Uri actualURL = apiUrlBuilder.GetApiEndPointBaseUrl();

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetFullPathForInStoreApiService(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/in-store/merchantScan/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.InStore, Constants.Resources.InStore.MerchantScan);

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetFullPathForDeliveryTrackerApiService(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/deliveryTrackers/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.Default, Constants.Resources.DeliveryTracker);

// assert
Assert.AreEqual(expectedURL, actualURL);
}

public void GetFullPathForTokenExchangeApi(ApiConfiguration payConfig)
{
// arrange
payConfig.Region = Region.UnitedStates;
payConfig.Environment = Environment.Sandbox;
apiUrlBuilder = new ApiUrlBuilder(payConfig);
Uri expectedURL = new Uri("https://pay-api.amazon.com/sandbox/v2/authorizationTokens/");

// act
Uri actualURL = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.Default, Constants.Resources.TokenExchange);

// assert
Assert.AreEqual(expectedURL, actualURL);
}
}
}
Loading

0 comments on commit 094aea6

Please sign in to comment.