0% found this document useful (0 votes)
7 views13 pages

IryoConnector HTTP Wrapper Code

.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

IryoConnector HTTP Wrapper Code

.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)

Enric Jimenez <ejimenez@[Link]>

(sin asunto)
Enric Jimenez <ejimenez@[Link]> 24 de octubre de 2024, 8:18
Borrador

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace [Link]
{
public class HttpWrapper
{
private static readonly HttpClient _client = new HttpClient
{
Timeout = [Link](5) // Configuro un timeout de 5 minutos
};

public async Task<JourneySearchRS> SearchAsync(JourneySearchRQ query)


{
try
{
ConfigureHeaders();
[Link] = [Link];
var strContent = [Link]();
var uri = [Link] + "/conecta/availability/search";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "Search", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "Search", "", strResponse);

if ([Link])
{
var resp = [Link]<JourneySearchRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{

[Link] 1/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
throw new Exception($"Error in SearchAsync: {[Link]}", ex);
}
}

public async Task<CreateBookingRS> CreateBookingAsync(CreateBookingRQ query)


{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var strContent = [Link]();


var uri = [Link] + "/conecta/build/bookings";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "CreateBooking", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "CreateBooking", "", strResponse);

if ([Link])
{
var resp = [Link]<CreateBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in CreateBookingAsync: {[Link]}", ex);
}
}

public async Task<SearchBookingsRS> SearchBookingsAsync(SearchBookingsRQ query)


{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var strContent = [Link]();


var uri = [Link] + "/conecta/manage/bookings/search";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "SearchBookings", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "SearchBookings", "", strResponse);

if ([Link])
{
var resp = [Link]<SearchBookingsRS>(strResponse);
return resp;

[Link] 2/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in SearchBookingsAsync: {[Link]}", ex);
}
}

public async Task<ConfirmBookingRS> ConfirmBookingAsync(string bookingNumber)


{
try
{
ConfigureHeaders();

var uri = [Link] + "/conecta/manage/bookings/" + bookingNumber + "/confirm";

var message = new HttpRequestMessage([Link], uri);

[Link]([Link], "ConfirmBooking", uri, "");

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "ConfirmBooking", "", strResponse);

if ([Link])
{
var resp = [Link]<ConfirmBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in ConfirmBookingAsync: {[Link]}", ex);
}
}

public async Task<UpdatePassengerRS> UpdatePassengerAsync(UpdatePassengersRQ query)


{
try
{
ConfigureHeaders();

var result = new UpdatePassengerRS();


foreach (var passenger in [Link])
{
var strContent = [Link]();
var uri = [Link] + "/conecta/manage/bookings/" + [Link] +
"/passengers/" + passenger.passenger_id;

var message = new HttpRequestMessage(new HttpMethod("PATCH"), uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "UpdatePassenger", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{

[Link] 3/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
var strResponse = await [Link]();
[Link]([Link], "UpdatePassenger", "", strResponse);

if ([Link])
{
var resp = [Link]<UpdatePassengerRS>(strResponse);
result = resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}

return result;
}
catch (Exception ex)
{
throw new Exception($"Error in UpdatePassengerAsync: {[Link]}", ex);
}
}

public async Task<ProcessPaymentRS> ProcessPaymentAsync(ProcessPaymentRQ query)


{
try
{
ConfigureHeaders();

var strContent = [Link]();


var uri = [Link] + "/conecta/gateway/payments/process";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "ProcessPayment", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "ProcessPayment", "", strResponse);

if ([Link])
{
var resp = [Link]<ProcessPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in ProcessPaymentAsync: {[Link]}", ex);
}
}

public async Task<RetrieveBookingRS> RetrieveBookingAsync(string bookingNumber)


{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var uri = [Link] + "/conecta/manage/bookings/" + bookingNumber;

[Link] 4/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)

var message = new HttpRequestMessage([Link], uri);

[Link]([Link], "RetrieveBooking", uri, "");

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "RetrieveBooking", "", strResponse);

if ([Link])
{
var resp = [Link]<RetrieveBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RetrieveBookingAsync: {[Link]}", ex);
}
}

public async Task<CancelBookingRS> CancelBookingAsync(string bookingNumber, bool twoStep)


{
try
{
ConfigureHeaders();

var cancelRQ = new CancelBookingRQ()


{
twoStepsAction = true
};

string strContent = twoStep ? [Link]() : "";

var uri = [Link] + "/conecta/manage/bookings/" + bookingNumber + "/cancel";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "CancelBooking", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "CancelBooking", "", strResponse);

if ([Link])
{
var resp = [Link]<CancelBookingRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in CancelBookingAsync: {[Link]}", ex);
}

[Link] 5/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}

public async Task<RefundMethodsRS> RefundMethodsAsync(string bookingNumber)


{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var uri = [Link] + "/conecta/gateway/payments/methods?bookingNumber=" +


bookingNumber;

var message = new HttpRequestMessage([Link], uri);

[Link]([Link], "RefundMethods", uri, "");

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "RefundMethods", "", strResponse);

if ([Link])
{
var methodsArray = [Link]<RefundMethod[]>(strResponse);
var resp = new RefundMethodsRS { RefundMethods = methodsArray };
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RefundMethodsAsync: {[Link]}", ex);
}
}

public async Task RefundPSPAsync(string bookingNumber)


{
try
{
ConfigureHeaders();

var refundRQ = new RefundPspRQ() { bookingNumber = bookingNumber };

var strContent = [Link]();


var uri = [Link] + "/conecta/gateway/refunds/psp";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "Refund", uri, "");

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if (![Link])
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RefundPSPAsync: {[Link]}", ex);

[Link] 6/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
}
}
public async Task<List<Products>> GetProductsAsync()
{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var uri = [Link] + "/conecta/support/products";

var message = new HttpRequestMessage([Link], uri);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if ([Link])
{
var strResponse = await [Link]();
var resp = [Link]<IryoProductRS>(strResponse);
return [Link]();
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in GetProductsAsync: {[Link]}", ex);
}
}

