Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,42 @@
/// <summary>
///
/// </summary>
/// <seealso cref="MediatR.IRequestHandler{TransactionProcessorACL.BusinessLogic.Requests.ProcessLogonTransactionRequest, TransactionProcessorACL.Models.ProcessLogonTransactionResponse}" />
/// <seealso cref="ProcessLogonTransactionResponse" />
public class ProcessLogonTransactionRequestHandler : IRequestHandler<ProcessLogonTransactionRequest, ProcessLogonTransactionResponse>
{
#region Fields

/// <summary>
/// The application service
/// </summary>
private readonly ITransactionProcessorACLApplicationService ApplicationService;

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ProcessLogonTransactionRequestHandler"/> class.
/// </summary>
/// <param name="applicationService">The application service.</param>
public ProcessLogonTransactionRequestHandler(ITransactionProcessorACLApplicationService applicationService)
{
this.ApplicationService = applicationService;
}

#endregion

#region Methods

/// <summary>
/// Handles the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
/// <returns>
/// Response from the request
/// </returns>
public async Task<ProcessLogonTransactionResponse> Handle(ProcessLogonTransactionRequest request,
CancellationToken cancellationToken)
{
Expand All @@ -41,4 +59,55 @@ public async Task<ProcessLogonTransactionResponse> Handle(ProcessLogonTransactio

#endregion
}

public class ProcessSaleTransactionRequestHandler : IRequestHandler<ProcessSaleTransactionRequest, ProcessSaleTransactionResponse>
{
#region Fields

/// <summary>
/// The application service
/// </summary>
private readonly ITransactionProcessorACLApplicationService ApplicationService;

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ProcessSaleTransactionRequestHandler"/> class.
/// </summary>
/// <param name="applicationService">The application service.</param>
public ProcessSaleTransactionRequestHandler(ITransactionProcessorACLApplicationService applicationService)
{
this.ApplicationService = applicationService;
}

#endregion

#region Methods

/// <summary>
/// Handles the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// Response from the request
/// </returns>
public async Task<ProcessSaleTransactionResponse> Handle(ProcessSaleTransactionRequest request,
CancellationToken cancellationToken)
{
return await this.ApplicationService.ProcessSaleTransaction(request.EstateId,
request.MerchantId,
request.TransactionDateTime,
request.TransactionNumber,
request.DeviceIdentifier,
request.OperatorIdentifier,
request.Amount,
request.CustomerAccountNumber,
cancellationToken);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
namespace TransactionProcessorACL.BusinessLogic.Requests
{
using System;
using MediatR;
using Models;

public class ProcessSaleTransactionRequest : IRequest<ProcessSaleTransactionResponse>
{
#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="ProcessLogonTransactionRequest" /> class.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="transactionDateTime">The transaction date time.</param>
/// <param name="transactionNumber">The transaction number.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="operatorIdentifier">The operator identifier.</param>
/// <param name="amount">The amount.</param>
/// <param name="customerAccountNumber">The customer account number.</param>
private ProcessSaleTransactionRequest(Guid estateId,
Guid merchantId,
DateTime transactionDateTime,
String transactionNumber,
String deviceIdentifier,
String operatorIdentifier,
Decimal amount,
String customerAccountNumber)
{
this.EstateId = estateId;
this.MerchantId = merchantId;
this.DeviceIdentifier = deviceIdentifier;
this.OperatorIdentifier = operatorIdentifier;
this.Amount = amount;
this.CustomerAccountNumber = customerAccountNumber;
this.TransactionDateTime = transactionDateTime;
this.TransactionNumber = transactionNumber;
}

public ProcessSaleTransactionRequest()
{
// This constructor is only required for IoC tests :|
}

#endregion

#region Properties

/// <summary>
/// Gets the amount.
/// </summary>
/// <value>
/// The amount.
/// </value>
public Decimal Amount { get; }

/// <summary>
/// Gets the customer account number.
/// </summary>
/// <value>
/// The customer account number.
/// </value>
public String CustomerAccountNumber { get; }

/// <summary>
/// Gets the device identifier.
/// </summary>
/// <value>
/// The device identifier.
/// </value>
public String DeviceIdentifier { get; }

/// <summary>
/// Gets the estate identifier.
/// </summary>
/// <value>
/// The estate identifier.
/// </value>
public Guid EstateId { get; }

/// <summary>
/// Gets the merchant identifier.
/// </summary>
/// <value>
/// The merchant identifier.
/// </value>
public Guid MerchantId { get; }

/// <summary>
/// Gets the operator identifier.
/// </summary>
/// <value>
/// The operator identifier.
/// </value>
public String OperatorIdentifier { get; }

/// <summary>
/// Gets the transaction date time.
/// </summary>
/// <value>
/// The transaction date time.
/// </value>
public DateTime TransactionDateTime { get; }

/// <summary>
/// Gets the transaction number.
/// </summary>
/// <value>
/// The transaction number.
/// </value>
public String TransactionNumber { get; }

#endregion

#region Methods

/// <summary>
/// Creates the specified estate identifier.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="transactionDateTime">The transaction date time.</param>
/// <param name="transactionNumber">The transaction number.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="operatorIdentifier">The operator identifier.</param>
/// <param name="amount">The amount.</param>
/// <param name="customerAccountNumber">The customer account number.</param>
/// <returns></returns>
public static ProcessSaleTransactionRequest Create(Guid estateId,
Guid merchantId,
DateTime transactionDateTime,
String transactionNumber,
String deviceIdentifier,
String operatorIdentifier,
Decimal amount,
String customerAccountNumber)
{
return new ProcessSaleTransactionRequest(estateId,
merchantId,
transactionDateTime,
transactionNumber,
deviceIdentifier,
operatorIdentifier,
amount,
customerAccountNumber);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,28 @@ Task<ProcessLogonTransactionResponse> ProcessLogonTransaction(Guid estateId,
String transactionNumber,
String deviceIdentifier,
CancellationToken cancellationToken);

/// <summary>
/// Processes the sale transaction.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="transactionDateTime">The transaction date time.</param>
/// <param name="transactionNumber">The transaction number.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="operatorIdentifier">The operator identifier.</param>
/// <param name="amount">The amount.</param>
/// <param name="customerAccountNumber">The customer account number.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<ProcessSaleTransactionResponse> ProcessSaleTransaction(Guid estateId,
Guid merchantId,
DateTime transactionDateTime,
String transactionNumber,
String deviceIdentifier,
String operatorIdentifier,
Decimal amount,
String customerAccountNumber,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace TransactionProcessorACL.BusinessLogic.Services
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Models;
Expand Down Expand Up @@ -118,6 +119,87 @@ public async Task<ProcessLogonTransactionResponse> ProcessLogonTransaction(Guid
return response;
}

/// <summary>
/// Processes the sale transaction.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="transactionDateTime">The transaction date time.</param>
/// <param name="transactionNumber">The transaction number.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="operatorIdentifier">The operator identifier.</param>
/// <param name="amount">The amount.</param>
/// <param name="customerAccountNumber">The customer account number.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public async Task<ProcessSaleTransactionResponse> ProcessSaleTransaction(Guid estateId,
Guid merchantId,
DateTime transactionDateTime,
String transactionNumber,
String deviceIdentifier,
String operatorIdentifier,
Decimal amount,
String customerAccountNumber,
CancellationToken cancellationToken)
{
// Get a client token to call the Transaction Processor
String clientId = ConfigurationReader.GetValue("AppSettings", "ClientId");
String clientSecret = ConfigurationReader.GetValue("AppSettings", "ClientSecret");

TokenResponse accessToken = await this.SecurityServiceClient.GetToken(clientId, clientSecret, cancellationToken);

SaleTransactionRequest saleTransactionRequest = new SaleTransactionRequest();
saleTransactionRequest.TransactionNumber = transactionNumber;
saleTransactionRequest.DeviceIdentifier = deviceIdentifier;
saleTransactionRequest.TransactionDateTime = transactionDateTime;
saleTransactionRequest.TransactionType = "SALE";
saleTransactionRequest.OperatorIdentifier = operatorIdentifier;

// Build up the metadata
saleTransactionRequest.AdditionalTransactionMetadata = new Dictionary<String, String>();
saleTransactionRequest.AdditionalTransactionMetadata.Add("Amount", amount.ToString());
saleTransactionRequest.AdditionalTransactionMetadata.Add("CustomerAccountNumber", customerAccountNumber);

SerialisedMessage requestSerialisedMessage = new SerialisedMessage();
requestSerialisedMessage.Metadata.Add("EstateId", estateId.ToString());
requestSerialisedMessage.Metadata.Add("MerchantId", merchantId.ToString());
requestSerialisedMessage.SerialisedData = JsonConvert.SerializeObject(saleTransactionRequest,
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
});

ProcessSaleTransactionResponse response = null;

try
{
SerialisedMessage responseSerialisedMessage =
await this.TransactionProcessorClient.PerformTransaction(accessToken.AccessToken, requestSerialisedMessage, cancellationToken);

SaleTransactionResponse saleTransactionResponse = JsonConvert.DeserializeObject<SaleTransactionResponse>(responseSerialisedMessage.SerialisedData);

response = new ProcessSaleTransactionResponse
{
ResponseCode = saleTransactionResponse.ResponseCode,
ResponseMessage = saleTransactionResponse.ResponseMessage
};
}
catch (Exception ex)
{
if (ex.InnerException is InvalidOperationException)
{
// This means there is an error in the request
response = new ProcessSaleTransactionResponse
{
ResponseCode = "0001", // Request Message error
ResponseMessage = ex.InnerException.Message
};
}
}

return response;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ItemGroup>
<PackageReference Include="MediatR" Version="8.0.1" />
<PackageReference Include="SecurityService.Client" Version="0.0.9" />
<PackageReference Include="Shared" Version="0.0.11.3" />
<PackageReference Include="TransactionProcessor.Client" Version="0.0.5" />
<PackageReference Include="Shared" Version="0.0.12" />
<PackageReference Include="TransactionProcessor.Client" Version="0.0.5.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading