Skip to content

Commit

Permalink
Amazon Pay SDK (.NET) 2.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Kumar committed Jun 12, 2024
1 parent 92c1075 commit 46f02d8
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 77 deletions.
171 changes: 104 additions & 67 deletions Amazon.Pay.API.SDK.Tests/WebStore/Charge/CreateChargeRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class CreateChargeRequestTests
[Test]
public void CanConstructWithAllPropertiesInitializedAsExpected()
{
// arrange
// Arrange
var chargePermissionId = "S02-7331650-8246451";

// act
// Act
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);

// assert
// Assert
Assert.IsNotNull(request);
Assert.IsNotNull(request.ChargePermissionId);
Assert.IsNotNull(request.ChargeAmount);
Expand All @@ -36,19 +36,19 @@ public void CanConstructWithAllPropertiesInitializedAsExpected()
[Test]
public void CanConvertToJsonMinimal()
{
// arrange
// Arrange
var chargePermissionId = "S02-7331650-8246451";
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"}}", json);

// verify object hasn't been corrupted
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);
// Act
string actualJson = request.ToJson();

// Expected JSON string
string expectedJson = "{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"}}";

// Assert
Assert.AreEqual(actualJson, expectedJson);

// Verify object hasn't been corrupted
request.ProviderMetadata.ProviderReferenceId = "foo";
request.SoftDescriptor = "foo";
request.CaptureNow = true;
Expand All @@ -63,72 +63,109 @@ public void CanConvertToJsonMinimal()
[Test]
public void CanConvertToJsonFull()
{
// arrange
// Arrange
var chargePermissionId = "S02-7331650-8246451";
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);
request.ProviderMetadata.ProviderReferenceId = "foo";
request.SoftDescriptor = "foo";
request.CaptureNow = true;
request.PlatformId = "My Platform Id";
request.CanHandlePendingAuthorization = true;

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo\"}}", json);
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR)
{
ProviderMetadata = new ProviderMetadata { ProviderReferenceId = "foo1" },
SoftDescriptor = "foo2",
CaptureNow = true,
PlatformId = "My Platform Id",
CanHandlePendingAuthorization = true
};

// Act
string actualJson = request.ToJson();

// Expected JSON string
string expectedJson = "{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo2\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo1\"}}";

// Assert
Assert.AreEqual(actualJson, expectedJson);
}

[Test]
public void CanConvertToJsonRecurring()
{
// arrange
// Arrange
var chargePermissionId = "S02-7331650-8246451";
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);
request.ProviderMetadata.ProviderReferenceId = "foo1";
request.SoftDescriptor = "foo2";
request.CaptureNow = true;
request.PlatformId = "My Platform Id";
request.CanHandlePendingAuthorization = true;
request.MerchantMetadata.MerchantReferenceId = "123abc!";
request.MerchantMetadata.MerchantStoreName = "My Store Name";
request.MerchantMetadata.NoteToBuyer = "My Note to Buyer";
request.MerchantMetadata.CustomInformation = "My Custom Info";

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo2\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo1\"},\"merchantMetadata\":{\"merchantReferenceId\":\"123abc!\",\"merchantStoreName\":\"My Store Name\",\"noteToBuyer\":\"My Note to Buyer\",\"customInformation\":\"My Custom Info\"}}", json);
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR)
{
ProviderMetadata = new ProviderMetadata { ProviderReferenceId = "foo1" },
SoftDescriptor = "foo2",
CaptureNow = true,
PlatformId = "My Platform Id",
CanHandlePendingAuthorization = true,
MerchantMetadata = new MerchantMetadata
{
MerchantReferenceId = "123abc!",
MerchantStoreName = "My Store Name",
NoteToBuyer = "My Note to Buyer",
CustomInformation = "My Custom Info",
}
};

// Act
string actualJson = request.ToJson();

// Expected JSON string
string expectedJson = "{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo2\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo1\"},\"merchantMetadata\":{\"merchantReferenceId\":\"123abc!\",\"merchantStoreName\":\"My Store Name\",\"noteToBuyer\":\"My Note to Buyer\",\"customInformation\":\"My Custom Info\"}}";

