Skip to content

Commit

Permalink
Merge branch 'alanz-cd-update-sdk-3ds'
Browse files Browse the repository at this point in the history
  • Loading branch information
incarnate committed May 13, 2021
2 parents 31a838d + 7d1bd7b commit 0cb7633
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All Notable changes will be documented in this file

## 1.6.3

- Update the SDK API to support Rapid 3D Secure enroll and verify.

## 1.6.2

- Change default TransactionType to MOTO when creating a Token Customer.
Expand Down
47 changes: 47 additions & 0 deletions eWAY.Rapid.Tests/IntegrationTests/Direct3DSEnrollTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using eWAY.Rapid.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace eWAY.Rapid.Tests.IntegrationTests
{
//Block the integration test beacuse rapid Sandbox is not support MPI now.
[TestClass]
public class Direct3DSEnrollTests : SdkTestBase
{
private IRapidClient _client;
private Direct3DSEnrollRequest _request;

[TestInitialize]
public void Initial()
{
_client = CreateRapidApiClient();
_request = TestUtil.CreateEnrollRequest();
}

[TestMethod]
public void Enroll_Returns_ValidResponse()
{
var response = _client.Direct3DSEnroll(_request);

Assert.IsFalse(string.IsNullOrEmpty(response.Default3dsUrl));
Assert.AreNotEqual(0, response.TraceId);
Assert.IsFalse(string.IsNullOrEmpty(response.AccessCode));
Assert.IsNull(response.Errors);
}

[TestMethod]
public void Enroll_Returns_ErrorResponse()
{
var request = TestUtil.CreateEnrollRequest();
//Send no postal code will cause error V6068
request.Customer.Address.PostalCode = "";

var response = _client.Direct3DSEnroll(request);

Assert.IsTrue(string.IsNullOrEmpty(response.Default3dsUrl));
Assert.AreEqual(0, response.TraceId);
Assert.IsTrue(string.IsNullOrEmpty(response.AccessCode));
Assert.IsNotNull(response.Errors);
Assert.AreEqual("V6068", response.Errors[0]);
}
}
}
56 changes: 56 additions & 0 deletions eWAY.Rapid.Tests/IntegrationTests/Direct3DSVerifyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using eWAY.Rapid.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace eWAY.Rapid.Tests.IntegrationTests
{
//Block the integration test beacuse rapid Sandbox is not support MPI now.
[TestClass]
public class Direct3DSVerifyTests : SdkTestBase
{
private IRapidClient _client;

[TestInitialize]
public void Initialize()
{
_client = CreateRapidApiClient();
}

[TestMethod]
public void Verify_Returns_Valid_Response()
{
var request = Generate3DSVerifyRequest();
var response = _client.Direct3DSVerify(request);

Assert.AreNotEqual(0, response.TraceId);
Assert.IsNotNull(response.AccessCode);
Assert.IsNotNull(response.ThreeDSecureAuth);
//Before verify, need to go to Direct3DSUrl to initialize the request, if not, will return D4417
Assert.IsNotNull(response.Errors);
Assert.AreEqual("D4417", response.Errors[0]);
}

[TestMethod]
public void Verify_Returns_Errors_Invalid_Response()
{
var request = Generate3DSVerifyRequest();
request.TraceId = 0;
var response = _client.Direct3DSVerify(request);

Assert.AreEqual("0", response.TraceId);
Assert.IsNull(response.AccessCode);
Assert.IsNull(response.ThreeDSecureAuth);
Assert.IsNotNull(response.Errors);
Assert.AreEqual("D4417", response.Errors[0]);
}

private Direct3DSVerifyRequest Generate3DSVerifyRequest()
{
var enrollResponse = _client.Direct3DSEnroll(TestUtil.CreateEnrollRequest());
return new Direct3DSVerifyRequest()
{
TraceId = enrollResponse.TraceId,
AccessCode = enrollResponse.AccessCode
};
}
}
}
4 changes: 2 additions & 2 deletions eWAY.Rapid.Tests/IntegrationTests/SettlementSearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void SettlementSearch_ByDateRange_Test()

//Assert
Assert.IsNotNull(settlementResponse);
Assert.IsTrue(settlementResponse.SettlementTransactions.Length > 1);
Assert.IsTrue(settlementResponse.SettlementSummaries.Length > 1);
Assert.IsTrue(settlementResponse.SettlementTransactions.Length >= 0);
Assert.IsTrue(settlementResponse.SettlementSummaries.Length >= 0);
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions eWAY.Rapid.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.2.0")]
[assembly: AssemblyFileVersion("1.6.2.0")]
[assembly: AssemblyVersion("1.6.3.0")]
[assembly: AssemblyFileVersion("1.6.3.0")]
59 changes: 54 additions & 5 deletions eWAY.Rapid.Tests/TestUtil.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using eWAY.Rapid.Enums;
using eWAY.Rapid.Internals.Models;
using eWAY.Rapid.Enums;
using eWAY.Rapid.Internals.Response;
using eWAY.Rapid.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using CardDetails = eWAY.Rapid.Models.CardDetails;
using Customer = eWAY.Rapid.Models.Customer;
using DirectTokenCustomer = eWAY.Rapid.Internals.Models.DirectTokenCustomer;
using LineItem = eWAY.Rapid.Models.LineItem;
using Payment = eWAY.Rapid.Internals.Models.Payment;
using Refund = eWAY.Rapid.Models.Refund;
using ShippingAddress = eWAY.Rapid.Models.ShippingAddress;
using VerificationResult = eWAY.Rapid.Internals.Models.VerificationResult;

namespace eWAY.Rapid.Tests
Expand Down Expand Up @@ -123,7 +124,7 @@ internal static Customer CreateCustomer()
{
Country = "au",
City = "Sydney",
PostalCode = "",
PostalCode = "2000",
State = "NSW",
Street1 = "Level 5",
Street2 = "369 Queen Street"
Expand Down Expand Up @@ -280,6 +281,54 @@ internal static DirectPaymentResponse CreateDirectPaymentResponse()
};
}

internal static Direct3DSEnrollRequest CreateEnrollRequest()
{
return new Direct3DSEnrollRequest
{
Customer = CreateCustomer(),
ShippingAddress = new ShippingAddress {
ShippingMethod = "NextDay",
FirstName = "John",
LastName = "Smith",
Street1 = "Level 5",
Street2 = "369 Queen Street",
City = "Sydney",
State = "NSW",
Country = "au",
PostalCode = "2000",
Phone = "09 889 0986"
},
Items = new List<LineItem>()
{
new LineItem()
{
SKU = "12345678901234567890",
Description = "Item Description 1",
Quantity = 1,
UnitCost = 400,
Tax = 100,
Total = 500
},
new LineItem()
{
SKU = "123456789012",
Description = "Item Description 2",
Quantity = 1,
UnitCost = 400,
Tax = 100,
Total = 500
}
},
Payment = new PaymentDetails()
{
TotalAmount = 1000,
CurrencyCode = "AUD"
},
RedirectUrl = "http://www.ewaypayments.com",
SecuredCardData = ""
};
}

