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 @@ -203,26 +203,28 @@ private async Task HandleSpecificDomainEvent(CustomerEmailReceiptRequestedEvent

TransactionAggregate transactionAggregate = await this.TransactionAggregateManager.GetAggregate(domainEvent.EstateId, domainEvent.TransactionId, cancellationToken);

var merchant = await this.EstateClient.GetMerchant(this.TokenResponse.AccessToken, domainEvent.EstateId, domainEvent.MerchantId, cancellationToken);
MerchantResponse merchant = await this.EstateClient.GetMerchant(this.TokenResponse.AccessToken, domainEvent.EstateId, domainEvent.MerchantId, cancellationToken);

// Determine the body of the email
String receiptMessage = await this.TransactionReceiptBuilder.GetEmailReceiptMessage(transactionAggregate.GetTransaction(), merchant, cancellationToken);

// Send the message
await this.SendEmailMessage(this.TokenResponse.AccessToken, domainEvent.EstateId, "Transaction Successful", receiptMessage, domainEvent.CustomerEmailAddress, cancellationToken);
await this.SendEmailMessage(this.TokenResponse.AccessToken, domainEvent.EventId, domainEvent.EstateId, "Transaction Successful", receiptMessage, domainEvent.CustomerEmailAddress, cancellationToken);

}

/// <summary>
/// Sends the email message.
/// </summary>
/// <param name="accessToken">The access token.</param>
/// <param name="messageId">The message identifier.</param>
/// <param name="estateId">The estate identifier.</param>
/// <param name="subject">The subject.</param>
/// <param name="body">The body.</param>
/// <param name="emailAddress">The email address.</param>
/// <param name="cancellationToken">The cancellation token.</param>
private async Task SendEmailMessage(String accessToken,
Guid messageId,
Guid estateId,
String subject,
String body,
Expand All @@ -231,6 +233,7 @@ private async Task SendEmailMessage(String accessToken,
{
SendEmailRequest sendEmailRequest = new SendEmailRequest
{
MessageId = messageId,
Body = body,
ConnectionIdentifier = estateId,
FromAddress = "golfhandicapping@btinternet.com", // TODO: lookup from config
Expand All @@ -244,7 +247,19 @@ private async Task SendEmailMessage(String accessToken,

// TODO: may decide to record the message Id againsts the Transaction Aggregate in future, but for now
// we wont do this...
await this.MessagingServiceClient.SendEmail(accessToken, sendEmailRequest, cancellationToken);
try
{
await this.MessagingServiceClient.SendEmail(accessToken, sendEmailRequest, cancellationToken);
}
catch(Exception ex) when (ex.InnerException != null && ex.InnerException.GetType() == typeof(InvalidOperationException))
{
// Only bubble up if not a duplicate message
if (ex.InnerException.Message.Contains("Cannot send a message to provider that has already been sent", StringComparison.InvariantCultureIgnoreCase) == false)
{
throw;
}
}

}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="EstateManagement.Client" Version="1.0.2.2-build25" />
<PackageReference Include="MessagingService.Client" Version="1.0.3-build28" />
<PackageReference Include="MessagingService.Client" Version="1.0.3.1" />
<PackageReference Include="SecurityService.Client" Version="1.0.0" />
<PackageReference Include="Shared" Version="0.0.15.7" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="0.0.15.7" />
Expand Down