1+ using Checkout . Authentication . Standalone . GETSessionsId . Responses . GetSessionDetailsResponseOk ;
2+ using Checkout . Authentication . Standalone . POSTSessions . Requests . RequestASessionRequest ;
3+ using Checkout . Authentication . Standalone . POSTSessions . Responses ;
4+ using Checkout . Authentication . Standalone . POSTSessions . Responses . RequestASessionResponseAccepted ;
5+ using Checkout . Authentication . Standalone . POSTSessions . Responses . RequestASessionResponseCreated ;
6+ using Checkout . Authentication . Standalone . POSTSessionsIdComplete . Responses . CompleteASessionResponseNoContent ;
7+ using Checkout . Authentication . Standalone . PUTSessionsIdCollectData . Requests ;
8+ using Checkout . Authentication . Standalone . PUTSessionsIdCollectData . Responses . UpdateASessionResponseOk ;
9+ using Checkout . Authentication . Standalone . PUTSessionsIdIssuerFingerprint . Requests .
10+ UpdateSessionThreeDSMethodCompletionIndicatorRequest ;
11+ using Checkout . Authentication . Standalone . PUTSessionsIdIssuerFingerprint . Responses .
12+ UpdateSessionThreedsMethodCompletionIndicatorResponseOk ;
13+ using System ;
14+ using System . Collections . Generic ;
15+ using System . Threading ;
16+ using System . Threading . Tasks ;
17+
18+ namespace Checkout . Authentication
19+ {
20+ public class AuthenticationClient : AbstractClient , IAuthenticationClient
21+ {
22+ private const string SessionsPath = "sessions" ;
23+ private const string CollectDataPath = "collect-data" ;
24+ private const string CompletePath = "complete" ;
25+ private const string IssuerFingerprintPath = "issuer-fingerprint" ;
26+ private const string SessionIdPath = "sessionId" ;
27+
28+ private static readonly IDictionary < int , Type > RequestASessionResponseMappings = new Dictionary < int , Type > ( ) ;
29+
30+ static AuthenticationClient ( )
31+ {
32+ RequestASessionResponseMappings [ 201 ] = typeof ( RequestASessionResponseCreated ) ;
33+ RequestASessionResponseMappings [ 202 ] = typeof ( RequestASessionResponseAccepted ) ;
34+ }
35+
36+ public AuthenticationClient ( IApiClient apiClient , CheckoutConfiguration configuration )
37+ : base ( apiClient , configuration , SdkAuthorizationType . OAuth )
38+ {
39+ }
40+
41+ public async Task < RequestASessionResponse > RequestASession ( RequestASessionRequest requestASessionRequest ,
42+ CancellationToken cancellationToken = default )
43+ {
44+ CheckoutUtils . ValidateParams ( "requestASessionRequest" , requestASessionRequest ) ;
45+ var resource = await ApiClient . Post < HttpMetadata > ( SessionsPath , SdkAuthorization ( ) ,
46+ RequestASessionResponseMappings ,
47+ requestASessionRequest , cancellationToken ) ;
48+
49+ switch ( resource )
50+ {
51+ case RequestASessionResponseCreated requestASessionResponseCreated :
52+ return new RequestASessionResponse ( requestASessionResponseCreated ) ;
53+
54+ case RequestASessionResponseAccepted requestASessionResponseAccepted :
55+ return new RequestASessionResponse ( requestASessionResponseAccepted ) ;
56+
57+ default :
58+ throw new InvalidOperationException ( "Unexpected mapping type " + resource . GetType ( ) ) ;
59+ }
60+ }
61+
62+ public async Task < GetSessionDetailsResponseOk > GetSessionDetails ( string sessionId ,
63+ CancellationToken cancellationToken = default )
64+ {
65+ CheckoutUtils . ValidateParams ( "sessionId" , sessionId ) ;
66+ return await GetSessionDetails ( sessionId , SdkAuthorization ( ) , cancellationToken ) ;
67+ }
68+
69+ public async Task < GetSessionDetailsResponseOk > GetSessionDetails ( string sessionSecret , string sessionId ,
70+ CancellationToken cancellationToken = default )
71+ {
72+ CheckoutUtils . ValidateParams ( "sessionSecret" , sessionSecret , "sessionId" , sessionId ) ;
73+ return await GetSessionDetails ( sessionId , SessionSecretAuthorization ( sessionSecret ) , cancellationToken ) ;
74+ }
75+
76+ public async Task < UpdateASessionResponseOk > UpdateASession ( string sessionId ,
77+ AbstractUpdateASessionRequest updateASessionRequest ,
78+ CancellationToken cancellationToken = default )
79+ {
80+ CheckoutUtils . ValidateParams ( "sessionId" , sessionId , "updateASessionRequest" , updateASessionRequest ) ;
81+ return await UpdateASession ( sessionId , updateASessionRequest , SdkAuthorization ( ) , cancellationToken ) ;
82+ }
83+
84+ public async Task < UpdateASessionResponseOk > UpdateASession ( string sessionSecret , string sessionId ,
85+ AbstractUpdateASessionRequest updateASessionRequest , CancellationToken cancellationToken = default )
86+ {
87+ CheckoutUtils . ValidateParams ( "sessionSecret" , sessionSecret , "sessionId" , sessionId ,
88+ "updateASessionRequest" ,
89+ updateASessionRequest ) ;
90+ return await UpdateASession ( sessionId , updateASessionRequest , SessionSecretAuthorization ( sessionSecret ) ,
91+ cancellationToken ) ;
92+ }
93+
94+ public async Task < CompleteASessionResponseNoContent > CompleteASession ( string sessionId ,
95+ CancellationToken cancellationToken = default )
96+ {
97+ CheckoutUtils . ValidateParams ( "sessionId" , sessionId ) ;
98+ return await CompleteASession ( sessionId , SdkAuthorization ( ) , cancellationToken ) ;
99+ }
100+
101+ public async Task < CompleteASessionResponseNoContent > CompleteASession ( string sessionSecret , string sessionId ,
102+ CancellationToken cancellationToken = default )
103+ {
104+ CheckoutUtils . ValidateParams ( "sessionSecret" , sessionSecret , "sessionId" , sessionId ) ;
105+ return await CompleteASession ( sessionId , SessionSecretAuthorization ( sessionSecret ) , cancellationToken ) ;
106+ }
107+
108+ public Task < UpdateSessionThreedsMethodCompletionIndicatorResponseOk >
109+ UpdateSessionThreedsMethodCompletionIndicator ( string sessionId ,
110+ UpdateSessionThreedsMethodCompletionIndicatorRequest
111+ updateSessionThreedsMethodCompletionIndicatorRequest ,
112+ CancellationToken cancellationToken = default )
113+ {
114+ CheckoutUtils . ValidateParams ( "sessionId" , sessionId , "updateSessionThreedsMethodCompletionIndicatorRequest" ,
115+ updateSessionThreedsMethodCompletionIndicatorRequest ) ;
116+ return UpdateSessionThreedsMethodCompletionIndicator ( sessionId ,
117+ updateSessionThreedsMethodCompletionIndicatorRequest , SdkAuthorization ( ) ,
118+ cancellationToken ) ;
119+ }
120+
121+ public Task < UpdateSessionThreedsMethodCompletionIndicatorResponseOk >
122+ UpdateSessionThreedsMethodCompletionIndicator ( string sessionSecret ,
123+ string sessionId ,
124+ UpdateSessionThreedsMethodCompletionIndicatorRequest
125+ updateSessionThreedsMethodCompletionIndicatorRequest ,
126+ CancellationToken cancellationToken = default )
127+ {
128+ CheckoutUtils . ValidateParams ( "sessionSecret" , sessionSecret , "sessionId" ,
129+ sessionId , "updateSessionThreedsMethodCompletionIndicatorRequest" ,
130+ updateSessionThreedsMethodCompletionIndicatorRequest ) ;
131+ return UpdateSessionThreedsMethodCompletionIndicator ( sessionId ,
132+ updateSessionThreedsMethodCompletionIndicatorRequest ,
133+ SessionSecretAuthorization ( sessionSecret ) , cancellationToken ) ;
134+ }
135+
136+ private async Task < GetSessionDetailsResponseOk > GetSessionDetails ( string sessionId , SdkAuthorization sdkAuthorization ,
137+ CancellationToken cancellationToken = default )
138+ {
139+ CheckoutUtils . ValidateParams ( SessionIdPath , sessionId , "sdkAuthorization" , sdkAuthorization ) ;
140+ return await ApiClient . Get < GetSessionDetailsResponseOk > ( BuildPath ( SessionsPath , sessionId ) , sdkAuthorization ,
141+ cancellationToken ) ;
142+ }
143+
144+ private async Task < UpdateASessionResponseOk > UpdateASession ( string sessionId , AbstractUpdateASessionRequest updateASessionRequest ,
145+ SdkAuthorization sdkAuthorization ,
146+ CancellationToken cancellationToken = default )
147+ {
148+ return await ApiClient . Put < UpdateASessionResponseOk > ( BuildPath ( SessionsPath , sessionId , CollectDataPath ) ,
149+ sdkAuthorization , updateASessionRequest , cancellationToken ) ;
150+ }
151+
152+ private async Task < CompleteASessionResponseNoContent > CompleteASession ( string sessionId , SdkAuthorization sdkAuthorization ,
153+ CancellationToken cancellationToken = default )
154+ {
155+ return await ApiClient . Post < CompleteASessionResponseNoContent > ( BuildPath ( SessionsPath , sessionId , CompletePath ) ,
156+ sdkAuthorization , null ,
157+ cancellationToken , null ) ;
158+ }
159+
160+ private async Task < UpdateSessionThreedsMethodCompletionIndicatorResponseOk > UpdateSessionThreedsMethodCompletionIndicator (
161+ string sessionId , UpdateSessionThreedsMethodCompletionIndicatorRequest updateSessionThreedsMethodCompletionIndicatorRequest ,
162+ SdkAuthorization sdkAuthorization , CancellationToken cancellationToken = default )
163+ {
164+ return await ApiClient . Put < UpdateSessionThreedsMethodCompletionIndicatorResponseOk > (
165+ BuildPath ( SessionsPath , sessionId , IssuerFingerprintPath ) , sdkAuthorization ,
166+ updateSessionThreedsMethodCompletionIndicatorRequest , cancellationToken ) ;
167+ }
168+
169+ private static SdkAuthorization SessionSecretAuthorization ( string sessionSecret )
170+ {
171+ return new SessionSecretSdkCredentials ( sessionSecret ) . GetSdkAuthorization ( SdkAuthorizationType . Custom ) ;
172+ }
173+ }
174+ }
0 commit comments