Skip to content

Commit

Permalink
Amazon Pay API SDK (.NET) 2.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Shangamesh T committed Mar 30, 2021
1 parent 89928c3 commit 64cf197
Show file tree
Hide file tree
Showing 11 changed files with 323 additions and 11 deletions.
52 changes: 49 additions & 3 deletions Amazon.Pay.API.SDK.Tests/WebStore/Buyer/SignInRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ public void CanConstruct2WithAllPropertiesInitialized()
public void CanConstructWithAllPropertiesAndAllScopesInitialized()
{
// act
SignInScope[] scopes = new SignInScope[] { SignInScope.Name, SignInScope.Email, SignInScope.PostalCode, SignInScope.ShippingAddress, SignInScope.PhoneNumber };
SignInScope[] scopes = new SignInScope[] {
SignInScope.Name, SignInScope.Email,
SignInScope.PostalCode, SignInScope.ShippingAddress,
SignInScope.PhoneNumber,
SignInScope.BillingAddress,
SignInScope.PrimeStatus
};
var request = new SignInRequest
(
signInReturnUrl: "https://example.com/review.html",
Expand All @@ -63,6 +69,8 @@ public void CanConstructWithAllPropertiesAndAllScopesInitialized()
Assert.Contains(SignInScope.PostalCode, request.SignInScopes);
Assert.Contains(SignInScope.ShippingAddress, request.SignInScopes);
Assert.Contains(SignInScope.PhoneNumber, request.SignInScopes);
Assert.Contains(SignInScope.BillingAddress, request.SignInScopes);
Assert.Contains(SignInScope.PrimeStatus, request.SignInScopes);
}

[Test]
Expand All @@ -84,15 +92,53 @@ public void CanConvertToJson()
public void CanConvertToJsonAllScopes()
{
// arrange
var request = new SignInRequest("https://example.com/review.html", "amzn1.application-oa2-client.000000000000000000000000000000000", SignInScope.Name, SignInScope.Email, SignInScope.PostalCode, SignInScope.ShippingAddress, SignInScope.PhoneNumber);
var request = new SignInRequest(
"https://example.com/review.html",
"amzn1.application-oa2-client.000000000000000000000000000000000",
SignInScope.Name, SignInScope.Email,
SignInScope.PostalCode,
SignInScope.ShippingAddress,
SignInScope.PhoneNumber,
SignInScope.BillingAddress,
SignInScope.PrimeStatus);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"signInReturnUrl\":\"https://example.com/review.html\",\"signInScopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\"]}", json);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"signInReturnUrl\":\"https://example.com/review.html\",\"signInScopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\",\"billingAddress\",\"primeStatus\"]}", json);
}

[Test]
public void TestBillingAddressInResponseByPassingBillingAddressInScope()
{
// arrange
var request = new SignInRequest("https://example.com/review.html", "amzn1.application-oa2-client.000000000000000000000000000000000", SignInScope.BillingAddress);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"signInReturnUrl\":\"https://example.com/review.html\",\"signInScopes\":[\"billingAddress\"]}", json);
}

[Test]
public void TestPrimeMemberShipStausInResponseByPassingPrimeStatusInScope()
{
// arrange
var request = new SignInRequest("https://example.com/review.html", "amzn1.application-oa2-client.000000000000000000000000000000000", SignInScope.PrimeStatus);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"signInReturnUrl\":\"https://example.com/review.html\",\"signInScopes\":[\"primeStatus\"]}", json);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,101 @@ public void CheckoutSessionResponseTest()
Assert.AreEqual("800-000-0000", r.ShippingAddress.PhoneNumber);
}

