Skip to content

Commit

Permalink
Amazon Pay SDK (.NET) 2.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayan Kumar S committed Oct 18, 2023
1 parent c287d1b commit 92c1075
Show file tree
Hide file tree
Showing 31 changed files with 1,124 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using Amazon.Pay.API.WebStore.AccountManagement;
using Amazon.Pay.API.WebStore.Types;
using NUnit.Framework;

namespace Amazon.Pay.API.Tests.WebStore.AccountManagement
{
[TestFixture]
public class RegisterAmazonPayAccountRequestTests
{
[Test]
public void CanConstructWithAllPropertiesInitialized()
{
// act
var request = new RegisterAmazonPayAccountRequest(uniqueReferenceId: "ABCDEF1234", ledgerCurrency: LedgerCurrency.JPY);

// assert
Assert.IsNotNull(request);
Assert.IsNotNull(request.BusinessInfo);
Assert.IsNotNull(request.PrimaryContactPerson);
}

private RegisterAmazonPayAccountRequest CreateIndividualAccountRequest()
{
var request = new RegisterAmazonPayAccountRequest(uniqueReferenceId: "ABCDEF12345", ledgerCurrency: LedgerCurrency.JPY)
{
BusinessInfo = {
BusinessType = BusinessType.INDIVIDUAL,
CountryOfEstablishment = "JP",
BusinessLegalName = "TestingSubmerchant",
BusinessAddress = {
AddressLine1 = "450",
AddressLine2 = "Noda",
City = "香取市",
StateOrRegion = "千葉県",
PostalCode = "289-0314",
CountryCode = "JP"
}
}
};
return request;
}

private RegisterAmazonPayAccountRequest CreateCorporateAccountRequest()
{
var request = new RegisterAmazonPayAccountRequest(uniqueReferenceId: "ABCDEF12345", ledgerCurrency: LedgerCurrency.JPY)
{
BusinessInfo = {
BusinessType = BusinessType.CORPORATE,
CountryOfEstablishment = "JP",
BusinessLegalName = "TestingSubmerchant",
BusinessAddress = {
AddressLine1 = "450",
AddressLine2 = "Noda",
City = "香取市",
StateOrRegion = "千葉県",
PostalCode = "289-0314",
CountryCode = "JP"
}
}
};
return request;
}

private RegisterAmazonPayAccountRequest CreateCorporateAccountRequestWithPoc()
{
var request = CreateCorporateAccountRequest();
request.PrimaryContactPerson.PersonFullName = "Testing";
request.PrimaryContactPerson.ResidentialAddress.AddressLine1 = "621-4";
request.PrimaryContactPerson.ResidentialAddress.AddressLine2 = "Haramanda";
request.PrimaryContactPerson.ResidentialAddress.City = "Arao City";
request.PrimaryContactPerson.ResidentialAddress.StateOrRegion = "Kumamoto";
request.PrimaryContactPerson.ResidentialAddress.PostalCode = "836-0806";
request.PrimaryContactPerson.ResidentialAddress.CountryCode = "JP";
return request;
}

[Test]
public void CanConvertToJsonMinimal()
{
// arrange
var request = new RegisterAmazonPayAccountRequest(uniqueReferenceId: "ABCDEF1234", ledgerCurrency: LedgerCurrency.JPY);

// act
string json = request.ToJson();

// assert
Assert.AreEqual("{\"uniqueReferenceId\":\"ABCDEF1234\",\"ledgerCurrency\":\"JPY\",\"businessInfo\":{}}", json);
}

[Test]
public void RegisterAmazonPayAccountWithIndividualBusinessType()
{
// arrange
var request = CreateIndividualAccountRequest();

// act
string json = request.ToJson();

// assert
const string expectedJson = "{\"uniqueReferenceId\":\"ABCDEF12345\",\"ledgerCurrency\":\"JPY\",\"businessInfo\":{\"businessType\":\"INDIVIDUAL\",\"countryOfEstablishment\":\"JP\",\"businessLegalName\":\"TestingSubmerchant\",\"businessAddress\":{\"addressLine1\":\"450\",\"addressLine2\":\"Noda\",\"city\":\"香取市\",\"stateOrRegion\":\"千葉県\",\"postalCode\":\"289-0314\",\"countryCode\":\"JP\"}}}";
Assert.AreEqual(expectedJson, json);
}

[Test]
public void RegisterAmazonPayAccountWithCorporateBusinessTypeAndWithoutPoc()
{
// arrange
var request = CreateCorporateAccountRequest();

// act
string json = request.ToJson();

// assert
const string expectedJson = "{\"uniqueReferenceId\":\"ABCDEF12345\",\"ledgerCurrency\":\"JPY\",\"businessInfo\":{\"businessType\":\"CORPORATE\",\"countryOfEstablishment\":\"JP\",\"businessLegalName\":\"TestingSubmerchant\",\"businessAddress\":{\"addressLine1\":\"450\",\"addressLine2\":\"Noda\",\"city\":\"香取市\",\"stateOrRegion\":\"千葉県\",\"postalCode\":\"289-0314\",\"countryCode\":\"JP\"}}}";
Assert.AreEqual(expectedJson, json);
}

[Test]
public void RegisterAmazonPayAccountWithCorporateBusinessTypeAndPoc()
{
// arrange
var request = CreateCorporateAccountRequestWithPoc();

// act
string json = request.ToJson();

// assert
const string expectedJson = "{\"uniqueReferenceId\":\"ABCDEF12345\",\"ledgerCurrency\":\"JPY\",\"businessInfo\":{\"businessType\":\"CORPORATE\",\"countryOfEstablishment\":\"JP\",\"businessLegalName\":\"TestingSubmerchant\",\"businessAddress\":{\"addressLine1\":\"450\",\"addressLine2\":\"Noda\",\"city\":\"香取市\",\"stateOrRegion\":\"千葉県\",\"postalCode\":\"289-0314\",\"countryCode\":\"JP\"}},\"primaryContactPerson\":{\"personFullName\":\"Testing\",\"residentialAddress\":{\"addressLine1\":\"621-4\",\"addressLine2\":\"Haramanda\",\"city\":\"Arao City\",\"stateOrRegion\":\"Kumamoto\",\"postalCode\":\"836-0806\",\"countryCode\":\"JP\"}}}";
Assert.AreEqual(expectedJson, json);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Amazon.Pay.API.WebStore.AccountManagement;
using Amazon.Pay.API.WebStore.Types;
using NUnit.Framework;

namespace Amazon.Pay.API.Tests.WebStore.AccountManagement
{
[TestFixture]
public class UpdateAmazonPayAccountRequestTests
{
[Test]
public void CanConstructWithAllPropertiesInitialized()
{
// act
var request = new UpdateAmazonPayAccountRequest();

// assert
Assert.IsNotNull(request);
Assert.IsNotNull(request.BusinessInfo);
}

[Test]
public void CanConvertToJsonMinimal()
{
// arrange
var request = new UpdateAmazonPayAccountRequest();

// act
string json = request.ToJson();

// assert
Assert.AreEqual("{\"businessInfo\":{}}", json);
}

private UpdateAmazonPayAccountRequest CreateUpdatePayload()
{
var request = new UpdateAmazonPayAccountRequest()
{
BusinessInfo = {
BusinessAddress = {
AddressLine1 = "41",
AddressLine2 = "Nishigamo Kitaimaharacho",
City = "京都市",
StateOrRegion = "京都府",
PostalCode = "683-8821",
CountryCode = "JP"
}
}
};
return request;
}

[Test]
public void UpdateAmazonPayAccount()
{
// arrange
var request = CreateUpdatePayload();

// act
string json = request.ToJson();

// assert
const string expectedJson = "{\"businessInfo\":{\"businessAddress\":{\"addressLine1\":\"41\",\"addressLine2\":\"Nishigamo Kitaimaharacho\",\"city\":\"京都市\",\"stateOrRegion\":\"京都府\",\"postalCode\":\"683-8821\",\"countryCode\":\"JP\"}}}";

Assert.AreEqual(expectedJson, json);
}

[Test]
public void UpdateAmazonPayAccountWithPrimaryContactPerson()
{
// arrange
var request = CreateUpdatePayload();
request.BusinessInfo.BusinessType = BusinessType.CORPORATE;
request.BusinessInfo.CountryOfEstablishment = "JP";
request.BusinessInfo.BusinessLegalName = "TestingSubmerchant";
request.PrimaryContactPerson.DateOfBirth = "19971111";
request.PrimaryContactPerson.PersonFullName = "Test";

// act
string json = request.ToJson();

// assert
const string expectedJson = "{\"businessInfo\":{\"businessType\":\"CORPORATE\",\"countryOfEstablishment\":\"JP\",\"businessLegalName\":\"TestingSubmerchant\",\"businessAddress\":{\"addressLine1\":\"41\",\"addressLine2\":\"Nishigamo Kitaimaharacho\",\"city\":\"京都市\",\"stateOrRegion\":\"京都府\",\"postalCode\":\"683-8821\",\"countryCode\":\"JP\"}},\"primaryContactPerson\":{\"personFullName\":\"Test\",\"dateOfBirth\":\"19971111\"}}";
Assert.AreEqual(expectedJson, json);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,30 @@ public void CanConvertToJsonPaymentMethodOnFile()
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"paymentMethodOnFileMetadata\":{\"setupOnly\":true},\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\",\"checkoutResultReturnUrl\":\"https://example.com/return.html\"},\"paymentDetails\":{\"paymentIntent\":\"Confirm\"},\"chargePermissionType\":\"PaymentMethodOnFile\"}", json);
}

[Test]
public void CanConvertToJsonPaymentMethodOnFileForUpdateFlow()
{
// arrange
var request = new CreateCheckoutSessionRequest
(
checkoutReviewReturnUrl: "https://example.com/review.html",
storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
chargePermissionId: "B01-0000000-0000000"
);
request.WebCheckoutDetails.CheckoutResultReturnUrl = "https://example.com/return.html";
request.ChargePermissionType = ChargePermissionType.PaymentMethodOnFile;
request.PaymentMethodOnFileMetadata.SetupOnly = true;
request.PaymentDetails.PaymentIntent = PaymentIntent.Confirm;
request.PaymentDetails.CanHandlePendingAuthorization = false;

// act
string json = request.ToJson();
string json2 = request.ToJson();

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"paymentMethodOnFileMetadata\":{\"setupOnly\":true},\"chargePermissionId\":\"B01-0000000-0000000\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\",\"checkoutResultReturnUrl\":\"https://example.com/return.html\"},\"paymentDetails\":{\"paymentIntent\":\"Confirm\",\"canHandlePendingAuthorization\":false},\"chargePermissionType\":\"PaymentMethodOnFile\"}", json);
}

[Test]
public void AdditionalPaymentButton()
Expand Down Expand Up @@ -253,7 +277,7 @@ public void AdditionalPaymentButton()

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"addressDetails\":{\"districtOrCounty\":\"Manhattan\",\"name\":\"Paul Smith\",\"addressLine1\":\"9999 First Avenue\",\"city\":\"New York\",\"stateOrRegion\":\"NY\",\"postalCode\":\"10016\",\"countryCode\":\"US\",\"phoneNumber\":\"212555555\"},\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\",\"checkoutMode\":\"ProcessOrder\"},\"paymentDetails\":{\"paymentIntent\":\"AuthorizeWithCapture\",\"chargeAmount\":{\"amount\":10,\"currencyCode\":\"USD\"},\"presentmentCurrency\":\"USD\"},\"merchantMetadata\":{\"merchantReferenceId\":\"Merchant Ref ID\",\"merchantStoreName\":\"Store Name\",\"noteToBuyer\":\"Buyer Note\"}}", json);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"addressDetails\":{\"districtOrCounty\":\"Manhattan\",\"name\":\"Paul Smith\",\"phoneNumber\":\"212555555\",\"addressLine1\":\"9999 First Avenue\",\"city\":\"New York\",\"stateOrRegion\":\"NY\",\"postalCode\":\"10016\",\"countryCode\":\"US\"},\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\",\"checkoutMode\":\"ProcessOrder\"},\"paymentDetails\":{\"paymentIntent\":\"AuthorizeWithCapture\",\"chargeAmount\":{\"amount\":10,\"currencyCode\":\"USD\"},\"presentmentCurrency\":\"USD\"},\"merchantMetadata\":{\"merchantReferenceId\":\"Merchant Ref ID\",\"merchantStoreName\":\"Store Name\",\"noteToBuyer\":\"Buyer Note\"}}", json);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Amazon.Pay.API.Types;
using Amazon.Pay.API.WebStore.CheckoutSession;
using Amazon.Pay.API.WebStore.Types;
using NUnit.Framework;

namespace Amazon.Pay.API.Tests.WebStore.CheckoutSession
{
[TestFixture]
public class FinalizeCheckoutSessionRequestTests
{
[Test]
public void CanConvertToJsonMinimal()
{
// arrange
var request = new FinalizeCheckoutSessionRequest(10, Currency.USD, PaymentIntent.Confirm);

// act
string json = request.ToJson();

// assert
Assert.AreEqual("{\"paymentIntent\":\"Confirm\",\"chargeAmount\":{\"amount\":10,\"currencyCode\":\"USD\"}}", json);
}

[Test]
public void CanConstructWithAllPropertiesInitialized()
{
// act
var request = new FinalizeCheckoutSessionRequest(10, Currency.USD, PaymentIntent.Confirm);

// assert
Assert.IsNotNull(request);
Assert.IsNotNull(request.ShippingAddress);
Assert.IsNotNull(request.ChargeAmount);
Assert.IsNotNull(request.TotalOrderAmount);
Assert.IsNotNull(request.PaymentIntent);
}

[Test]
public void FinalizeCheckoutSessionResponseTest()
{
// arrange
var request = new FinalizeCheckoutSessionRequest(amount: 10, currency: Currency.USD, PaymentIntent.Confirm);
request.ShippingAddress.Name = "Susie Smith";
request.ShippingAddress.AddressLine1 = "10 Ditka Ave";
request.ShippingAddress.AddressLine2 = "Suite 2500";
request.ShippingAddress.City = "Chicago";
request.ShippingAddress.County = null;
request.ShippingAddress.District = null;
request.ShippingAddress.StateOrRegion = "IL";
request.ShippingAddress.PostalCode = "60602";
request.ShippingAddress.CountryCode = "US";
request.ShippingAddress.PhoneNumber = "800-000-0000";
request.TotalOrderAmount.Amount = 10;
request.TotalOrderAmount.CurrencyCode = Currency.USD;
request.CanHandlePendingAuthorization = false;

// act
string json = request.ToJson();
// assert
Assert.AreEqual("{\"paymentIntent\":\"Confirm\",\"canHandlePendingAuthorization\":false,\"shippingAddress\":{\"name\":\"Susie Smith\",\"phoneNumber\":\"800-000-0000\",\"addressLine1\":\"10 Ditka Ave\",\"addressLine2\":\"Suite 2500\",\"city\":\"Chicago\",\"stateOrRegion\":\"IL\",\"postalCode\":\"60602\",\"countryCode\":\"US\"},\"chargeAmount\":{\"amount\":10,\"currencyCode\":\"USD\"},\"totalOrderAmount\":{\"amount\":10,\"currencyCode\":\"USD\"}}", json);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.Generic;
using Amazon.Pay.API.WebStore.AccountManagement;
using Amazon.Pay.API.WebStore.Types;
using Amazon.Pay.API.WebStore.Interfaces;
using Moq;
using NUnit.Framework;

namespace Amazon.Pay.API.SDK.Tests.WebStore.Interfaces
{
// This is a test fixture to ensure that a method can be mocked and helps ensure it is on the interface.
[TestFixture]
public class IMerchantOnboardingClientTests
{
private Mock<IMerchantOnboardingClient> mockMerchantOnboardingClient;

[OneTimeSetUp]
public void Init()
{
this.mockMerchantOnboardingClient = new Mock<IMerchantOnboardingClient>(MockBehavior.Strict);
}

[SetUp]
public void Setup()
{
this.mockMerchantOnboardingClient.Reset();
}

// ------------ Testing the Merchant Onboarding & Account Management APIs ---------------

[Test]
public void RegisterAmazonPayAccountCanBeMocked()
{
var registerAmazonPayAccountResponse = new RegisterAmazonPayAccountResponse();
this.mockMerchantOnboardingClient.Setup(mwsc => mwsc.RegisterAmazonPayAccount(It.IsAny<RegisterAmazonPayAccountRequest>(), It.IsAny<Dictionary<string, string>>())).Returns(registerAmazonPayAccountResponse);

var result = this.mockMerchantOnboardingClient.Object.RegisterAmazonPayAccount(new RegisterAmazonPayAccountRequest("ABCD12345", LedgerCurrency.JPY), new Dictionary<string, string>());

Assert.That(result, Is.EqualTo(registerAmazonPayAccountResponse));
this.mockMerchantOnboardingClient.Verify(mwsc => mwsc.RegisterAmazonPayAccount(It.IsAny<RegisterAmazonPayAccountRequest>(), It.IsAny<Dictionary<string, string>>()), Times.Once);
}

[Test]
public void UpdateAmazonPayAccountCanBeMocked()
{
var updateAmazonPayAccountResponse = new UpdateAmazonPayAccountResponse();
this.mockMerchantOnboardingClient.Setup(mwsc => mwsc.UpdateAmazonPayAccount(It.IsAny<string>(), It.IsAny<UpdateAmazonPayAccountRequest>(), It.IsAny<Dictionary<string, string>>())).Returns(updateAmazonPayAccountResponse);

var result = this.mockMerchantOnboardingClient.Object.UpdateAmazonPayAccount("SessionId", new UpdateAmazonPayAccountRequest(), new Dictionary<string, string>());

Assert.That(result, Is.EqualTo(updateAmazonPayAccountResponse));
this.mockMerchantOnboardingClient.Verify(mwsc => mwsc.UpdateAmazonPayAccount(It.IsAny<string>(), It.IsAny<UpdateAmazonPayAccountRequest>(), It.IsAny<Dictionary<string, string>>()), Times.Once);
}

[Test]
public void DeleteAmazonPayAccountCanBeMocked()
{
var deleteAmazonPayAccountResponse = new DeleteAmazonPayAccountResponse();
this.mockMerchantOnboardingClient.Setup(mwsc => mwsc.DeleteAmazonPayAccount("merchantAccountId", It.IsAny<Dictionary<string, string>>())).Returns(deleteAmazonPayAccountResponse);

var result = this.mockMerchantOnboardingClient.Object.DeleteAmazonPayAccount("merchantAccountId", new Dictionary<string, string>());

Assert.That(result, Is.EqualTo(deleteAmazonPayAccountResponse));
this.mockMerchantOnboardingClient.Verify(mwsc => mwsc.DeleteAmazonPayAccount("merchantAccountId", It.IsAny<Dictionary<string, string>>()), Times.Once);
}
}
}
Loading

0 comments on commit 92c1075

Please sign in to comment.