liteapi-node-sdk
Advanced tools
Comparing version 3.0.3 to 3.0.4
77
index.js
@@ -92,66 +92,5 @@ class LiteApi { | ||
* | ||
* @param {string} prebookId - prebook id retrived from prebook response. | ||
* @param {object} guestInfo - Format : {guestFirstName: 'Kim', guestLastName: 'James', guestEmail: 'test@nlite.ml'}. | ||
* @param {string} paymentMethod - Should be STRIPE_TOKEN or CREDIT_CARD. | ||
* @param {string} holderName - The holder name | ||
* @param {object} paymentInfo - If STRIPE_TOKEN is selected then {"token":YOUR_STRIPE_TOKEN}, if CREDIT_CARD is select then {"card_number" : "4242424242424242","exp_month":11,exp_year:"23","cvc":123} | ||
* @returns {object} - The result of the operation. | ||
* @param {object} data - the API request parameters | ||
*/ | ||
async book(prebookId, guestInfo, paymentMethod, holderName, paymentInfo) { | ||
let errors = []; | ||
let payment = {}; | ||
if (prebookId == "" || prebookId === undefined) { | ||
errors.push("The prebook ID is required"); | ||
} | ||
if (guestInfo == "" || guestInfo === undefined || typeof guestInfo !== 'object') { | ||
errors.push("Invalid guestInfo, it should be in this format : {guestFirstName: 'Kim', guestLastName: 'James', guestEmail: 'test@nlite.ml'}"); | ||
} else { | ||
if (!guestInfo.hasOwnProperty('guestFirstName') || !guestInfo.hasOwnProperty('guestLastName') || !guestInfo.hasOwnProperty('guestEmail')) { | ||
errors.push("Invalid guestInfo, it should be in this format : {guestFirstName: 'Kim', guestLastName: 'James', guestEmail: 'test@nlite.ml'}"); | ||
} | ||
} | ||
if (paymentMethod == "" || paymentMethod === undefined) { | ||
errors.push("Payment Method is required"); | ||
} else { | ||
if (!["CREDIT_CARD", "STRIPE_TOKEN"].includes(paymentMethod)) { | ||
errors.push("Available Payment Method are : CREDIT_CARD and STRIPE_TOKEN"); | ||
} else { | ||
payment["method"] = paymentMethod; | ||
} | ||
} | ||
if (holderName == "" || holderName === undefined) { | ||
errors.push("Holder name is required"); | ||
} else { | ||
payment["holderName"] = holderName; | ||
} | ||
if (paymentMethod == "CREDIT_CARD") { | ||
if (paymentInfo != "" && paymentInfo !== undefined && typeof paymentInfo === 'object') { | ||
if (!paymentInfo.hasOwnProperty('card_number') || !paymentInfo.hasOwnProperty('exp_month') || !paymentInfo.hasOwnProperty('exp_year') || !paymentInfo.hasOwnProperty('cvc')) { | ||
errors.push('The paymentInfo object is invalid, it should be in this format: {"card_number" : "4242424242424242","exp_month":11,exp_year:"23","cvc":123}'); | ||
} else { | ||
payment["number"] = paymentInfo.card_number; | ||
payment["expireDate"] = paymentInfo.exp_month + "/" + paymentInfo.exp_year; | ||
payment["cvc"] = paymentInfo.cvc + ""; | ||
} | ||
} else { | ||
errors.push('The paymentInfo object should in this format: {"card_number" : "4242424242424242","exp_month":11,exp_year:"23","cvc":123}'); | ||
} | ||
} else if (paymentInfo == "STRIPE_TOKEN") { | ||
if (paymentInfo != "" && paymentInfo !== undefined && typeof paymentInfo === 'object') { | ||
if (!paymentInfo.hasOwnProperty('token')) { | ||
errors.push('The paymentInfo object is invalid, it should be in this format:{"token":YOUR_STRIPE_TOKEN}'); | ||
} else { | ||
payment["token"] = paymentInfo.token; | ||
} | ||
} else { | ||
errors.push('The paymentInfo object should in this format: {"token":YOUR_STRIPE_TOKEN}'); | ||
} | ||
} | ||
if (errors.length > 0) { | ||
return { | ||
"status": "failed", | ||
"errors": errors | ||
} | ||
} | ||
async book(data) { | ||
const options = { | ||
@@ -164,14 +103,10 @@ method: 'POST', | ||
}, | ||
body: JSON.stringify({ | ||
prebookId: prebookId, | ||
guestInfo: guestInfo, | ||
payment: payment | ||
}) | ||
body: JSON.stringify(data) | ||
}; | ||
const response = await fetch(this.bookServiceURL + '/rates/book', options) | ||
const data = await response.json(); | ||
const result = await response.json(); | ||
if (!response.ok) { | ||
return { | ||
"status": "failed", | ||
"error": data.error | ||
"error": result.error | ||
} | ||
@@ -182,3 +117,3 @@ } | ||
"status": "success", | ||
"data": data.data | ||
"data": result.data | ||
} | ||
@@ -185,0 +120,0 @@ } |
{ | ||
"name": "liteapi-node-sdk", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Start building travel apps with liteAPI. Instantly access millions of hotels to build new or existing apps and platforms.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -445,10 +445,22 @@ <h1 style="font-weight: 500;">liteAPI SDK</h1> | ||
```js | ||
const prebookId = "8iaO7PXBU"; | ||
const guestInfo = { guestFirstName: 'Kim', guestLastName: 'James', guestEmail: 'test@nlite.ml' }; | ||
const paymentMethod = "CREDIT_CARD"; | ||
const holderName = "Kim James"; | ||
const paymentInfo = { "card_number": "4242424242424242", "exp_month": 11, "exp_year": 23, "cvc": 123,"token":null } | ||
const result = await liteApi.book(prebookId, guestInfo, paymentMethod, holderName, paymentInfo) | ||
const result = await liteApi.book({ | ||
holder: { | ||
firstName: 'Steve', | ||
lastName: 'Doe', | ||
email: 's.doe@liteapi.travel' | ||
}, | ||
payment: { | ||
method: 'TRANSACTION_ID', | ||
transactionId: '456' | ||
}, | ||
prebookId: '123', | ||
guests: [ | ||
{ | ||
occupancyNumber: 1, | ||
firstName: 'Sunny', | ||
lastName: 'Mars', | ||
email: 's.mars@liteapi.travel' | ||
} | ||
] | ||
}); | ||
``` | ||
@@ -455,0 +467,0 @@ * <h4 style="color:#9155fd; font-weight: 800;"> Parameters :</h4> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
639
132089
555