forked from Adyen/adyen-dotnet-api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaymentsService.cs
249 lines (217 loc) · 16.1 KB
/
PaymentsService.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Adyen Checkout API
*
*
* The version of the OpenAPI document: 71
*
* 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.Checkout;
namespace Adyen.Service.Checkout
{
/// <summary>
/// PaymentsService Interface
/// </summary>
public interface IPaymentsService
{
/// <summary>
/// Get the list of brands on the card
/// </summary>
/// <param name="cardDetailsRequest"><see cref="CardDetailsRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="CardDetailsResponse"/>.</returns>
Model.Checkout.CardDetailsResponse CardDetails(CardDetailsRequest cardDetailsRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Get the list of brands on the card
/// </summary>
/// <param name="cardDetailsRequest"><see cref="CardDetailsRequest"/> - </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="CardDetailsResponse"/>.</returns>
Task<Model.Checkout.CardDetailsResponse> CardDetailsAsync(CardDetailsRequest cardDetailsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Start a transaction for donations
/// </summary>
/// <param name="donationPaymentRequest"><see cref="DonationPaymentRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="DonationPaymentResponse"/>.</returns>
Model.Checkout.DonationPaymentResponse Donations(DonationPaymentRequest donationPaymentRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Start a transaction for donations
/// </summary>
/// <param name="donationPaymentRequest"><see cref="DonationPaymentRequest"/> - </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="DonationPaymentResponse"/>.</returns>
Task<Model.Checkout.DonationPaymentResponse> DonationsAsync(DonationPaymentRequest donationPaymentRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Get the result of a payment session
/// </summary>
/// <param name="sessionId"><see cref="string"/> - A unique identifier of the session.</param>
/// <param name="sessionResult"><see cref="string"/> - The `sessionResult` value from the Drop-in or Component.</param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="SessionResultResponse"/>.</returns>
Model.Checkout.SessionResultResponse GetResultOfPaymentSession(string sessionId, string sessionResult, RequestOptions requestOptions = default);
/// <summary>
/// Get the result of a payment session
/// </summary>
/// <param name="sessionId"><see cref="string"/> - A unique identifier of the session.</param>
/// <param name="sessionResult"><see cref="string"/> - The `sessionResult` value from the Drop-in or Component.</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="SessionResultResponse"/>.</returns>
Task<Model.Checkout.SessionResultResponse> GetResultOfPaymentSessionAsync(string sessionId, string sessionResult, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Get a list of available payment methods
/// </summary>
/// <param name="paymentMethodsRequest"><see cref="PaymentMethodsRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="PaymentMethodsResponse"/>.</returns>
Model.Checkout.PaymentMethodsResponse PaymentMethods(PaymentMethodsRequest paymentMethodsRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Get a list of available payment methods
/// </summary>
/// <param name="paymentMethodsRequest"><see cref="PaymentMethodsRequest"/> - </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="PaymentMethodsResponse"/>.</returns>
Task<Model.Checkout.PaymentMethodsResponse> PaymentMethodsAsync(PaymentMethodsRequest paymentMethodsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Start a transaction
/// </summary>
/// <param name="paymentRequest"><see cref="PaymentRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="PaymentResponse"/>.</returns>
Model.Checkout.PaymentResponse Payments(PaymentRequest paymentRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Start a transaction
/// </summary>
/// <param name="paymentRequest"><see cref="PaymentRequest"/> - </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="PaymentResponse"/>.</returns>
Task<Model.Checkout.PaymentResponse> PaymentsAsync(PaymentRequest paymentRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Submit details for a payment
/// </summary>
/// <param name="paymentDetailsRequest"><see cref="PaymentDetailsRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="PaymentDetailsResponse"/>.</returns>
Model.Checkout.PaymentDetailsResponse PaymentsDetails(PaymentDetailsRequest paymentDetailsRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Submit details for a payment
/// </summary>
/// <param name="paymentDetailsRequest"><see cref="PaymentDetailsRequest"/> - </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="PaymentDetailsResponse"/>.</returns>
Task<Model.Checkout.PaymentDetailsResponse> PaymentsDetailsAsync(PaymentDetailsRequest paymentDetailsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
/// <summary>
/// Create a payment session
/// </summary>
/// <param name="createCheckoutSessionRequest"><see cref="CreateCheckoutSessionRequest"/> - </param>
/// <param name="requestOptions"><see cref="RequestOptions"/> - Additional request options.</param>
/// <returns><see cref="CreateCheckoutSessionResponse"/>.</returns>
Model.Checkout.CreateCheckoutSessionResponse Sessions(CreateCheckoutSessionRequest createCheckoutSessionRequest = default, RequestOptions requestOptions = default);
/// <summary>
/// Create a payment session
/// </summary>
/// <param name="createCheckoutSessionRequest"><see cref="CreateCheckoutSessionRequest"/> - </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="CreateCheckoutSessionResponse"/>.</returns>
Task<Model.Checkout.CreateCheckoutSessionResponse> SessionsAsync(CreateCheckoutSessionRequest createCheckoutSessionRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default);
}
/// <summary>
/// Represents a collection of functions to interact with the PaymentsService API endpoints
/// </summary>
public class PaymentsService : AbstractService, IPaymentsService
{
private readonly string _baseUrl;
public PaymentsService(Client client) : base(client)
{
_baseUrl = CreateBaseUrl("https://checkout-test.adyen.com/v71");
}
public Model.Checkout.CardDetailsResponse CardDetails(CardDetailsRequest cardDetailsRequest = default, RequestOptions requestOptions = default)
{
return CardDetailsAsync(cardDetailsRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.CardDetailsResponse> CardDetailsAsync(CardDetailsRequest cardDetailsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/cardDetails";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.CardDetailsResponse>(cardDetailsRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.DonationPaymentResponse Donations(DonationPaymentRequest donationPaymentRequest = default, RequestOptions requestOptions = default)
{
return DonationsAsync(donationPaymentRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.DonationPaymentResponse> DonationsAsync(DonationPaymentRequest donationPaymentRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/donations";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.DonationPaymentResponse>(donationPaymentRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.SessionResultResponse GetResultOfPaymentSession(string sessionId, string sessionResult, RequestOptions requestOptions = default)
{
return GetResultOfPaymentSessionAsync(sessionId, sessionResult, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.SessionResultResponse> GetResultOfPaymentSessionAsync(string sessionId, string sessionResult, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
// Build the query string
var queryParams = new Dictionary<string, string>();
queryParams.Add("sessionResult", sessionResult);
var endpoint = _baseUrl + $"/sessions/{sessionId}" + ToQueryString(queryParams);
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.SessionResultResponse>(null, requestOptions, new HttpMethod("GET"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.PaymentMethodsResponse PaymentMethods(PaymentMethodsRequest paymentMethodsRequest = default, RequestOptions requestOptions = default)
{
return PaymentMethodsAsync(paymentMethodsRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.PaymentMethodsResponse> PaymentMethodsAsync(PaymentMethodsRequest paymentMethodsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/paymentMethods";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.PaymentMethodsResponse>(paymentMethodsRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.PaymentResponse Payments(PaymentRequest paymentRequest = default, RequestOptions requestOptions = default)
{
return PaymentsAsync(paymentRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.PaymentResponse> PaymentsAsync(PaymentRequest paymentRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/payments";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.PaymentResponse>(paymentRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.PaymentDetailsResponse PaymentsDetails(PaymentDetailsRequest paymentDetailsRequest = default, RequestOptions requestOptions = default)
{
return PaymentsDetailsAsync(paymentDetailsRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.PaymentDetailsResponse> PaymentsDetailsAsync(PaymentDetailsRequest paymentDetailsRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/payments/details";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.PaymentDetailsResponse>(paymentDetailsRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
public Model.Checkout.CreateCheckoutSessionResponse Sessions(CreateCheckoutSessionRequest createCheckoutSessionRequest = default, RequestOptions requestOptions = default)
{
return SessionsAsync(createCheckoutSessionRequest, requestOptions).ConfigureAwait(false).GetAwaiter().GetResult();
}
public async Task<Model.Checkout.CreateCheckoutSessionResponse> SessionsAsync(CreateCheckoutSessionRequest createCheckoutSessionRequest = default, RequestOptions requestOptions = default, CancellationToken cancellationToken = default)
{
var endpoint = _baseUrl + "/sessions";
var resource = new ServiceResource(this, endpoint);
return await resource.RequestAsync<Model.Checkout.CreateCheckoutSessionResponse>(createCheckoutSessionRequest.ToJson(), requestOptions, new HttpMethod("POST"), cancellationToken).ConfigureAwait(false);
}
}
}