Skip to content

Commit 9643507

Browse files
committed
Add SaveCustomer flag to Transactions to create a token when a transaction is completed.
1 parent 31c1a83 commit 9643507

File tree

8 files changed

+53
-7
lines changed

8 files changed

+53
-7
lines changed

eWAY.Rapid.Tests/IntegrationTests/CreateTransactionTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ public void Transaction_CreateTransactionTransparentRedirect_ReturnValidData()
5353
transaction.Customer);
5454
}
5555

56+
[TestMethod]
57+
public void Transaction_CreateTokenTransactionTransparentRedirect_ReturnValidData()
58+
{
59+
var client = CreateRapidApiClient();
60+
//Arrange
61+
var transaction = TestUtil.CreateTransaction();
62+
transaction.SaveCustomer = true;
63+
64+
//Act
65+
var response = client.Create(PaymentMethod.TransparentRedirect, transaction);
66+
67+
//Assert
68+
Assert.IsNull(response.Errors);
69+
Assert.IsNotNull(response.AccessCode);
70+
Assert.IsNotNull(response.FormActionUrl);
71+
TestUtil.AssertReturnedCustomerData_VerifyAddressAreEqual(response.Transaction.Customer,
72+
transaction.Customer);
73+
TestUtil.AssertReturnedCustomerData_VerifyAllFieldsAreEqual(response.Transaction.Customer,
74+
transaction.Customer);
75+
}
76+
5677
[TestMethod]
5778
public void Transaction_CreateTransactionResponsiveShared_ReturnValidData()
5879
{

eWAY.Rapid.Tests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.1.3.0")]
35-
[assembly: AssemblyFileVersion("1.1.3.0")]
34+
[assembly: AssemblyVersion("1.2.0.0")]
35+
[assembly: AssemblyFileVersion("1.2.0.0")]

eWAY.Rapid.Tests/TestUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ namespace eWAY.Rapid.Tests
1717
public static class TestUtil
1818
{
1919
//Third party Merchant
20-
internal static Transaction CreateTransaction(bool capture, string tokenId = null)
20+
internal static Transaction CreateTransaction(bool capture, string tokenId = null, bool createToken = false)
2121
{
22-
var result = new Transaction { Capture = capture };
22+
var result = new Transaction { Capture = capture, SaveCustomer = createToken };
2323
var cardDetails = new CardDetails() { Name = "John Smith", Number = "4444333322221111", ExpiryMonth = "12", ExpiryYear = "25", CVN = "123" };
2424
var address = new Address()
2525
{

eWAY.Rapid.Tests/UnitTests/CreateTransactionTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ public void CreateTransaction_TransparentRedirect_CaptureTrue_TokenYes_InvokeCre
9494
Assert.IsNotNull(assertRequest);
9595
Assert.AreEqual(assertRequest.Method, Method.TokenPayment);
9696
}
97+
[TestMethod]
98+
public void CreateTransaction_TransparentRedirect_CreateTokenTrue_InvokeCreateAccessCode_TokenPayment()
99+
{
100+
var mockRapidApiClient = new Mock<IRapidService>();
101+
var rapidSdkClient = new RapidClient(mockRapidApiClient.Object);
102+
CreateAccessCodeRequest assertRequest = null;
103+
//Arrange
104+
var transaction = TestUtil.CreateTransaction(true, null, true);
105+
mockRapidApiClient.Setup(x => x.IsValid()).Returns(true);
106+
mockRapidApiClient.Setup(x => x.CreateAccessCode(It.IsAny<CreateAccessCodeRequest>()))
107+
.Callback<CreateAccessCodeRequest>(i => assertRequest = i)
108+
.Returns(new CreateAccessCodeResponse()).Verifiable();
109+
//Act
110+
rapidSdkClient.Create(PaymentMethod.TransparentRedirect, transaction);
111+
//Assert
112+
mockRapidApiClient.Verify();
113+
Assert.IsNotNull(assertRequest);
114+
Assert.AreEqual(Method.TokenPayment, assertRequest.Method);
115+
}
97116

98117
[TestMethod]
99118
public void CreateTransaction_Authorisation_InvokeDirectAuthorisation()

eWAY.Rapid.Tests/eWAY.Rapid.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<Compile Include="IntegrationTests\PreAuthTests.cs" />
6767
<Compile Include="IntegrationTests\QueryCustomerTests.cs" />
6868
<Compile Include="IntegrationTests\QueryTransactionTests.cs" />
69+
<Compile Include="IntegrationTests\UpdateCustomerTests.cs" />
6970
<Compile Include="MappingTests\MappingTests.cs" />
7071
<Compile Include="Properties\AssemblyInfo.cs" />
7172
<Compile Include="IntegrationTests\SdkTestBase.cs" />

eWAY.Rapid/Internals/Services/MappingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void RegisterRequestMapping()
5252
.ForMember(dest => dest.ShippingAddress, opt => opt.MapFrom(src => src.ShippingDetails))
5353
.ForMember(dest => dest.Payment, opt => opt.MapFrom(src => src.PaymentDetails))
5454
.ForMember(dest => dest.Method, opt => opt.MapFrom(src => src.Capture
55-
? (src.Customer.TokenCustomerID == null ? Method.ProcessPayment : Method.TokenPayment)
55+
? (src.Customer.TokenCustomerID == null && src.SaveCustomer != true ? Method.ProcessPayment : Method.TokenPayment)
5656
: Method.Authorise));
5757

5858
Mapper.CreateMap<Transaction, CapturePaymentRequest>()

eWAY.Rapid/Models/Transaction.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class Transaction
1919
/// </summary>
2020
public bool Capture { get; set; }
2121
/// <summary>
22+
/// Set to true to create a token when the payment is processed using Transparent Redirect or Shared Page
23+
/// Set to false to process a standard transaction (default)
24+
/// </summary>
25+
public bool SaveCustomer { get; set; }
26+
/// <summary>
2227
/// Customer details (name address token etc)
2328
/// </summary>
2429
public Customer Customer { get; set; }

eWAY.Rapid/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.3.0")]
36-
[assembly: AssemblyFileVersion("1.1.3.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]
3737

3838
[assembly: InternalsVisibleTo("eWAY.Rapid.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001001fa88da23161933c177ff28430a896e9dc1d184b788db49eed5f7a6c101ed7cd4820b80a0f22949cc0077c5fa00d7c575a678e145d35f391caf1ec747a00602fc86df22717d7c0ee5fe4607f0c64ac2b99aa6d81198d7d308db51f457576d541e2318d58f3b54859a6ee60154193472f9d8a1bfdae9c16f26aa755d658d8f0f5")]
3939
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

0 commit comments

Comments
 (0)