44using System . Text ;
55using System . Text . Json ;
66using System . Web ;
7- using Mimo . AppStoreServerLibrary . Exceptions ;
8- using Mimo . AppStoreServerLibrary . Models ;
97using Microsoft . IdentityModel . JsonWebTokens ;
108using Microsoft . IdentityModel . Tokens ;
9+ using Mimo . AppStoreServerLibrary . Exceptions ;
10+ using Mimo . AppStoreServerLibrary . Models ;
1111
1212namespace Mimo . AppStoreServerLibrary ;
1313
@@ -26,7 +26,8 @@ public class AppStoreServerApiClient(
2626 string issuerId ,
2727 string bundleId ,
2828 AppStoreEnvironment environment ,
29- HttpClient ? httpClient = null )
29+ HttpClient ? httpClient = null
30+ )
3031{
3132 private readonly HttpClient httpClient = httpClient ?? new HttpClient ( ) ;
3233
@@ -50,7 +51,8 @@ public Task<SubscriptionStatusResponse> GetAllSubscriptionStatuses(string transa
5051 /// <returns>A list of notifications and their attempts</returns>
5152 public Task < NotificationHistoryResponse ? > GetNotificationHistory (
5253 NotificationHistoryRequest notificationHistoryRequest ,
53- string paginationToken = "" )
54+ string paginationToken = ""
55+ )
5456 {
5557 //Call to https://developer.apple.com/documentation/appstoreserverapi/get_notification_history
5658 Dictionary < string , string > queryParameters = new ( ) ;
@@ -61,17 +63,19 @@ public Task<SubscriptionStatusResponse> GetAllSubscriptionStatuses(string transa
6163
6264 string path = $ "v1/notifications/history";
6365
64- return this . MakeRequest < NotificationHistoryResponse > ( path , HttpMethod . Post , queryParameters ,
65- notificationHistoryRequest ) ;
66+ return this . MakeRequest < NotificationHistoryResponse > (
67+ path ,
68+ HttpMethod . Post ,
69+ queryParameters ,
70+ notificationHistoryRequest
71+ ) ;
6672 }
6773
6874 /// <summary>
6975 /// Get a customer’s in-app purchase transaction history for your app.
7076 /// </summary>
7177 /// <returns>A list of transactions associated with the provided Transaction Id</returns>
72- public Task < TransactionHistoryResponse ? > GetTransactionHistory (
73- string transactionId ,
74- string revisionToken = "" )
78+ public Task < TransactionHistoryResponse ? > GetTransactionHistory ( string transactionId , string revisionToken = "" )
7579 {
7680 //Call to https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history
7781 Dictionary < string , string > queryParameters = new ( ) ;
@@ -114,15 +118,12 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
114118 {
115119 { "iss" , issuerId } ,
116120 { "aud" , "appstoreconnect-v1" } ,
117- { "bid" , bundleId }
121+ { "bid" , bundleId } ,
118122 } ,
119- TokenType = "JWT"
123+ TokenType = "JWT" ,
120124 } ;
121125
122- var securityKey = new ECDsaSecurityKey ( prvKey )
123- {
124- KeyId = keyId
125- } ;
126+ var securityKey = new ECDsaSecurityKey ( prvKey ) { KeyId = keyId } ;
126127
127128 securityDescriptor . SigningCredentials = new SigningCredentials ( securityKey , "ES256" ) ;
128129
@@ -134,7 +135,9 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
134135 HttpMethod method ,
135136 Dictionary < string , string > ? queryParameters = null ,
136137 object ? body = null ,
137- bool fetchResponse = true ) where TReturn : class
138+ bool fetchResponse = true
139+ )
140+ where TReturn : class
138141 {
139142 string token = CreateBearerToken ( keyId , issuerId , signingKey , bundleId ) ;
140143
@@ -153,10 +156,7 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
153156 builder . Query = query . ToString ( ) ;
154157 }
155158
156- var jsonOptions = new JsonSerializerOptions
157- {
158- PropertyNamingPolicy = JsonNamingPolicy . CamelCase
159- } ;
159+ var jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
160160
161161 try
162162 {
@@ -168,23 +168,28 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
168168 request . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
169169 httpResponse = await this . httpClient . SendAsync ( request ) ;
170170 }
171-
172171 else if ( method == HttpMethod . Post )
173172 {
174173 var request = new HttpRequestMessage ( HttpMethod . Post , builder . Uri ) ;
175174 request . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
176- request . Content = new StringContent ( JsonSerializer . Serialize ( body , jsonOptions ) , Encoding . UTF8 , "application/json" ) ;
175+ request . Content = new StringContent (
176+ JsonSerializer . Serialize ( body , jsonOptions ) ,
177+ Encoding . UTF8 ,
178+ "application/json"
179+ ) ;
177180 httpResponse = await this . httpClient . SendAsync ( request ) ;
178181 }
179-
180182 else if ( method == HttpMethod . Put )
181183 {
182184 var request = new HttpRequestMessage ( HttpMethod . Put , builder . Uri ) ;
183185 request . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
184- request . Content = new StringContent ( JsonSerializer . Serialize ( body , jsonOptions ) , Encoding . UTF8 , "application/json" ) ;
186+ request . Content = new StringContent (
187+ JsonSerializer . Serialize ( body , jsonOptions ) ,
188+ Encoding . UTF8 ,
189+ "application/json"
190+ ) ;
185191 httpResponse = await this . httpClient . SendAsync ( request ) ;
186192 }
187-
188193 else
189194 {
190195 throw new NotSupportedException ( $ "Method { method } not supported") ;
@@ -200,12 +205,10 @@ private static string CreateBearerToken(string keyId, string issuerId, string si
200205 var error = JsonSerializer . Deserialize < ErrorResponse > ( responseContent , jsonOptions ) ;
201206
202207 throw new ApiException ( httpResponse . StatusCode , error ) ;
203-
204208 }
205-
206209 catch ( HttpRequestException ex )
207210 {
208211 throw new ApiException ( ex . StatusCode , null , ex ) ;
209212 }
210213 }
211- }
214+ }
0 commit comments