1+ //------------------------------------------------------------------------------
2+ // <auto-generated>
3+ // This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
4+ //
5+ // Changes to this file may cause incorrect behavior and will be lost when
6+ // the code is regenerated.
7+ // </auto-generated>
8+ //------------------------------------------------------------------------------
9+ #nullable enable
10+ namespace Gr4vy
11+ {
12+ using Gr4vy . Hooks ;
13+ using Gr4vy . Models . Components ;
14+ using Gr4vy . Models . Errors ;
15+ using Gr4vy . Models . Requests ;
16+ using Gr4vy . Utils ;
17+ using Gr4vy . Utils . Retries ;
18+ using Newtonsoft . Json ;
19+ using System ;
20+ using System . Collections . Generic ;
21+ using System . Net . Http ;
22+ using System . Net . Http . Headers ;
23+ using System . Threading . Tasks ;
24+
25+ public interface IAll
26+ {
27+
28+ /// <summary>
29+ /// Create batch transaction refund
30+ ///
31+ /// <remarks>
32+ /// Create a refund for all instruments on a transaction.
33+ /// </remarks>
34+ /// </summary>
35+ Task < CollectionNoCursorRefund > CreateAsync ( string transactionId , double ? timeoutInSeconds = 1D , string ? merchantAccountId = null , TransactionRefundAllCreate ? transactionRefundAllCreate = null ) ;
36+ }
37+
38+ public class All : IAll
39+ {
40+ public SDKConfig SDKConfiguration { get ; private set ; }
41+ private const string _language = "csharp" ;
42+ private const string _sdkVersion = "0.0.9" ;
43+ private const string _sdkGenVersion = "2.598.22" ;
44+ private const string _openapiDocVersion = "1.0.0" ;
45+ private const string _userAgent = "speakeasy-sdk/csharp 0.0.9 2.598.22 1.0.0 Gr4vy" ;
46+ private string _serverUrl = "" ;
47+ private ISpeakeasyHttpClient _client ;
48+ private Func < Gr4vy . Models . Components . Security > ? _securitySource ;
49+
50+ public All ( ISpeakeasyHttpClient client , Func < Gr4vy . Models . Components . Security > ? securitySource , string serverUrl , SDKConfig config )
51+ {
52+ _client = client ;
53+ _securitySource = securitySource ;
54+ _serverUrl = serverUrl ;
55+ SDKConfiguration = config ;
56+ }
57+
58+ public async Task < CollectionNoCursorRefund > CreateAsync ( string transactionId , double ? timeoutInSeconds = 1D , string ? merchantAccountId = null , TransactionRefundAllCreate ? transactionRefundAllCreate = null )
59+ {
60+ var request = new CreateFullTransactionRefundRequest ( )
61+ {
62+ TransactionId = transactionId ,
63+ TimeoutInSeconds = timeoutInSeconds ,
64+ MerchantAccountId = merchantAccountId ,
65+ TransactionRefundAllCreate = transactionRefundAllCreate ,
66+ } ;
67+ request . MerchantAccountId ??= SDKConfiguration . MerchantAccountId ;
68+
69+ string baseUrl = this . SDKConfiguration . GetTemplatedServerUrl ( ) ;
70+ var urlString = URLBuilder . Build ( baseUrl , "/transactions/{transaction_id}/refunds/all" , request ) ;
71+
72+ var httpRequest = new HttpRequestMessage ( HttpMethod . Post , urlString ) ;
73+ httpRequest . Headers . Add ( "user-agent" , _userAgent ) ;
74+ HeaderSerializer . PopulateHeaders ( ref httpRequest , request ) ;
75+
76+ var serializedBody = RequestBodySerializer . Serialize ( request , "TransactionRefundAllCreate" , "json" , true , true ) ;
77+ if ( serializedBody != null )
78+ {
79+ httpRequest . Content = serializedBody ;
80+ }
81+
82+ if ( _securitySource != null )
83+ {
84+ httpRequest = new SecurityMetadata ( _securitySource ) . Apply ( httpRequest ) ;
85+ }
86+
87+ var hookCtx = new HookContext ( baseUrl , "create_full_transaction_refund" , new List < string > { } , _securitySource ) ;
88+
89+ httpRequest = await this . SDKConfiguration . Hooks . BeforeRequestAsync ( new BeforeRequestContext ( hookCtx ) , httpRequest ) ;
90+
91+ HttpResponseMessage httpResponse ;
92+ try
93+ {
94+ httpResponse = await _client . SendAsync ( httpRequest ) ;
95+ int _statusCode = ( int ) httpResponse . StatusCode ;
96+
97+ if ( _statusCode == 400 || _statusCode == 401 || _statusCode == 403 || _statusCode == 404 || _statusCode == 405 || _statusCode == 409 || _statusCode == 422 || _statusCode == 425 || _statusCode == 429 || _statusCode >= 400 && _statusCode < 500 || _statusCode == 500 || _statusCode == 502 || _statusCode == 504 || _statusCode >= 500 && _statusCode < 600 )
98+ {
99+ var _httpResponse = await this . SDKConfiguration . Hooks . AfterErrorAsync ( new AfterErrorContext ( hookCtx ) , httpResponse , null ) ;
100+ if ( _httpResponse != null )
101+ {
102+ httpResponse = _httpResponse ;
103+ }
104+ }
105+ }
106+ catch ( Exception error )
107+ {
108+ var _httpResponse = await this . SDKConfiguration . Hooks . AfterErrorAsync ( new AfterErrorContext ( hookCtx ) , null , error ) ;
109+ if ( _httpResponse != null )
110+ {
111+ httpResponse = _httpResponse ;
112+ }
113+ else
114+ {
115+ throw ;
116+ }
117+ }
118+
119+ httpResponse = await this . SDKConfiguration . Hooks . AfterSuccessAsync ( new AfterSuccessContext ( hookCtx ) , httpResponse ) ;
120+
121+ var contentType = httpResponse . Content . Headers . ContentType ? . MediaType ;
122+ int responseStatusCode = ( int ) httpResponse . StatusCode ;
123+ if ( responseStatusCode == 201 )
124+ {
125+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
126+ {
127+ var obj = ResponseBodyDeserializer . Deserialize < CollectionNoCursorRefund > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
128+ return obj ! ;
129+ }
130+
131+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
132+ }
133+ else if ( responseStatusCode == 400 )
134+ {
135+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
136+ {
137+ var obj = ResponseBodyDeserializer . Deserialize < Error400 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
138+ throw obj ! ;
139+ }
140+
141+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
142+ }
143+ else if ( responseStatusCode == 401 )
144+ {
145+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
146+ {
147+ var obj = ResponseBodyDeserializer . Deserialize < Error401 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
148+ throw obj ! ;
149+ }
150+
151+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
152+ }
153+ else if ( responseStatusCode == 403 )
154+ {
155+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
156+ {
157+ var obj = ResponseBodyDeserializer . Deserialize < Response403CreateFullTransactionRefund > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
158+ switch ( obj ! . Type . ToString ( ) ) {
159+ case "Error403" :
160+ throw obj ! . Error403 ! ;
161+ case "Error403Forbidden" :
162+ throw obj ! . Error403Forbidden ! ;
163+ case "Error403Active" :
164+ throw obj ! . Error403Active ! ;
165+ default :
166+ throw new InvalidOperationException ( "Unknown error type." ) ;
167+ } ;
168+ }
169+
170+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
171+ }
172+ else if ( responseStatusCode == 404 )
173+ {
174+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
175+ {
176+ var obj = ResponseBodyDeserializer . Deserialize < Error404 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
177+ throw obj ! ;
178+ }
179+
180+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
181+ }
182+ else if ( responseStatusCode == 405 )
183+ {
184+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
185+ {
186+ var obj = ResponseBodyDeserializer . Deserialize < Error405 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
187+ throw obj ! ;
188+ }
189+
190+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
191+ }
192+ else if ( responseStatusCode == 409 )
193+ {
194+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
195+ {
196+ var obj = ResponseBodyDeserializer . Deserialize < Error409 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
197+ throw obj ! ;
198+ }
199+
200+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
201+ }
202+ else if ( responseStatusCode == 422 )
203+ {
204+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
205+ {
206+ var obj = ResponseBodyDeserializer . Deserialize < HTTPValidationError > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
207+ throw obj ! ;
208+ }
209+
210+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
211+ }
212+ else if ( responseStatusCode == 425 )
213+ {
214+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
215+ {
216+ var obj = ResponseBodyDeserializer . Deserialize < Error425 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
217+ throw obj ! ;
218+ }
219+
220+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
221+ }
222+ else if ( responseStatusCode == 429 )
223+ {
224+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
225+ {
226+ var obj = ResponseBodyDeserializer . Deserialize < Error429 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
227+ throw obj ! ;
228+ }
229+
230+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
231+ }
232+ else if ( responseStatusCode == 500 )
233+ {
234+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
235+ {
236+ var obj = ResponseBodyDeserializer . Deserialize < Error500 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
237+ throw obj ! ;
238+ }
239+
240+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
241+ }
242+ else if ( responseStatusCode == 502 )
243+ {
244+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
245+ {
246+ var obj = ResponseBodyDeserializer . Deserialize < Error502 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
247+ throw obj ! ;
248+ }
249+
250+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
251+ }
252+ else if ( responseStatusCode == 504 )
253+ {
254+ if ( Utilities . IsContentTypeMatch ( "application/json" , contentType ) )
255+ {
256+ var obj = ResponseBodyDeserializer . Deserialize < Error504 > ( await httpResponse . Content . ReadAsStringAsync ( ) , NullValueHandling . Ignore ) ;
257+ throw obj ! ;
258+ }
259+
260+ throw new Models . Errors . APIException ( "Unknown content type received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
261+ }
262+ else if ( responseStatusCode >= 400 && responseStatusCode < 500 )
263+ {
264+ throw new Models . Errors . APIException ( "API error occurred" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
265+ }
266+ else if ( responseStatusCode >= 500 && responseStatusCode < 600 )
267+ {
268+ throw new Models . Errors . APIException ( "API error occurred" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
269+ }
270+
271+ throw new Models . Errors . APIException ( "Unknown status code received" , responseStatusCode , await httpResponse . Content . ReadAsStringAsync ( ) , httpResponse ) ;
272+ }
273+ }
274+ }
0 commit comments