[Test]
public void CanConstructWithAllCheckoutSessionScopes()
{
CheckoutSessionScope[] scopes = new CheckoutSessionScope[] {
CheckoutSessionScope.Name,
CheckoutSessionScope.Email,
CheckoutSessionScope.PostalCode,
CheckoutSessionScope.ShippingAddress,
CheckoutSessionScope.PhoneNumber,
CheckoutSessionScope.PrimeStatus,
CheckoutSessionScope.BillingAddress
};
// act
var request = new CreateCheckoutSessionRequest
(
checkoutReviewReturnUrl: "https://example.com/review.html",
storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
scopes
);

// assert
Assert.IsNotNull(request);
Assert.IsNotNull(request.WebCheckoutDetails);
Assert.IsNotNull(request.DeliverySpecifications);
Assert.IsNotNull(request.MerchantMetadata);
Assert.IsNotNull(request.PaymentDetails);
Assert.IsNotNull(request.ProviderMetadata);
Assert.IsNotNull(request.RecurringMetadata);
Assert.IsNotNull(request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.Name, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.Email, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.PostalCode, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.ShippingAddress, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.PhoneNumber, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.PrimeStatus, request.CheckoutSessionScope);
Assert.Contains(CheckoutSessionScope.BillingAddress, request.CheckoutSessionScope);
Assert.AreEqual("https://example.com/review.html", request.WebCheckoutDetails.CheckoutReviewReturnUrl);
Assert.AreEqual("amzn1.application-oa2-client.000000000000000000000000000000000", request.StoreId);
}

[Test]
public void CanConvertToJsonWithCheckoutSessionScope()
{
CheckoutSessionScope[] scopes = new CheckoutSessionScope[] {
CheckoutSessionScope.Name,
CheckoutSessionScope.Email,
CheckoutSessionScope.PostalCode,
};

// arrange
var request = new CreateCheckoutSessionRequest
(
checkoutReviewReturnUrl: "https://example.com/review.html",
storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
scopes
);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"scopes\":[\"name\",\"email\",\"postalCode\"],\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);
}

[Test]
public void CanConvertToJsonMinimalWithAllCheckoutSessionScopes()
{
CheckoutSessionScope[] scopes = new CheckoutSessionScope[] {
CheckoutSessionScope.Name,
CheckoutSessionScope.Email,
CheckoutSessionScope.PostalCode,
CheckoutSessionScope.ShippingAddress,
CheckoutSessionScope.PhoneNumber,
CheckoutSessionScope.PrimeStatus,
CheckoutSessionScope.BillingAddress
};

// arrange
var request = new CreateCheckoutSessionRequest
(
checkoutReviewReturnUrl: "https://example.com/review.html",
storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
scopes
);

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

// assert
Assert.AreEqual(json, json2);
Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"scopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\",\"primeStatus\",\"billingAddress\"],\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);
}

}
}
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.4.4</Version>
<AssemblyVersion>2.4.4.0</AssemblyVersion>
<Version>2.4.5</Version>
<AssemblyVersion>2.4.5.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.4.4.0";
public const string SdkVersion = "2.4.5.0";
public const string SdkName = "amazon-pay-api-sdk-dotnet";
public const int ApiVersion = 2;

Expand Down
13 changes: 13 additions & 0 deletions Amazon.Pay.API.SDK/WebStore/Buyer/BuyerResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Amazon.Pay.API.Types;
using System.Collections.Generic;
using Amazon.Pay.API.WebStore.Types;
using Newtonsoft.Json;

Expand Down Expand Up @@ -41,5 +42,17 @@ public class BuyerResponse : AmazonPayResponse
/// </summary>
[JsonProperty(PropertyName = "shippingAddress")]
public Address ShippingAddress { get; internal set; }

/// <summary>
/// Billing address for buyer-selected payment instrument.
/// </summary>
[JsonProperty(PropertyName = "billingAddress")]
public Address BillingAddress { get; internal set; }

/// <summary>
/// PrimeMembershipTypes of the buyer.
/// </summary>
[JsonProperty(PropertyName = "primeMembershipTypes")]
public IList<string> PrimeMembershipTypes { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public CreateCheckoutSessionRequest() : base()
AddressDetails = new AddressDetails();
}

/// <summary>
/// Initializes a new instance of the CreateCheckoutSessionRequest class.
/// </summary>
/// <param name="checkoutReviewReturnUrl">Checkout review URL provided by the merchant. Amazon Pay will redirect to this URL after the buyer selects their preferred payment instrument and shipping address.</param>
/// <param name="storeId">Store ID as defined in Seller Central.</param>
/// <param name="scopes">Scopes passed by merchant to request buyer data</param>
public CreateCheckoutSessionRequest(string checkoutReviewReturnUrl, string storeId, CheckoutSessionScope[] checkoutSessionScopes) : base()
{
WebCheckoutDetails.CheckoutReviewReturnUrl = checkoutReviewReturnUrl;
StoreId = storeId;
DeliverySpecifications = new DeliverySpecifications();
AddressDetails = new AddressDetails();
CheckoutSessionScope = checkoutSessionScopes;
}

