Article - https://support.travelpayouts.com/hc/en-us/articles/210996008 Flights search - https://support.travelpayouts.com/hc/en-us/articles/203956173-Flights-search-API-Real-time-and-multi-city-search
Created
May 18, 2022 06:56
-
-
Save IvanAdmaers/ec9f6c6a66d3a980337a45f13f8bf07c to your computer and use it in GitHub Desktop.
Create a TravelPayouts flight search signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import createTravelPayoutsSignature from './createTravelPayoutsSignature'; | |
describe('createTravelPayoutsSignature', () => { | |
it('should return a correct signature', () => { | |
const data = { | |
marker: '168869', | |
host: 'test.mysite.com', | |
user_ip: '68.237.210.150', | |
locale: 'en', | |
trip_class: 'Y', | |
passengers: { | |
adults: 1, | |
children: 0, | |
infants: 0, | |
}, | |
segments: [ | |
{ | |
origin: 'NYC', | |
destination: 'LAX', | |
date: '2022-05-17', | |
}, | |
], | |
}; | |
const token = 'SUPER_TOKEN'; | |
const output = '95cd7ea9f7264d09d099f5d39b02c34a'; | |
expect(createTravelPayoutsSignature(data, token)).toBe(output); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { sortObject, collectObjectValues, createMD5Signature } from '..'; | |
/* | |
sortObject - https://gist.github.com/IvanAdmaers/c42cfc26f55a110b416fa4e53ff7c414 | |
collectObjectValues - https://gist.github.com/IvanAdmaers/369a3800138579ebf7d7a1afcda69830 | |
createMD5Signature - https://gist.github.com/IvanAdmaers/f1d7fc0f98dff9e5d08cd2a5a7fbfaab | |
*/ | |
interface Segments { | |
origin: string; | |
destination: string; | |
date: string; | |
} | |
interface FlighSearchParameters { | |
marker: string; | |
host: string; | |
user_ip: string; | |
locale: string; | |
trip_class: string; | |
passengers: { | |
adults: number; | |
children: number; | |
infants: number; | |
}; | |
segments: Array<Segments>; | |
} | |
/** | |
* This function creates a travel payouts signature | |
*/ | |
const createTravelPayoutsSignature = ( | |
data: FlighSearchParameters, | |
token: string | |
): string => { | |
const sortedData = <FlighSearchParameters>sortObject(data); | |
const sortedDataValues = collectObjectValues(sortedData); | |
const stringOfDataValues: string = sortedDataValues.join(':'); | |
const signatureString: string = `${token}:${stringOfDataValues}`; | |
const MD5Signature: string = createMD5Signature(signatureString); | |
return MD5Signature; | |
}; | |
export default createTravelPayoutsSignature; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment