-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29bb915
commit a8932d0
Showing
8 changed files
with
1,304 additions
and
0 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
lib/PCPServerSDKDotNet/Endpoints/CommerceCaseApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
namespace PCPServerSDKDotNet.Endpoints; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using PCPServerSDKDotNet.Errors; | ||
using PCPServerSDKDotNet.Models; | ||
using PCPServerSDKDotNet.Queries; | ||
using PCPServerSDKDotNet.Utils; | ||
|
||
public class CommerceCaseApiClient : BaseApiClient | ||
{ | ||
public CommerceCaseApiClient(CommunicatorConfiguration config) : base(config) { } | ||
|
||
public async Task<CreateCommerceCaseResponse> CreateCommerceCaseRequestAsync(string merchantId, CreateCommerceCaseRequest payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Post, url) | ||
{ | ||
Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
return await MakeApiCallAsync<CreateCommerceCaseResponse>(request); | ||
} | ||
|
||
public async Task<CommerceCaseResponse> GetCommerceCaseRequestAsync(string merchantId, string commerceCaseId) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}" | ||
}.Uri; | ||
|
||
HttpRequestMessage request = new(HttpMethod.Get, url); | ||
|
||
return await MakeApiCallAsync<CommerceCaseResponse>(request); | ||
} | ||
|
||
public async Task<List<CommerceCaseResponse>> GetCommerceCasesRequestAsync(string merchantId, GetCommerceCasesQuery? queryParams = null) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
|
||
UriBuilder uriBuilder = new() | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}" | ||
}; | ||
|
||
var queryParameters = queryParams?.ToQueryMap(); | ||
if (queryParameters != null) | ||
{ | ||
var query = System.Web.HttpUtility.ParseQueryString(string.Empty); | ||
foreach (var param in queryParameters) | ||
{ | ||
query[param.Key] = param.Value; | ||
} | ||
uriBuilder.Query = query.ToString(); | ||
} | ||
|
||
HttpRequestMessage request = new(HttpMethod.Get, uriBuilder.Uri); | ||
|
||
return await MakeApiCallAsync<List<CommerceCaseResponse>>(request); | ||
} | ||
|
||
public async Task UpdateCommerceCaseRequestAsync(string merchantId, string commerceCaseId, Customer payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Patch, url) | ||
{ | ||
Content = new StringContent("{\"customer\":" + jsonString + "}", System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
await MakeApiCallAsync(request); | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
lib/PCPServerSDKDotNet/Endpoints/OrderManagementCheckoutActionsApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
namespace PCPServerSDKDotNet.Endpoints; | ||
|
||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
using PCPServerSDKDotNet.Errors; | ||
using PCPServerSDKDotNet.Models; | ||
using PCPServerSDKDotNet.Utils; | ||
|
||
public class OrderManagementCheckoutActionsApiClient : BaseApiClient | ||
{ | ||
public OrderManagementCheckoutActionsApiClient(CommunicatorConfiguration config) : base(config) { } | ||
|
||
public async Task<OrderResponse> CreateOrderAsync(string merchantId, string commerceCaseId, string checkoutId, OrderRequest payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(checkoutId)) | ||
throw new ArgumentException(CHECKOUT_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}/{PCP_PATH_SEGMENT_CHECKOUTS}/{checkoutId}/order" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Post, url) | ||
{ | ||
Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
return await MakeApiCallAsync<OrderResponse>(request); | ||
} | ||
|
||
public async Task<DeliverResponse> DeliverOrderAsync(string merchantId, string commerceCaseId, string checkoutId, DeliverRequest payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(checkoutId)) | ||
throw new ArgumentException(CHECKOUT_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}/{PCP_PATH_SEGMENT_CHECKOUTS}/{checkoutId}/deliver" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Post, url) | ||
{ | ||
Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
return await MakeApiCallAsync<DeliverResponse>(request); | ||
} | ||
|
||
public async Task<ReturnResponse> ReturnOrderAsync(string merchantId, string commerceCaseId, string checkoutId, ReturnRequest payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(checkoutId)) | ||
throw new ArgumentException(CHECKOUT_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}/{PCP_PATH_SEGMENT_CHECKOUTS}/{checkoutId}/return" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Post, url) | ||
{ | ||
Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
return await MakeApiCallAsync<ReturnResponse>(request); | ||
} | ||
|
||
public async Task<CancelResponse> CancelOrderAsync(string merchantId, string commerceCaseId, string checkoutId, CancelRequest payload) | ||
{ | ||
if (string.IsNullOrEmpty(merchantId)) | ||
throw new ArgumentException(MERCHANT_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(commerceCaseId)) | ||
throw new ArgumentException(COMMERCE_CASE_ID_REQUIRED_ERROR); | ||
if (string.IsNullOrEmpty(checkoutId)) | ||
throw new ArgumentException(CHECKOUT_ID_REQUIRED_ERROR); | ||
if (payload == null) | ||
throw new ArgumentException(PAYLOAD_REQUIRED_ERROR); | ||
|
||
Uri url = new UriBuilder | ||
{ | ||
Scheme = HTTPS_SCHEME, | ||
Host = GetConfig().Host, | ||
Path = $"{PCP_PATH_SEGMENT_VERSION}/{merchantId}/{PCP_PATH_SEGMENT_COMMERCE_CASES}/{commerceCaseId}/{PCP_PATH_SEGMENT_CHECKOUTS}/{checkoutId}/cancel" | ||
}.Uri; | ||
|
||
string jsonString = JsonConvert.SerializeObject(payload); | ||
|
||
HttpRequestMessage request = new(HttpMethod.Post, url) | ||
{ | ||
Content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json") | ||
}; | ||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | ||
|
||
return await MakeApiCallAsync<CancelResponse>(request); | ||
} | ||
} |
Oops, something went wrong.