/// <summary>
/// Login with Amazon client ID. Do not use the application ID.
/// </summary>
Expand All @@ -47,5 +62,11 @@ public CreateCheckoutSessionRequest() : base()
[JsonProperty(PropertyName = "addressDetails")]
public AddressDetails AddressDetails { get; internal set; }

/// <summary>
/// Checkout Session Scopes
/// </summary>
[JsonProperty(PropertyName = "scopes")]
public CheckoutSessionScope[] CheckoutSessionScope { get; internal set; }

}
}
13 changes: 13 additions & 0 deletions Amazon.Pay.API.SDK/WebStore/Types/Buyer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Amazon.Pay.API.WebStore.Types
Expand All @@ -21,5 +22,17 @@ public class Buyer
/// </summary>
[JsonProperty(PropertyName = "email")]
public string Email { get; internal set; }

/// <summary>
/// Buyer Phone Number.
/// </summary>
[JsonProperty(PropertyName = "phoneNumber")]
public string PhoneNumber { get; internal set; }

/// <summary>
/// Buyer PrimeMembershipTypes.
/// </summary>
[JsonProperty(PropertyName = "primeMembershipTypes")]
public IList<string> PrimeMembershipTypes { get; internal set; }
}
}
58 changes: 58 additions & 0 deletions Amazon.Pay.API.SDK/WebStore/Types/CheckoutSessionScope.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace Amazon.Pay.API.WebStore.Types
{
/// <summary>
/// The buyer details that you're requesting access for.
/// </summary>
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public enum CheckoutSessionScope
{
/// <summary>
/// Request access to buyer name.
/// </summary>
[EnumMember(Value = "name")]
Name,

/// <summary>
/// Request access to buyer email address.
/// </summary>
[EnumMember(Value = "email")]
Email,

/// <summary>
/// Request access to buyer default shipping address postal code and country code.
/// </summary>
[EnumMember(Value = "postalCode")]
PostalCode,

/// <summary>
/// Request access to buyer default full shipping address (including postal code and country code).
/// </summary>
[EnumMember(Value = "shippingAddress")]
ShippingAddress,

/// <summary>
/// Request access to buyer default phone number.
/// </summary>
[EnumMember(Value = "phoneNumber")]
PhoneNumber,

/// <summary>
/// Request access to buyer prime membership status.
/// </summary>
/// <remarks>
/// Note that Passing "primeStatus" will return value for field "primeMembershipTypes" in response, only if the customer is eligible for prime membership
/// </remarks>
[EnumMember(Value = "primeStatus")]
PrimeStatus,

/// <summary>
/// Request access to buyer default full billing address (including postal code and country code).
/// </summary>
[EnumMember(Value = "billingAddress")]
BillingAddress
}
}
14 changes: 13 additions & 1 deletion Amazon.Pay.API.SDK/WebStore/Types/SignInScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public enum SignInScope
/// Request access to buyer default phone number.
/// </summary>
[EnumMember(Value = "phoneNumber")]
PhoneNumber
PhoneNumber,

/// <summary>
/// Request access to buyer prime membership status.
/// </summary>
[EnumMember(Value = "primeStatus")]
PrimeStatus,

/// <summary>
/// Request access to buyer default full billing address (including postal code and country code).
/// </summary>
[EnumMember(Value = "billingAddress")]
BillingAddress
}
}
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 2.4.5 - March 2021
* Added "phoneNumber" and "primeMembershipTypes" to "Buyer" object for both CheckoutSession and ChargePermission API's
* Added "phoneNumber" and "primeMembershipTypes" to "BuyerResponse" object for GetBuyer API
* Added "billingAddress" & "primeStatus" as scopes to SignInScopes
* Enabled CreateCheckoutSession Scopes for CreateCheckoutSession API
* Note : Passing "primeStatus" as SignInScope or CheckoutSessionScope will return value for field "primeMembershipTypes" in response, only if the customer is eligible for prime membership

### Version 2.4.4 - February 2021
* Switch from BouncyCastle and BouncyCastle.Core reference to latest release Portable.BouncyCastle (1.8.9), while also switching to use default trailer for PssSigner in signature generation. This resolves previous signature generation issues encountered using non-default trailer for PssSigner on BouncyCastle versions 1.8.6 and higher.

Expand Down
Loading

0 comments on commit 64cf197

Please sign in to comment.