Skip to content

Commit fe60ade

Browse files
committed
Added ticket inform operation
1 parent 899e98a commit fe60ade

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/Sportradar.Mbs.Sdk/Internal/Connection/TokenProvider.cs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http.Headers;
2+
using System.Text;
23
using System.Text.Json;
34
using System.Text.Json.Serialization;
45
using Sportradar.Mbs.Sdk.Exceptions;
@@ -127,7 +128,7 @@ internal async Task<string> GetAuthTokenAsync(CancellationToken cancellationToke
127128

128129
var response = JsonSerializer.Deserialize<AuthResponse>(content);
129130
if (response == null || string.IsNullOrEmpty(response.AccessToken))
130-
return null;
131+
return ProcessPossibleError(response);
131132

132133
var token = response.AccessToken.NotNull();
133134
if (response.ExpiresIn is > 1)
@@ -139,6 +140,27 @@ internal async Task<string> GetAuthTokenAsync(CancellationToken cancellationToke
139140
return token;
140141
}
141142

143+
private string? ProcessPossibleError(AuthResponse? authResponse)
144+
{
145+
if (authResponse == null) return null;
146+
147+
if (string.IsNullOrEmpty(authResponse.Error) && string.IsNullOrEmpty(authResponse.ErrorDescription))
148+
return null;
149+
150+
var msg = new StringBuilder();
151+
msg.Append("Auth error");
152+
if (!string.IsNullOrEmpty(authResponse.Error))
153+
{
154+
msg.Append(": ").Append(authResponse.Error.NotNull());
155+
}
156+
if (!string.IsNullOrEmpty(authResponse.ErrorDescription))
157+
{
158+
msg.Append(": ").Append(authResponse.ErrorDescription.NotNull());
159+
}
160+
161+
throw new AuthTokenFailureException(msg.ToString());
162+
}
163+
142164
public class AuthResponse
143165
{
144166
[JsonPropertyName("access_token")]
@@ -151,5 +173,9 @@ public class AuthResponse
151173
public string? RefreshToken { get; set; }
152174
[JsonPropertyName("scope")]
153175
public string? Scope { get; set; }
176+
[JsonPropertyName("error")]
177+
public string? Error { get; set; }
178+
[JsonPropertyName("error_description")]
179+
public string? ErrorDescription { get; set; }
154180
}
155181
}

src/Sportradar.Mbs.Sdk/Internal/Protocol/ProtocolProvider.ITicketProtocol.cs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public async Task<TicketResponse> SendTicketAsync(TicketRequest request)
1313
return await ProcessRequestAsync<TicketResponse>("ticket-placement", request).ConfigureAwait(false);
1414
}
1515

16+
public async Task<TicketInformResponse> SendTicketInformAsync(TicketInformRequest request)
17+
{
18+
return await ProcessRequestAsync<TicketInformResponse>("ticket-placement-inform", request).ConfigureAwait(false);
19+
}
20+
1621
public async Task<TicketAckResponse> SendTicketAckAsync(TicketAckRequest request)
1722
{
1823
return await ProcessRequestAsync<TicketAckResponse>("ticket-placement-ack", request).ConfigureAwait(false);

src/Sportradar.Mbs.Sdk/Internal/Utils/DecimalJsonConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class DecimalJsonConverter : JsonConverter<decimal>
99
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1010
{
1111
var jsonVal = reader.GetString();
12-
if (decimal.TryParse(jsonVal, out var result)) return result;
12+
if (decimal.TryParse(jsonVal, NumberStyles.Number, CultureInfo.InvariantCulture, out var result)) return result;
1313

1414
throw new JsonException("Unknown decimal: " + jsonVal);
1515
}

src/Sportradar.Mbs.Sdk/Protocol/ITicketProtocol.cs

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public interface ITicketProtocol
1616
/// <exception cref="SdkException">Thrown when operation has failed.</exception>
1717
Task<TicketResponse> SendTicketAsync(TicketRequest request);
1818

19+
/// <summary>
20+
/// Sends a ticket inform request asynchronously.
21+
/// </summary>
22+
/// <param name="request">The ticket inform request to send.</param>
23+
/// <returns>A task that represents the asynchronous operation. The task result contains the ticket inform response.</returns>
24+
/// <exception cref="SdkException">Thrown when operation has failed.</exception>
25+
Task<TicketInformResponse> SendTicketInformAsync(TicketInformRequest request);
26+
1927
/// <summary>
2028
/// Sends a ticket acknowledgement request asynchronously.
2129
/// </summary>

0 commit comments

Comments
 (0)