forked from Adyen/adyen-dotnet-api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionsService.cs
123 lines (111 loc) · 9.53 KB
/
TransactionsService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Transfers API
*
*
* The version of the OpenAPI document: 3
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Adyen.Model;
using Adyen.Model.Transfers;
namespace Adyen.Service.Transfers
{
/// <summary>
/// TransactionsService Interface
/// </summary>
public interface ITransactionsService
{
/// <summary>
/// Get all transactions
/// </summary>
/// <param name="balancePlatform"><see cref="string"/> - Unique identifier of the [balance platform](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/balancePlatforms/{id}__queryParam_id).</param>
/// <param name="paymentInstrumentId"><see cref="string"/> - Unique identifier of the [payment instrument](https://docs.adyen.com/api-explorer/balanceplatform/latest/get/paymentInstruments/_id_).</param>
/// <param name="accountHolderId"><see cref="string"/> - Unique identifier of the [account holder](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/accountHolders/{id}__queryParam_id).</param>
/// <param name="balanceAccountId"><see cref="string"/> - Unique identifier of the [balance account](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/balanceAccounts/{id}__queryParam_id).</param>
/// <param name="cursor"><see cref="string"/> - The `cursor` returned in the links of the previous response.</param>
/// <param name="createdSince"><see cref="DateTime"/> - Only include transactions that have been created on or after this point in time. The value must be in ISO 8601 format. For example, **2021-05-30T15:07:40Z**.</param>
/// <param name="createdUntil"><see cref="DateTime"/> - Only include transactions that have been created on or before this point in time. The value must be in ISO 8601 format. For example, **2021-05-30T15:07:40Z**.</param>
/// <param name="limit"><see cref="int?"/> - The number of items returned per page, maximum of 100 items. By default, the response returns 10 items per page.</param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="TransactionSearchResponse"/>.</returns>
Model.Transfers.TransactionSearchResponse GetAllTransactions(DateTime createdSince, DateTime createdUntil, string balancePlatform = default, string paymentInstrumentId = default, string accountHolderId = default, string balanceAccountId = default, string cursor = default, int? limit = default, RequestOptions requestOptions = default);
/// <summary>
/// Get all transactions
/// </summary>
/// <param name="balancePlatform"><see cref="string"/> - Unique identifier of the [balance platform](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/balancePlatforms/{id}__queryParam_id).</param>
/// <param name="paymentInstrumentId"><see cref="string"/> - Unique identifier of the [payment instrument](https://docs.adyen.com/api-explorer/balanceplatform/latest/get/paymentInstruments/_id_).</param>
/// <param name="accountHolderId"><see cref="string"/> - Unique identifier of the [account holder](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/accountHolders/{id}__queryParam_id).</param>
/// <param name="balanceAccountId"><see cref="string"/> - Unique identifier of the [balance account](https://docs.adyen.com/api-explorer/#/balanceplatform/latest/get/balanceAccounts/{id}__queryParam_id).</param>
/// <param name="cursor"><see cref="string"/> - The `cursor` returned in the links of the previous response.</param>
/// <param name="createdSince"><see cref="DateTime"/> - Only include transactions that have been created on or after this point in time. The value must be in ISO 8601 format. For example, **2021-05-30T15:07:40Z**.</param>
/// <param name="createdUntil"><see cref="DateTime"/> - Only include transactions that have been created on or before this point in time. The value must be in ISO 8601 format. For example, **2021-05-30T15:07:40Z**.</param>
/// <param name="limit"><see cref="int?"/> - The number of items returned per page, maximum of 100 items. By default, the response returns 10 items per page.</param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <param name="cancellationToken"> A CancellationToken enables cooperative cancellation between threads, thread pool work items, or Task objects.</param>
/// <returns>Task of <see cref="TransactionSearchResponse"/>.</returns>
Task<Model.Transfers.TransactionSearchResponse> GetAllTransactionsAsync(DateTime createdSince, DateTime createdUntil, string balancePlatform = default, string paymentInstrumentId = default, string accountHolderId = default, string balanceAccountId = default, string cursor = default, int? limit = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Get a transaction
/// </summary>
/// <param name="id"><see cref="string"/> - Unique identifier of the transaction.</param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="Transaction"/>.</returns>
Model.Transfers.Transaction GetTransaction(string id, RequestOptions requestOptions = default);
/// <summary>
/// Get a transaction
/// </summary>
/// <param name="id"><see cref="string"/> - Unique identifier of the transaction.</param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <param name="cancellationToken"> A CancellationToken enables cooperative cancellation between threads, thread pool work items, or Task objects.</param>
/// <returns>Task of <see cref="Transaction"/>.</returns>
Task<Model.Transfers.Transaction> GetTransactionAsync(string id, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
}
/// <summary>
/// Represents a collection of functions to interact with the TransactionsService API endpoints
/// </summary>
public class TransactionsService : AbstractService, ITransactionsService
{
private readonly string _baseUrl;
public TransactionsService(Client client) : base(client)
{
_baseUrl = CreateBaseUrl("https://balanceplatform-api-test.adyen.com/btl/v3");
}
public Model.Transfers.TransactionSearchResponse GetAllTransactions(DateTime createdSince, DateTime createdUntil, string balancePlatform = default, string paymentInstrumentId = default, string accountHolderId = default, string balanceAccountId = default, string cursor = default, int? limit = default, RequestOptions requestOptions = default)
{
return GetAllTransactionsAsync(createdSince, createdUntil, balancePlatform, paymentInstrumentId, accountHolderId, balanceAccountId, cursor, limit, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Transfers.TransactionSearchResponse> GetAllTransactionsAsync(DateTime createdSince, DateTime createdUntil, string balancePlatform = default, string paymentInstrumentId = default, string accountHolderId = default, string balanceAccountId = default, string cursor = default, int? limit = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
// Build the query string
var queryParams = new Dictionary<string, string>();
if (balancePlatform != null) queryParams.Add("balancePlatform", balancePlatform);
if (paymentInstrumentId != null) queryParams.Add("paymentInstrumentId", paymentInstrumentId);
if (accountHolderId != null) queryParams.Add("accountHolderId", accountHolderId);
if (balanceAccountId != null) queryParams.Add("balanceAccountId", balanceAccountId);
if (cursor != null) queryParams.Add("cursor", cursor);
queryParams.Add("createdSince", createdSince.ToString());
queryParams.Add("createdUntil", createdUntil.ToString());
if (limit != null) queryParams.Add("limit", limit.ToString());
var endpoint = _baseUrl + "/transactions" + ToQueryString(queryParams);
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Transfers.TransactionSearchResponse>(null, requestOptions, new HttpMethod("GET"), cancellationToken).ConfigureAwait(false);
}
public Model.Transfers.Transaction GetTransaction(string id, RequestOptions requestOptions = default)
{
return GetTransactionAsync(id, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Transfers.Transaction> GetTransactionAsync(string id, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + $"/transactions/{id}";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Transfers.Transaction>(null, requestOptions, new HttpMethod("GET"), cancellationToken).ConfigureAwait(false);
}
}
}