Skip to main content

PoliciesHelpers

Helpers for Mapping Supplier Policies Data

To accurately map supplier cancellation policies to our internal model, you can use one of the following helper methods depending on the supplier data format:

CancelPenaltyFromDateWithoutTimeZone

Use this method when the supplier provides a deadline date without time zone information.

public CancelPenalty CancelPenaltyFromDateWithoutTimeZone(
DateTime checkIn,
PenaltyType penaltyType,
Currency currency,
double value,
string deadLineWithoutTimeZone,
string dateFormat,
TimeZoneEnum timeZone
);

//Example of how should it be implemented:

// Sample data
DateTime checkIn = supplier.CheckIn; //If supplier does not return checkIn, it can also be obtained by the request
PenaltyType penaltyType = PenaltyType.Amount; // Example enum value
Currency currency = Currency.USD; // Example enum value
double value = supplier.Price; // "150.00", Price given by the supplier;
string deadLineWithoutTimeZone = supplier.DeadlineWithoutTimezone; //"2025-07-10", Supplier penalty deadline without timezone;
string dateFormat = "yyyy-MM-dd"; //Supplier date format
TimeZoneEnum timeZone = TimeZoneEnum.UTC14; // Example enum value, check the real value with supplier

// Method call
CancelPenalty result = _connectorsUtilities.CancelPenaltyManager.CancelPenaltyFromDateWithoutTimeZone(
checkIn,
penaltyType,
currency,
value,
deadLineWithoutTimeZone,
dateFormat,
timeZone
);
  • Assumes no time zone is present (e.g., no "Z" or UTC offset).
  • Requires manual timezone configuration. If the documentation does not specify it, use TimeZoneEnum.Unknown, which applies a -14h safety offset.

CancelPenaltyFromDateWithTimeZone

Use this method when the deadline value includes time zone information explicitly.

public CancelPenalty CancelPenaltyFromDateWithTimeZone(
DateTime checkIn,
PenaltyType penaltyType,
Currency currency,
double value,
string deadLineWithTimeZone,
string dateFormat
);

// Example of how should it be implemented:

// Sample data
DateTime checkIn = supplier.CheckIn; // If supplier does not return checkIn, it can also be obtained by the request
PenaltyType penaltyType = PenaltyType.Amount; // Example enum value
Currency currency = Currency.USD; // Example enum value
double value = supplier.Price; // "150.00", Price given by the supplier;
string deadLineWithTimeZone = supplier.DeadlineWithTimezone; //"2025-07-10T23:59:59+14:00" Supplier penalty deadline with timezone
string dateFormat = "yyyy-MM-ddTHH:mm:sszzz"; // Supplier date format with timezone

// Method call
CancelPenalty result = _connectorsUtilities.CancelPenaltyManager.CancelPenaltyFromDateWithTimeZone(
checkIn,
penaltyType,
currency,
value,
deadLineWithTimeZone,
dateFormat
);
  • Parses and respects the timezone embedded in the deadline string.
  • No additional time zone logic required.

CancelPenaltyFromHours

Use this method when the supplier defines penalties as a number of hours before check-in (not an absolute timestamp).

public CancelPenalty CancelPenaltyFromHours(
uint hoursBefore,
PenaltyType penaltyType,
Currency currency,
double value,
DateTime date,
TimeZoneEnum timeZone
);

// Example of how should it be implemented:

// Sample data
uint hoursBefore = supplier.HoursBefore; //"48", Supplier states penalty applies 48 hours before the specified date
PenaltyType penaltyType = PenaltyType.Amount; // Example enum value
Currency currency = Currency.USD; // Example enum value
double value = supplier.Price; // "150.00", Price given by the supplier;
DateTime date = supplier.CheckIn; // Penalty applies based on check-in date
TimeZoneEnum timeZone = TimeZoneEnum.UTC14; // Example enum value, check the real value with supplier

// Method call
CancelPenalty result = _connectorsUtilities.CancelPenaltyManager.CancelPenaltyFromHours(
hoursBefore,
penaltyType,
currency,
value,
date,
timeZone
);
  • Converts a relative hoursBefore value into an absolute UTC deadline.
  • Time zone must be provided manually or as part of an integration agreement.

CancelPoliciesCombiner

Handles the transformation and management of supplier cancellation policies, ensuring compatibility with the standardized Travelgate format.

Use Case: Essential for operations like Quote or Cancel to standardize cancellation policies provided by the supplier.

int numberOfRooms = supplier.NumberOfRooms; // 2 rooms
bool policiesWithGross = supplier.IsGrossPrice; // Check if policies are with gross
DateTime checkIn = supplier.CheckIn; //It can also be obtained by the request
int nights = supplier.Nights;

CancelPoliciesCombiner policiesCombiner = new CancelPoliciesCombiner(numberOfRooms, policiesWithGross, checkIn, nights);

foreach (Room supplierRoom in supplier.Rooms)
{
//Use policies and price helpers in order to build them
policiesCombiner.Add(new CancelPolicy(), new Price());
}

//TryGet method will return a valid OptionCancelPolicy
policiesCombiner.TryGet(out OptionCancelPolicy cancelPolicy);