public async Task<List<T>> GetGenericAsync<T>(string uri)


{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var message = new HttpRequestMessage([Link], [Link] + uri);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if ([Link])
{
var strResponse = await [Link]();
var resp = [Link]<IryoGenericTypesRs<T>>(strResponse);
return [Link]();
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in GetGenericAsync: {[Link]}", ex);
}
}

public async Task<List<RouteInfo>> GetRoutesAsync()


{
try
{

[Link] 7/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
// Configurar los encabezados de la solicitud, agregando lo necesario para autenticación
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var uri = [Link] + "/conecta/support/routes";

// Crear una solicitud GET


var message = new HttpRequestMessage([Link], uri);

// Enviar la solicitud y obtener la respuesta


using (HttpResponseMessage response = await _client.SendAsync(message))
{
// Verificar si la respuesta es exitosa
if ([Link])
{
// Leer la respuesta como cadena
var strResponse = await [Link]();

// Deserializar la respuesta en un objeto de tipo RoutesRS


var resp = [Link]<RoutesRS>(strResponse);

// Retornar la lista de rutas


return [Link]();
}
else
{
// Lanzar una excepción si la respuesta no es exitosa
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
// Manejar cualquier excepción que ocurra durante la ejecución del método
throw new Exception($"Error in GetRoutesAsync: {[Link]}", ex);
}
}
public async Task<SalesChannelRS> SalesChannelAsync()
{
try
{
ConfigureHeaders();
_client.[Link]("Accept-Language", "es-ES");

var uri = [Link] + "/conecta/config/sales-channel";

var message = new HttpRequestMessage([Link], uri);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
if ([Link])
{
var resp = [Link]<SalesChannelRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in SalesChannelAsync: {[Link]}", ex);
}
}

[Link] 8/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)

public async Task<AuthenticationTokenRS> GetAuthenticationTokenAsync(string apiKey, string userName)


{
try
{
ConfigureHeaders();

var nvc = new List<KeyValuePair<string, string>>()


{
new KeyValuePair<string, string>("client_id", "api"),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("api_key", apiKey),
new KeyValuePair<string, string>("scope", "openid"),
new KeyValuePair<string, string>("username", userName)
};

var message = new HttpRequestMessage([Link], [Link] +


"/auth/realms/ilsa/protocol/openid-connect/token")
{
Content = new FormUrlEncodedContent(nvc)
};

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if ([Link])
{
var strResponse = await [Link]();
var resp = [Link]<AuthenticationTokenRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in GetAuthenticationTokenAsync: {[Link]}", ex);
}
}

public async Task<AuthorisationTokenRS> GetAuthorisationTokenAsync(string authenToken)


{
try
{
ConfigureHeaders();

var nvc = new List<KeyValuePair<string, string>>()


{
new KeyValuePair<string, string>("audience", "internal-api"),
new KeyValuePair<string, string>("grant_type", "urn:ietf:params:oauth:grant-type:uma-ticket")
};

_client.[Link] = new AuthenticationHeaderValue("Bearer", authenToken);

var message = new HttpRequestMessage([Link], [Link] +


"/auth/realms/ilsa/protocol/openid-connect/token")
{
Content = new FormUrlEncodedContent(nvc)
};

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if ([Link])
{
var strResponse = await [Link]();
var resp = [Link]<AuthorisationTokenRS>(strResponse);

[Link] 9/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in GetAuthorisationTokenAsync: {[Link]}", ex);
}
}

public async Task<RefreshAuthorisationTokenRS> RefreshAuthorisationTokenAsync(string authenToken, string


refreshToken)
{
try
{
ConfigureHeaders();

var nvc = new List<KeyValuePair<string, string>>()


{
new KeyValuePair<string, string>("client_id", "api"),
new KeyValuePair<string, string>("grant_type", "refresh_token"),
new KeyValuePair<string, string>("refresh_token", refreshToken)
};

_client.[Link] = new AuthenticationHeaderValue("Bearer", authenToken);

var message = new HttpRequestMessage([Link], [Link] +


"/auth/realms/ilsa/protocol/openid-connect/token")
{
Content = new FormUrlEncodedContent(nvc)
};

using (HttpResponseMessage response = await _client.SendAsync(message))


{
if ([Link])
{
var strResponse = await [Link]();
var resp = [Link]<RefreshAuthorisationTokenRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {await
[Link]()}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in RefreshAuthorisationTokenAsync: {[Link]}", ex);
}
}

public async Task<VoucherPaymentRS> VoucherPaymentAsync(VoucherPaymentRQ query)


{
try
{
ConfigureHeaders();

var strContent = [Link]();


var uri = [Link] + "/conecta/gateway/payments/voucher";

var message = new HttpRequestMessage([Link], uri)


{

[Link] 10/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "VoucherPayment", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "VoucherPayment", "", strResponse);

if ([Link])
{
var resp = [Link]<VoucherPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in VoucherPaymentAsync: {[Link]}", ex);
}
}

public async Task<Card3DsPaymentRS> Card3DsPaymentAsync(Card3DsPaymentRQ query)


{
try
{
ConfigureHeaders();

var strContent = [Link]();


var uri = [Link] + "/conecta/gateway/payments/3ds/api";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "Card3DsPayment", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "Card3DsPayment", "", strResponse);

if ([Link])
{
var resp = [Link]<Card3DsPaymentRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in Card3DsPaymentAsync: {[Link]}", ex);
}
}

public async Task<PaymentMethodsRS> PaymentMethodsAsync(string bookingNumber)


{
try
{

[Link] 11/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
ConfigureHeaders();

var uri = [Link] + "/conecta/gateway/payments/methods?bookingNumber=" +


bookingNumber;

var message = new HttpRequestMessage([Link], uri);

[Link]([Link], "PaymentMethods", uri, "");

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "PaymentMethods", "", strResponse);

if ([Link])
{
var methodsArray = [Link]<PaymenMethod[]>(strResponse);
var resp = new PaymentMethodsRS
{
Methods = methodsArray
};

return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)
{
throw new Exception($"Error in PaymentMethodsAsync: {[Link]}", ex);
}
}

public async Task<PaymentAccountRS> PaymentAccountAsync(PaymentAccountRQ query)


{
try
{
ConfigureHeaders();

var strContent = [Link]();


var uri = [Link] + "/conecta/gateway/payments/account";

var message = new HttpRequestMessage([Link], uri)


{
Content = new StringContent(strContent, Encoding.UTF8, "application/json"),
};

[Link]([Link], "PaymentAccount", uri, strContent);

using (HttpResponseMessage response = await _client.SendAsync(message))


{
var strResponse = await [Link]();
[Link]([Link], "PaymentAccount", "", strResponse);

if ([Link])
{
var resp = [Link]<PaymentAccountRS>(strResponse);
return resp;
}
else
{
throw new Exception($"Error HTTP - Code: {[Link]}, Message: {strResponse}");
}
}
}
catch (Exception ex)

[Link] 12/13
24/10/24, 8:18 Correo de EMOVEERE CONSULTING - (sin asunto)
{
throw new Exception($"Error in PaymentAccountAsync: {[Link]}", ex);
}
}

private void ConfigureHeaders()


{
_client.[Link]();
_client.[Link](new MediaTypeWithQualityHeaderValue("application/json"));
_client.[Link]("Content-Type", "application/json");
_client.[Link]("Ocp-Apim-Subscription-Key", IryoCredentials.
SubscriptionKey);
_client.[Link] = new AuthenticationHeaderValue("Bearer", IryoCredentials.
AuthorisationToken.access_token);
}
}
}

[Link] 13/13

You might also like