// Assert
Assert.AreEqual(actualJson, expectedJson);
}

[Test]
public void CanConvertToJsonPaymentMethodOnFile()
{
// arrange
// Arrange
var chargePermissionId = "S02-7331650-8246451";
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR);
request.ProviderMetadata.ProviderReferenceId = "foo";
request.SoftDescriptor = "foo";
request.CaptureNow = true;
request.PlatformId = "My Platform Id";
request.CanHandlePendingAuthorization = true;
request.ChargeInitiator = ChargeInitiator.CITR;
request.Channel = Channel.Web;

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo\"},\"chargeInitiator\":\"CITR\",\"channel\":\"Web\"}", json);
var request = new CreateChargeRequest(chargePermissionId, 12.99M, Currency.EUR)
{
ProviderMetadata = new ProviderMetadata { ProviderReferenceId = "foo" },
SoftDescriptor = "foo",
CaptureNow = true,
PlatformId = "My Platform Id",
CanHandlePendingAuthorization = true,
ChargeInitiator = ChargeInitiator.CITR,
Channel = Channel.Web,
};

// Act
string actualJson = request.ToJson();

// Expected JSON string
string expectedJson = "{\"chargePermissionId\":\"S02-7331650-8246451\",\"chargeAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo\"},\"chargeInitiator\":\"CITR\",\"channel\":\"Web\"}";

// Assert
Assert.AreEqual(actualJson, expectedJson);
}


[Test]
public void CanConvertToJsonSavedWallet()
{
// Arrange
var chargePermissionId = "S01-7436918-9739892";
var checkoutResultReturnUrl = "https://example.com/return.html";
var request = new CreateChargeRequest(chargePermissionId, 99.99M, Currency.EUR, checkoutResultReturnUrl)
{
ProviderMetadata = new ProviderMetadata { ProviderReferenceId = "foo" },
SoftDescriptor = "foo",
CaptureNow = true,
PlatformId = "My Platform Id",
CanHandlePendingAuthorization = true,
ChargeInitiator = ChargeInitiator.CITR,
Channel = Channel.Web
};

// Act
string actualJson = request.ToJson();

// Expected JSON string
string expectedJson = "{\"chargePermissionId\":\"S01-7436918-9739892\",\"chargeAmount\":{\"amount\":99.99,\"currencyCode\":\"EUR\"},\"captureNow\":true,\"softDescriptor\":\"foo\",\"platformId\":\"My Platform Id\",\"canHandlePendingAuthorization\":true,\"providerMetadata\":{\"providerReferenceId\":\"foo\"},\"chargeInitiator\":\"CITR\",\"channel\":\"Web\",\"webCheckoutDetails\":{\"checkoutResultReturnUrl\":\"https://example.com/return.html\"}}";

// Assert
Assert.AreEqual(actualJson, expectedJson);
}
}
}
4 changes: 2 additions & 2 deletions Amazon.Pay.API.SDK/Amazon.Pay.API.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<Version>2.7.2</Version>
<AssemblyVersion>2.7.2.0</AssemblyVersion>
<Version>2.7.3</Version>
<AssemblyVersion>2.7.3.0</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Amazon Pay</Authors>
<Company>Amazon</Company>
Expand Down
2 changes: 1 addition & 1 deletion Amazon.Pay.API.SDK/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Amazon.Pay.API
{
public class Constants
{
public const string SdkVersion = "2.7.2.0";
public const string SdkVersion = "2.7.3.0";
public const string SdkName = "amazon-pay-api-sdk-dotnet";
public const int ApiVersion = 2;

Expand Down
1 change: 1 addition & 0 deletions Amazon.Pay.API.SDK/Types/ReasonCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public static class ReasonCode
public const string ProcessingFailure = nameof(ProcessingFailure);
public const string TransactionAmountExceeded = nameof(TransactionAmountExceeded);
public const string TransactionTimedOut = nameof(TransactionTimedOut);
public const string BuyerClosed = nameof(BuyerClosed);
}
}
11 changes: 11 additions & 0 deletions Amazon.Pay.API.SDK/WebStore/Charge/ChargeResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Amazon.Pay.API.WebStore.Charge
{
public class ChargeResponse : AmazonPayResponse
{
public ChargeResponse()
{
WebCheckoutDetails = new WebCheckoutDetails();
}

/// <summary>
/// Charge identifer.
/// </summary>
Expand Down Expand Up @@ -109,5 +114,11 @@ public class ChargeResponse : AmazonPayResponse
/// </summary>
[JsonProperty(PropertyName = "merchantMetadata")]
public MerchantMetadata MerchantMetadata { get; internal set; }

/// <summary>
/// URLs associated to the Checkout Session used for completing checkout
/// </summary>
[JsonProperty(PropertyName = "webCheckoutDetails")]
public WebCheckoutDetails WebCheckoutDetails { get; internal set; }
}
}
23 changes: 21 additions & 2 deletions Amazon.Pay.API.SDK/WebStore/Charge/CreateChargeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public CreateChargeRequest(string chargePermissionId, decimal chargeAmount, Curr
MerchantMetadata = new MerchantMetadata();
}

