Skip to content

Commit

Permalink
Merge pull request #20 from Travelport-Ukraine/auto-cancel-failed-seg…
Browse files Browse the repository at this point in the history
…ments

Auto cancel failed segments
  • Loading branch information
shmuga authored Sep 30, 2016
2 parents b2e1801 + 27f198b commit 7de1489
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uapi-json",
"version": "0.2.7",
"version": "0.3.1",
"description": "Travelport Universal API",
"main": "build/",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions src/Air/AirParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const countHistogram = (arr) => {
throw new Error('argument should be an array');
}

if (_.isObject(arr[0])) {
arr = arr.map(elem => elem.Code);
}

arr.sort();
for (let i = 0; i < arr.length; i++) {
if (arr[i] !== prev) {
Expand Down Expand Up @@ -544,5 +548,6 @@ module.exports = {
AIR_PRICE_FARE_RULES: AirPriceFareRules,
FARE_RULES_RESPONSE: FareRules,
GDS_QUEUE_PLACE_RESPONSE: gdsQueue,
AIR_CANCEL_UR: nullParsing,
AIR_ERRORS: AirErrorHandler, // errors handling
};
17 changes: 16 additions & 1 deletion src/Air/AirService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ module.exports = (settings) => {
ticketDate: moment().add(1, 'day').format(),
ActionStatusType: 'TAW',
}, data);
return AirService.createReservation(bookingParams);
return AirService.createReservation(bookingParams).catch(err => {
if (err.errno === 1501) {
const code = err.details['universal:UniversalRecord'].LocatorCode;
return AirService.cancelUR({
LocatorCode: code,
}).then(() => {
throw err;
}).catch(() => {
if (debug > 0) {
console.log('Cant cancel booking with UR', code);
}
throw err;
});
}
throw err;
});
});
},

Expand Down
13 changes: 12 additions & 1 deletion src/Air/AirServiceInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,22 @@ module.exports = function (auth, debug, production) {
config(auth.region, production).GdsQueueService.url,
auth,
requests.GdsQueueService.GDS_QUEUE_PLACE,
null, // TODO rewrite into uAPI parser
'gdsQueue:GdsQueuePlaceRsp', // TODO rewrite into uAPI parser
AirValidator.GDS_QUEUE_PLACE,
AirParser.AIR_ERRORS,
AirParser.GDS_QUEUE_PLACE_RESPONSE,
debug
),

cancelUR: uApiRequest(
config(auth.region, production).UniversalRecord.url,
auth,
requests.AirService.AIR_CANCEL_UR,
null, // TODO rewrite into uAPI parser
AirValidator.AIR_CANCEL_UR,
AirParser.AIR_ERRORS,
AirParser.AIR_CANCEL_UR,
debug
),
};
};
5 changes: 5 additions & 0 deletions src/Air/AirValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,9 @@ module.exports = {
.pcc()
.end();
},

AIR_CANCEL_UR(params) {
return new Validator(params)
.end();
},
};
1 change: 1 addition & 0 deletions src/Hotels/HotelsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (settings) {
config(auth.region, production).UniversalRecord.url,
auth,
requests.HotelsService.HOTELS_CANCEL_BOOK_REQUEST,
null,
HotelsValidator.HOTELS_CANCEL_BOOK_REQUEST,
HotelsErrors,
HotelsParser.HOTELS_CANCEL_BOOK_REQUEST,
Expand Down
8 changes: 8 additions & 0 deletions src/XMLtemplates/AirCancelUR.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://www.travelport.com/schema/common_v36_0" xmlns:univ="http://www.travelport.com/schema/universal_v36_0">
<soapenv:Header/>
<soapenv:Body>
<univ:UniversalRecordCancelReq TargetBranch="{{TargetBranch}}" UniversalRecordLocatorCode="{{LocatorCode}}" Version="0">
<com:BillingPointOfSaleInfo OriginApplication="UAPI"/>
</univ:UniversalRecordCancelReq>
</soapenv:Body>
</soapenv:Envelope>
2 changes: 1 addition & 1 deletion src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const allErrors = {
msg: 'No universal:UniversalRecordImportRsp object in parsed XML for #Air.import()',
},
GDS_PLACE_QUEUE_ERROR: { errno: 1500, msg: 'Error during place queue request' },
AIR_SEGMENT_FAILURE: { errno: 1501, msg: 'Booking of some segments failure' },
AIR_SEGMENT_FAILURE: { errno: 1501, msg: 'Booking of some segments failure. PNR cancelled.' },
};


Expand Down
2 changes: 1 addition & 1 deletion src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
AIR_CREATE_RESERVATION_REQUEST: xmlDir + '/104-03_1G_AirBook_Rq_pricingSolutionXML.xml',
AIR_CREATE_RESERVATION_REQUEST_MANUAL: xmlDir + '/104-03_1G_AirBook_Rq.xml',
AIR_TICKET_REQUEST: xmlDir + '/104-04_1G_AirTicket_Rq.xml',

AIR_CANCEL_UR: xmlDir + '/AirCancelUR.xml',
AIR_PRICING_FARE_RULES: xmlDir + '/AirPricing_FareRules.manual_segments.xml',
FARE_RULES_REQUEST: xmlDir + '/FareRules_uAPI.xml',

Expand Down
12 changes: 12 additions & 0 deletions test/Air/AirParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,16 @@ describe('#AirParser', function () {
}).catch(err => assert(false, 'Error during parsing' + err.stack));
});
});

describe('AIR_CANCEL_UR', () => {
it('parse cancel by UR', () => {
const uParser = new ParserUapi(null, 'v36_0', { });
const parseFunction = require('../../src/Air/AirParser').AIR_CANCEL_UR;
const xml = fs.readFileSync(`${xmlFolder}/AirCancelUR.xml`).toString();
return uParser.parse(xml).then(json => {
const jsonResult = parseFunction.call(uParser, json)
assert(jsonResult);
}).catch(err => assert(false, 'Error during parsing' + err.stack));
});
});
});
1 change: 1 addition & 0 deletions test/FakeResponses/Air/AirCancelUR.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"><SOAP:Body><universal:UniversalRecordCancelRsp TransactionId="76FEEF0B0A0759DB8CF41511B47E0979" ResponseTime="701" xmlns:universal="http://www.travelport.com/schema/universal_v36_0"><universal:ProviderReservationStatus CreateDate="2016-09-29T17:30:00.571+00:00" ModifiedDate="2016-09-29T17:30:01.662+00:00" ProviderCode="1G" LocatorCode="PR0VQO" Cancelled="true"><universal:CancelInfo Code="0" Type="Warning"/></universal:ProviderReservationStatus></universal:UniversalRecordCancelRsp></SOAP:Body></SOAP:Envelope>

0 comments on commit 7de1489

Please sign in to comment.