diff --git a/TransactionProcessor.Client/TransactionProcessorClient.cs b/TransactionProcessor.Client/TransactionProcessorClient.cs
index d13f4cd1..70487eea 100644
--- a/TransactionProcessor.Client/TransactionProcessorClient.cs
+++ b/TransactionProcessor.Client/TransactionProcessorClient.cs
@@ -1,5 +1,4 @@
-namespace TransactionProcessor.Client
-{
+namespace TransactionProcessor.Client{
using System;
using System.Collections.Generic;
using System.Net.Http;
@@ -11,32 +10,17 @@
using DataTransferObjects;
using Newtonsoft.Json;
- ///
- ///
- ///
- ///
- ///
- public class TransactionProcessorClient : ClientProxyBase, ITransactionProcessorClient
- {
+ public class TransactionProcessorClient : ClientProxyBase, ITransactionProcessorClient{
#region Fields
- ///
- /// The base address
- ///
private readonly String BaseAddress;
#endregion
#region Constructors
- ///
- /// Initializes a new instance of the class.
- ///
- /// The base address resolver.
- /// The HTTP client.
public TransactionProcessorClient(Func baseAddressResolver,
- HttpClient httpClient) : base(httpClient)
- {
+ HttpClient httpClient) : base(httpClient){
this.BaseAddress = baseAddressResolver("TransactionProcessorApi");
// Add the API version header
@@ -47,43 +31,63 @@ public TransactionProcessorClient(Func baseAddressResolver,
#region Methods
- ///
- /// Performs the transaction.
- ///
- /// The access token.
- /// The transaction request.
- /// The cancellation token.
- ///
- public async Task PerformTransaction(String accessToken,
- SerialisedMessage transactionRequest,
- CancellationToken cancellationToken)
- {
- SerialisedMessage response = null;
+ public async Task CreateFloatForContractProduct(String accessToken, Guid estateId, CreateFloatForContractProductRequest createFloatForContractProductRequest, CancellationToken cancellationToken){
+ CreateFloatForContractProductResponse response = null;
- String requestUri = $"{this.BaseAddress}/api/transactions";
+ String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/floats";
+
+ try{
+ response = await this.Post(requestUri, createFloatForContractProductRequest, accessToken, cancellationToken);
+ }
+ catch(Exception ex){
+ // An exception has occurred, add some additional information to the message
+ Exception exception = new Exception("Error creating contract product float.", ex);
- try
- {
- String requestSerialised = JsonConvert.SerializeObject(transactionRequest);
+ throw exception;
+ }
+
+ return response;
+ }
+
+ public async Task GetMerchantBalance(String accessToken,
+ Guid estateId,
+ Guid merchantId,
+ CancellationToken cancellationToken,
+ Boolean liveBalance = true){
+ String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/balance";
- StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
+ if (liveBalance){
+ requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/livebalance";
+ }
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+ MerchantBalanceResponse response = null;
+ try{
+ response = await this.Get(requestUri, accessToken, cancellationToken);
+ }
+ catch(Exception ex){
+ // An exception has occurred, add some additional information to the message
+ Exception exception = new Exception("Error getting merchant balance.", ex);
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
+ throw exception;
+ }
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ return response;
+ }
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
+ public async Task> GetMerchantBalanceHistory(String accessToken,
+ Guid estateId,
+ Guid merchantId,
+ DateTime startDate,
+ DateTime endDate,
+ CancellationToken cancellationToken){
+ String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/balancehistory?startDate={startDate:yyyy-MM-dd}&endDate={endDate:yyyy-MM-dd}";
+ List response = null;
+ try{
+ response = await this.Get>(requestUri, accessToken, cancellationToken);
}
- catch(Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error posting transaction.", ex);
+ Exception exception = new Exception("Error getting merchant balance.", ex);
throw exception;
}
@@ -92,31 +96,18 @@ public async Task PerformTransaction(String accessToken,
}
public async Task GetSettlementByDate(String accessToken,
- DateTime settlementDate,
- Guid estateId,
- Guid merchantId,
- CancellationToken cancellationToken)
- {
+ DateTime settlementDate,
+ Guid estateId,
+ Guid merchantId,
+ CancellationToken cancellationToken){
SettlementResponse response = null;
String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/merchants/{merchantId}/pending";
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
-
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
-
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
-
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
+ try{
+ response = await this.Get(requestUri, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
Exception exception = new Exception("Error getting settlment.", ex);
@@ -126,99 +117,61 @@ public async Task GetSettlementByDate(String accessToken,
return response;
}
- public async Task ProcessSettlement(String accessToken,
- DateTime settlementDate,
- Guid estateId,
- Guid merchantId,
- CancellationToken cancellationToken)
- {
- String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/merchants/{merchantId}";
-
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
-
- StringContent requestContent = new StringContent(String.Empty);
-
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, requestContent, cancellationToken);
+ public async Task GetVoucherByCode(String accessToken,
+ Guid estateId,
+ String voucherCode,
+ CancellationToken cancellationToken){
+ GetVoucherResponse response = null;
- // Process the response
- await this.HandleResponse(httpResponse, cancellationToken);
+ String requestUri = $"{this.BaseAddress}/api/vouchers?estateId={estateId}&voucherCode={voucherCode}";
+ try{
+ response = await this.Get(requestUri, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error processing settlment.", ex);
+ Exception exception = new Exception("Error getting voucher.", ex);
throw exception;
}
- }
-
- public async Task ResendEmailReceipt(String accessToken,
- Guid estateId,
- Guid transactionId,
- CancellationToken cancellationToken) {
- String requestUri = $"{this.BaseAddress}/api/{estateId}/transactions/{transactionId}/resendreceipt";
-
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- StringContent requestContent = new StringContent(String.Empty);
+ return response;
+ }
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, requestContent, cancellationToken);
+ public async Task GetVoucherByTransactionId(String accessToken,
+ Guid estateId,
+ Guid transactionId,
+ CancellationToken cancellationToken){
+ GetVoucherResponse response = null;
- // Process the response
- await this.HandleResponse(httpResponse, cancellationToken);
+ String requestUri = $"{this.BaseAddress}/api/vouchers?estateId={estateId}&transactionId={transactionId}";
+ try{
+ response = await this.Get(requestUri, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error requesting receipt resend.", ex);
+ Exception exception = new Exception("Error getting voucher.", ex);
throw exception;
}
- }
-
- public async Task GetMerchantBalance(String accessToken,
- Guid estateId,
- Guid merchantId,
- CancellationToken cancellationToken,
- Boolean liveBalance = true){
-
- String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/balance";
-
- if (liveBalance){
- requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/livebalance";
- }
-
- MerchantBalanceResponse response = null;
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
-
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
+ return response;
+ }
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ public async Task PerformTransaction(String accessToken,
+ SerialisedMessage transactionRequest,
+ CancellationToken cancellationToken){
+ SerialisedMessage response = null;
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
+ String requestUri = $"{this.BaseAddress}/api/transactions";
+ try{
+ response = await this.Post(requestUri, transactionRequest, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error getting merchant balance.", ex);
+ Exception exception = new Exception("Error posting transaction.", ex);
throw exception;
}
@@ -226,66 +179,51 @@ public async Task GetMerchantBalance(String accessToken
return response;
}
- public async Task> GetMerchantBalanceHistory(String accessToken,
- Guid estateId,
- Guid merchantId,
- DateTime startDate,
- DateTime endDate,
- CancellationToken cancellationToken) {
- String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/merchants/{merchantId}/balancehistory?startDate={startDate:yyyy-MM-dd}&endDate={endDate:yyyy-MM-dd}";
- List response = null;
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
-
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
-
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ public async Task ProcessSettlement(String accessToken,
+ DateTime settlementDate,
+ Guid estateId,
+ Guid merchantId,
+ CancellationToken cancellationToken){
+ String requestUri = $"{this.BaseAddress}/api/settlements/{settlementDate.Date:yyyy-MM-dd}/estates/{estateId}/merchants/{merchantId}";
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject>(content);
+ try{
+ await this.Post(requestUri, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error getting merchant balance.", ex);
+ Exception exception = new Exception("Error processing settlment.", ex);
throw exception;
}
-
- return response;
}
- public async Task GetVoucherByTransactionId(String accessToken,
- Guid estateId,
- Guid transactionId,
- CancellationToken cancellationToken)
- {
- GetVoucherResponse response = null;
+ public async Task RecordFloatCreditPurchase(String accessToken, Guid estateId, RecordFloatCreditPurchaseRequest recordFloatCreditPurchaseRequest, CancellationToken cancellationToken){
+ String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/floats";
- String requestUri = $"{this.BaseAddress}/api/vouchers?estateId={estateId}&transactionId={transactionId}";
+ try{
+ await this.Put(requestUri, recordFloatCreditPurchaseRequest, accessToken, cancellationToken);
+ }
+ catch(Exception ex){
+ // An exception has occurred, add some additional information to the message
+ Exception exception = new Exception("Error crediting contract product float.", ex);
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+ throw exception;
+ }
+ }
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
+ public async Task RedeemVoucher(String accessToken,
+ RedeemVoucherRequest redeemVoucherRequest,
+ CancellationToken cancellationToken){
+ RedeemVoucherResponse response = null;
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ String requestUri = $"{this.BaseAddress}/api/vouchers";
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
+ try{
+ response = await this.Put(requestUri, redeemVoucherRequest, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error getting voucher.", ex);
+ Exception exception = new Exception("Error redeeming voucher.", ex);
throw exception;
}
@@ -293,147 +231,106 @@ public async Task GetVoucherByTransactionId(String accessTok
return response;
}
- public async Task GetVoucherByCode(String accessToken,
- Guid estateId,
- String voucherCode,
- CancellationToken cancellationToken)
- {
- GetVoucherResponse response = null;
-
- String requestUri = $"{this.BaseAddress}/api/vouchers?estateId={estateId}&voucherCode={voucherCode}";
-
- try
- {
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
-
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
-
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ public async Task ResendEmailReceipt(String accessToken,
+ Guid estateId,
+ Guid transactionId,
+ CancellationToken cancellationToken){
+ String requestUri = $"{this.BaseAddress}/api/{estateId}/transactions/{transactionId}/resendreceipt";
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
+ try{
+ await this.Post(requestUri, accessToken, cancellationToken);
}
- catch (Exception ex)
- {
+ catch(Exception ex){
// An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error getting voucher.", ex);
+ Exception exception = new Exception("Error requesting receipt resend.", ex);
throw exception;
}
-
- return response;
}
- ///
- /// Redeems the voucher.
- ///
- /// The access token.
- /// The redeem voucher request.
- /// The cancellation token.
- ///
- public async Task RedeemVoucher(String accessToken,
- RedeemVoucherRequest redeemVoucherRequest,
- CancellationToken cancellationToken)
- {
- RedeemVoucherResponse response = null;
+ private async Task Get(String requestUri, String accessToken, CancellationToken cancellationToken){
+ // Add the access token to the client headers
+ this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- String requestUri = $"{this.BaseAddress}/api/vouchers";
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken);
- try
- {
- String requestSerialised = JsonConvert.SerializeObject(redeemVoucherRequest);
+ // Process the response
+ String content = await this.HandleResponse(httpResponse, cancellationToken);
- StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
+ // call was successful so now deserialise the body to the response object
+ return JsonConvert.DeserializeObject(content);
+ }
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+ private async Task Post(String requestUri, String accessToken, CancellationToken cancellationToken){
+ StringContent httpContent = new StringContent("");
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken);
+ // Add the access token to the client headers
+ this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
- }
- catch (Exception ex)
- {
- // An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error redeeming voucher.", ex);
+ // Process the response
+ await this.HandleResponse(httpResponse, cancellationToken);
+ }
- throw exception;
- }
+ private async Task Post(String requestUri, TRequest requestObject, String accessToken, CancellationToken cancellationToken){
+ HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
- return response;
- }
+ String requestSerialised = JsonConvert.SerializeObject(requestObject);
- public async Task CreateFloatForContractProduct(String accessToken, Guid estateId, CreateFloatForContractProductRequest createFloatForContractProductRequest, CancellationToken cancellationToken){
- CreateFloatForContractProductResponse response = null;
+ StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
- String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/floats";
+ // Add the access token to the client headers
+ this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- try
- {
- String requestSerialised = JsonConvert.SerializeObject(createFloatForContractProductRequest);
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
- StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
+ // Process the response
+ String content = await this.HandleResponse(httpResponse, cancellationToken);
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+ // call was successful so now deserialise the body to the response object
+ return JsonConvert.DeserializeObject(content);
+ }
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
+ private async Task Put(String requestUri, TRequest requestObject, String accessToken, CancellationToken cancellationToken){
+ String requestSerialised = JsonConvert.SerializeObject(requestObject);
- // Process the response
- String content = await this.HandleResponse(httpResponse, cancellationToken);
+ StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
- // call was successful so now deserialise the body to the response object
- response = JsonConvert.DeserializeObject(content);
- }
- catch (Exception ex)
- {
- // An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error creating contract product float.", ex);
+ // Add the access token to the client headers
+ this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- throw exception;
- }
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken);
- return response;
+ // Process the response
+ await this.HandleResponse(httpResponse, cancellationToken);
}
- public async Task RecordFloatCreditPurchase(String accessToken, Guid estateId, RecordFloatCreditPurchaseRequest recordFloatCreditPurchaseRequest, CancellationToken cancellationToken){
- String requestUri = $"{this.BaseAddress}/api/estates/{estateId}/floats";
+ #endregion
- try
- {
- String requestSerialised = JsonConvert.SerializeObject(recordFloatCreditPurchaseRequest);
- StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
+ private async Task Put(String requestUri, TRequest requestObject, String accessToken, CancellationToken cancellationToken){
+ HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, requestUri);
- // Add the access token to the client headers
- this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+ String requestSerialised = JsonConvert.SerializeObject(requestObject);
+ StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
- // Make the Http Call here
- HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken);
+ // Add the access token to the client headers
+ this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- // Process the response
- await this.HandleResponse(httpResponse, cancellationToken);
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.PutAsync(requestUri, httpContent, cancellationToken);
- }
- catch (Exception ex)
- {
- // An exception has occurred, add some additional information to the message
- Exception exception = new Exception("Error crediting contract product float.", ex);
+ // Process the response
+ String content = await this.HandleResponse(httpResponse, cancellationToken);
- throw exception;
- }
+ // call was successful so now deserialise the body to the response object
+ return JsonConvert.DeserializeObject(content);
}
-
- #endregion
}
}
\ No newline at end of file
diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
index 38fc7b8e..be9f276e 100644
--- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
+++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
@@ -61,6 +61,9 @@
Always
+
+ Always
+