// Handle Saved Wallet transactions
public CreateChargeRequest(string chargePermissionId, decimal chargeAmount, Currency currencyCode, string checkoutResultReturnUrl)
{
ProviderMetadata = new ProviderMetadata();
ChargePermissionId = chargePermissionId;
ChargeAmount = new Price(chargeAmount, currencyCode);
MerchantMetadata = new MerchantMetadata();
WebCheckoutDetails = new WebCheckoutDetails
{
CheckoutResultReturnUrl = checkoutResultReturnUrl
};
}

[OnSerializing]
internal void OnSerializing(StreamingContext content)
{
Expand Down Expand Up @@ -75,13 +88,13 @@ internal void OnSerialized(StreamingContext content)
/// Payment service provider (PSP)-provided order information.
/// </summary>
[JsonProperty(PropertyName = "providerMetadata")]
public ProviderMetadata ProviderMetadata { get; internal set; }
public ProviderMetadata ProviderMetadata { get; set; }

/// <summary>
/// Merchant-provided order info.
/// </summary>
[JsonProperty(PropertyName = "merchantMetadata")]
public MerchantMetadata MerchantMetadata { get; internal set; }
public MerchantMetadata MerchantMetadata { get; set; }

/// <summary>
/// Represents who initiated the payment.
Expand All @@ -94,5 +107,11 @@ internal void OnSerialized(StreamingContext content)
/// </summary>
[JsonProperty(PropertyName = "channel")]
public Channel? Channel { get; set; }

/// <summary>
/// URLs associated to the Checkout Session used for completing checkout
/// </summary>
[JsonProperty(PropertyName = "webCheckoutDetails")]
public WebCheckoutDetails WebCheckoutDetails { get; set; }
}
}
3 changes: 2 additions & 1 deletion Amazon.Pay.API.SDK/WebStore/Types/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Channel
Alexa,
PointOfSale,
FireTv,
Offline
Offline,
Amazon
}
}
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#### Version 2.7.3 - June 2024
* Added checkoutResultReturnUrl in the CreateChargeRequest API.
* Added webCheckoutDetails object in the CreateChargeResponse.
* Added CreateChargeRequest API sample code for Saved Wallet transactions.
* Added BuyerClosed in the ReasonCodes.

#### Version 2.7.2 - October 2023
* Introducing new Merchant Onboarding & Account Management APIs, which allows our partners to onboard merchants programatically and as part of account management offer them creation, updation and deletion/dissociation capability.
* Introducing new API called finalizeCheckoutSession which validates checkout attributes and finalizes checkout session. On success returns charge permission id and charge id. Use this API to process payments for JavaScript-based integrations.
Expand Down
Loading

0 comments on commit 46f02d8

Please sign in to comment.