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 @@ -216,6 +216,7 @@ await transactionAggregateManager.StartTransaction(TestData.TransactionId,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier,
TestData.TransactionAmount,
CancellationToken.None);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Task RecordAdditionalResponseData(Guid estateId,
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="transactionAmount">The transaction amount.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task StartTransaction(Guid transactionId,
Expand All @@ -167,6 +168,7 @@ Task StartTransaction(Guid transactionId,
Guid estateId,
Guid merchantId,
String deviceIdentifier,
Decimal? transactionAmount,
CancellationToken cancellationToken);

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ public async Task RequestEmailReceipt(Guid estateId, Guid transactionId, String
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="transactionAmount">The transaction amount.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public async Task StartTransaction(Guid transactionId,
DateTime transactionDateTime,
Expand All @@ -284,14 +285,15 @@ public async Task StartTransaction(Guid transactionId,
Guid estateId,
Guid merchantId,
String deviceIdentifier,
Decimal? transactionAmount,
CancellationToken cancellationToken)
{
IAggregateRepository<TransactionAggregate> transactionAggregateRepository =
this.AggregateRepositoryManager.GetAggregateRepository<TransactionAggregate>(estateId);

TransactionAggregate transactionAggregate = await transactionAggregateRepository.GetLatestVersion(transactionId, cancellationToken);

transactionAggregate.StartTransaction(transactionDateTime, transactionNumber, transactionType, transactionReference, estateId, merchantId, deviceIdentifier);
transactionAggregate.StartTransaction(transactionDateTime, transactionNumber, transactionType, transactionReference, estateId, merchantId, deviceIdentifier, transactionAmount);

await transactionAggregateRepository.SaveChanges(transactionAggregate, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ await this.TransactionAggregateManager.StartTransaction(transactionId,
estateId,
merchantId,
deviceIdentifier,
null, // Logon transaction has no amount
cancellationToken);

(String responseMessage, TransactionResponseCode responseCode) validationResult =
Expand Down Expand Up @@ -162,6 +163,9 @@ public async Task<ProcessSaleTransactionResponse> ProcessSaleTransaction(Guid tr
// Generate a transaction reference
String transactionReference = this.GenerateTransactionReference();

// Extract the transaction amount from the metadata
Decimal transactionAmount = this.ExtractFieldFromMetadata<Decimal>("Amount", additionalTransactionMetadata);

await this.TransactionAggregateManager.StartTransaction(transactionId,
transactionDateTime,
transactionNumber,
Expand All @@ -170,6 +174,7 @@ await this.TransactionAggregateManager.StartTransaction(transactionId,
estateId,
merchantId,
deviceIdentifier,
transactionAmount,
cancellationToken);

(String responseMessage, TransactionResponseCode responseCode) validationResult =
Expand Down Expand Up @@ -255,6 +260,28 @@ await this.TransactionAggregateManager.RecordAdditionalResponseData(estateId,
};
}

/// <summary>
/// Extracts the field from metadata.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="fieldName">Name of the field.</param>
/// <param name="additionalTransactionMetadata">The additional transaction metadata.</param>
/// <returns></returns>
private T ExtractFieldFromMetadata<T>(String fieldName,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dictionary<String, String> additionalTransactionMetadata)
{
if (additionalTransactionMetadata.ContainsKey(fieldName))
{
String fieldData = additionalTransactionMetadata[fieldName];
return (T)Convert.ChangeType(fieldData, typeof(T));
}
else
{
return default(T);
}

}

private async Task AddDeviceToMerchant(Guid estateId,
Guid merchantId,
String deviceIdentifier,
Expand Down
17 changes: 12 additions & 5 deletions TransactionProcessor.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public class TestData

public static TransactionResponseCode TransactionResponseCodeDeclinedByOperator = TransactionResponseCode.TransactionDeclinedByOperator;

public static Decimal TransactionAmount = 1000.00m;

public static OperatorResponse OperatorResponse =>
new OperatorResponse
{
Expand Down Expand Up @@ -386,7 +388,8 @@ public static TransactionAggregate GetCompletedTransactionAggregate()
TestData.TransactionReference,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);

transactionAggregate.AuthoriseTransactionLocally(TestData.AuthorisationCode, TestData.ResponseCode, TestData.ResponseMessage);

Expand All @@ -410,7 +413,8 @@ public static TransactionAggregate GetLocallyAuthorisedTransactionAggregate()
TestData.TransactionReference,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);

transactionAggregate.AuthoriseTransactionLocally(TestData.AuthorisationCode, TestData.ResponseCode, TestData.ResponseMessage);

Expand All @@ -427,7 +431,8 @@ public static TransactionAggregate GetLocallyDeclinedTransactionAggregate(Transa
TestData.TransactionReference,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);

transactionAggregate.DeclineTransactionLocally(TestData.GetResponseCodeAsString(transactionResponseCode),
TestData.GetResponseCodeMessage(transactionResponseCode));
Expand All @@ -445,7 +450,8 @@ public static TransactionAggregate GetDeclinedTransactionAggregate(TransactionRe
TestData.TransactionReference,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);

transactionAggregate.DeclineTransaction(TestData.OperatorIdentifier1,
TestData.DeclinedOperatorResponseCode,
Expand Down Expand Up @@ -476,7 +482,8 @@ public static TransactionAggregate GetStartedTransactionAggregate()
TestData.TransactionReference,
TestData.EstateId,
TestData.MerchantId,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);

return transactionAggregate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public TransactionHasStartedEvent()
/// <param name="transactionType">Type of the transaction.</param>
/// <param name="transactionReference">The transaction reference.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="transactionAmount">The transaction amount.</param>
private TransactionHasStartedEvent(Guid aggregateId,
Guid eventId,
Guid estateId,
Expand All @@ -42,7 +43,8 @@ private TransactionHasStartedEvent(Guid aggregateId,
String transactionNumber,
String transactionType,
String transactionReference,
String deviceIdentifier) : base(aggregateId, eventId)
String deviceIdentifier,
Decimal? transactionAmount) : base(aggregateId, eventId)
{
this.TransactionId = aggregateId;
this.EstateId = estateId;
Expand All @@ -52,6 +54,7 @@ private TransactionHasStartedEvent(Guid aggregateId,
this.TransactionType = transactionType;
this.TransactionReference = transactionReference;
this.DeviceIdentifier = deviceIdentifier;
this.TransactionAmount = transactionAmount;
}

#endregion
Expand All @@ -76,6 +79,15 @@ private TransactionHasStartedEvent(Guid aggregateId,
[JsonProperty]
public String DeviceIdentifier { get; private set; }

/// <summary>
/// Gets the transaction amount.
/// </summary>
/// <value>
/// The transaction amount.
/// </value>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public Decimal? TransactionAmount { get; private set; }

/// <summary>
/// Gets the merchant identifier.
/// </summary>
Expand Down Expand Up @@ -139,6 +151,7 @@ private TransactionHasStartedEvent(Guid aggregateId,
/// <param name="transactionType">Type of the transaction.</param>
/// <param name="transactionReference">The transaction reference.</param>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="transactionAmount">The transaction amount.</param>
/// <returns></returns>
public static TransactionHasStartedEvent Create(Guid aggregateId,
Guid estateId,
Expand All @@ -147,9 +160,10 @@ public static TransactionHasStartedEvent Create(Guid aggregateId,
String transactionNumber,
String transactionType,
String transactionReference,
String deviceIdentifier)
String deviceIdentifier,
Decimal? transactionAmount)
{
return new TransactionHasStartedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, transactionDateTime, transactionNumber, transactionType, transactionReference, deviceIdentifier);
return new TransactionHasStartedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, transactionDateTime, transactionNumber, transactionType, transactionReference, deviceIdentifier, transactionAmount);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public void TransactionHasStartedEvent_CanBeCreated_IsCreated(TransactionType tr
TestData.TransactionNumber,
transactionType.ToString(),
TestData.TransactionReference,
TestData.DeviceIdentifier);
TestData.DeviceIdentifier,
TestData.TransactionAmount);
transactionHasStartedEvent.ShouldNotBeNull();
transactionHasStartedEvent.AggregateId.ShouldBe(TestData.TransactionId);
transactionHasStartedEvent.TransactionAmount.ShouldBe(TestData.TransactionAmount);
transactionHasStartedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue);
transactionHasStartedEvent.EventId.ShouldNotBe(Guid.Empty);
transactionHasStartedEvent.TransactionId.ShouldBe(TestData.TransactionId);
Expand Down
Loading