//Assertion helpers
internal static void AssertReturnedCustomerData_VerifyAddressAreEqual(Customer responseCustomer, Customer requestCustomer)
{
Expand Down
2 changes: 2 additions & 0 deletions eWAY.Rapid.Tests/eWAY.Rapid.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
<ItemGroup>
<Compile Include="IntegrationTests\CreateCustomerTests.cs" />
<Compile Include="IntegrationTests\CreateTransactionTests.cs" />
<Compile Include="IntegrationTests\Direct3DSEnrollTests.cs" />
<Compile Include="IntegrationTests\Direct3DSVerifyTests.cs" />
<Compile Include="IntegrationTests\DirectRefundTests.cs" />
<Compile Include="IntegrationTests\MultiThreadedTests.cs" />
<Compile Include="IntegrationTests\PreAuthTests.cs" />
Expand Down
14 changes: 14 additions & 0 deletions eWAY.Rapid/IRapidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public interface IRapidClient
/// <returns>SettlementSearchResponse</returns>
SettlementSearchResponse SettlementSearch(SettlementSearchRequest settlementSearchRequest);

/// <summary>
/// To verify that the card is enrolled and to authenticate the results if it is enrolled.
/// </summary>
/// <param name="enrollRequest">Request containing the transaction details</param>
/// <returns></returns>
Direct3DSEnrollResponse Direct3DSEnroll(Direct3DSEnrollRequest enrollRequest);

/// <summary>
/// Request the validation service to verify the authentication message returned by the card-issuing bank.
/// </summary>
/// <param name="verifyRequest">Containing the traceId and AccessCode</param>
/// <returns></returns>
Direct3DSVerifyResponse Direct3DSVerify(Direct3DSVerifyRequest verifyRequest);

/// <summary>
/// True if the Client has valid API Key, Password and Endpoint Set.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions eWAY.Rapid/Internals/Mappings/RequestMapProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public RequestMapProfile() {

CreateMap<Transaction, DirectAuthorisationRequest>(MemberList.None)
.IncludeBase<Transaction, DirectPaymentRequest>();

CreateMap<Direct3DSEnrollRequest, Direct3DSecureEnrollRequest>(MemberList.None)
.ForMember(dest => dest.Customer, opt => opt.MapFrom(src => src.Customer))
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src.ShippingAddress))
.ForMember(dest => dest.Payment, opt => opt.MapFrom(src => src.Payment))
.ForMember(dest => dest.Items, opt => opt.MapFrom(src => src.Items))
.ForMember(dest => dest.SecuredCardData, opt => opt.MapFrom(src => src.SecuredCardData));
}
}
}
9 changes: 9 additions & 0 deletions eWAY.Rapid/Internals/Mappings/ResponseMapProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using eWAY.Rapid.Models;
using BaseResponse = eWAY.Rapid.Internals.Response.BaseResponse;
using Customer = eWAY.Rapid.Models.Customer;
using DirectTokenCustomer = eWAY.Rapid.Internals.Models.DirectTokenCustomer;

namespace eWAY.Rapid.Internals.Mappings {
internal class ResponseMapProfile : Profile {
Expand Down Expand Up @@ -143,6 +144,14 @@ public ResponseMapProfile() {

CreateMap<DirectTokenCustomer, Customer>(MemberList.Destination)
.ForMember(dest => dest.Address, opt => opt.MapFrom(src => src));

CreateMap<Direct3DSecureEnrollResponse, Direct3DSEnrollResponse>(MemberList.Destination)
.IncludeBase<BaseResponse, Rapid.Models.BaseResponse>()
.ReverseMap();

CreateMap<Direct3DSecureVerifyResponse, Direct3DSVerifyResponse>(MemberList.Destination)
.IncludeBase<BaseResponse, Rapid.Models.BaseResponse>()
.ReverseMap();
}
}
}
18 changes: 18 additions & 0 deletions eWAY.Rapid/Internals/Models/Direct3DSecureAuth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace eWAY.Rapid.Internals.Models
{
internal class Direct3DSecureAuth
{
/// <summary>Cardholder Authentication Value</summary>
public string Cryptogram { get; set; }
/// <summary>Electronic Commerce Indicator</summary>
public string ECI { get; set; }
/// <summary>Transaction identifier resulting from authentication processing for 3DS V1</summary>
public string XID { get; set; }
/// <summary>The result of the 3D Secure authentication </summary>
public string AuthStatus { get; set; }
/// <summary>Version of 3D Secure.</summary>
public string Version { get; set; }
/// <summary>Transaction Id for 3DS 2.0</summary>
public string dsTransactionId { get; set; }
}
}
2 changes: 1 addition & 1 deletion eWAY.Rapid/Internals/Models/DirectTokenCustomer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace eWAY.Rapid.Internals.Models
{
internal class DirectTokenCustomer :TokenCustomer
internal class DirectTokenCustomer : TokenCustomer
{
public CardDetails CardDetails { get; set; }
}
Expand Down
14 changes: 14 additions & 0 deletions eWAY.Rapid/Internals/RapidClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ public SettlementSearchResponse SettlementSearch(SettlementSearchRequest settlem
return _mappingService.Map<DirectSettlementSearchResponse, SettlementSearchResponse>(response);
}

public Direct3DSEnrollResponse Direct3DSEnroll(Direct3DSEnrollRequest enrollRequest)
{
var request = _mappingService.Map<Direct3DSEnrollRequest, Direct3DSecureEnrollRequest>(enrollRequest);
var enrollResponse = _rapidService.ThreeDSEnroll(request);
return _mappingService.Map<Direct3DSecureEnrollResponse, Direct3DSEnrollResponse>(enrollResponse);
}

public Direct3DSVerifyResponse Direct3DSVerify(Direct3DSVerifyRequest verifyRequest)
{
var request = _mappingService.Map<Direct3DSVerifyRequest, Direct3DSecureVerifyRequest>(verifyRequest);
var verifyResponse = _rapidService.ThreeDSVerify(request);
return _mappingService.Map<Direct3DSecureVerifyResponse, Direct3DSVerifyResponse>(verifyResponse);
}

public bool IsValid
{
get
Expand Down
16 changes: 16 additions & 0 deletions eWAY.Rapid/Internals/Request/Direct3DSecureEnrollRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using eWAY.Rapid.Internals.Models;
using System.Collections.Generic;

namespace eWAY.Rapid.Internals.Request
{
internal
class Direct3DSecureEnrollRequest : BaseRequest
{
public DirectTokenCustomer Customer { get; set; }
public ShippingAddress ShippingAddress { get; set; }
public List<LineItem> Items { get; set; }
public Payment Payment { get; set; }
public string RedirectUrl { get; set; }
public string SecuredCardData { get; set; }
}
}
8 changes: 8 additions & 0 deletions eWAY.Rapid/Internals/Request/Direct3DSecureVerifyRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace eWAY.Rapid.Internals.Request
{
internal class Direct3DSecureVerifyRequest : BaseRequest
{
public long TraceId { get; set; }
public string AccessCode { get; set; }
}
}
9 changes: 9 additions & 0 deletions eWAY.Rapid/Internals/Response/Direct3DSecureEnrollResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace eWAY.Rapid.Internals.Response
{
internal class Direct3DSecureEnrollResponse : BaseResponse
{
public string Default3dsUrl { get; set; }
public long TraceId { get; set; }
public string AccessCode { get; set; }
}
}
11 changes: 11 additions & 0 deletions eWAY.Rapid/Internals/Response/Direct3DSecureVerifyResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using eWAY.Rapid.Internals.Models;

namespace eWAY.Rapid.Internals.Response
{
internal class Direct3DSecureVerifyResponse : BaseResponse
{
public string TraceId { get; set; }
public string AccessCode { get; set; }
public Direct3DSecureAuth ThreeDSecureAuth { get; set; }
}
}
2 changes: 2 additions & 0 deletions eWAY.Rapid/Internals/Services/IRapidService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal interface IRapidService
TransactionSearchResponse QueryInvoiceRef(string invoiceRef);
TransactionSearchResponse QueryInvoiceNumber(string invoiceNumber);
DirectSettlementSearchResponse SettlementSearch(string request);
Direct3DSecureEnrollResponse ThreeDSEnroll(Direct3DSecureEnrollRequest request);
Direct3DSecureVerifyResponse ThreeDSVerify(Direct3DSecureVerifyRequest request);

string GetRapidEndpoint();
void SetRapidEndpoint(string value);
Expand Down
Loading

0 comments on commit 0cb7633

Please sign in to comment.