Skip to content

Commit

Permalink
chore: remove preparing only instanciate
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgnreis committed Oct 27, 2023
1 parent bbae4e9 commit 99c4cbf
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions functions/routes/ecom/modules/calculate-shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ exports.post = ({ appSdk }, req, res) => {

const enivixAxios = new EnivixAxios(api_key, token, email, storeId)

/* if (!params.to) {
if (!params.to) {
// just a free shipping preview with no shipping address received
// respond only with free shipping option
res.send(response)
return
} */
}

if (!tokenProd) {
// must have configured kangu doc number and token
Expand Down Expand Up @@ -123,30 +123,27 @@ exports.post = ({ appSdk }, req, res) => {
weight: kgWeight
})
})

const body = {
auth: tokenProd,
to: destinationZip,
weight: finalWeight,
value: cartSubtotal || params.subtotal,
items
}

enivixAxios.preparing
.then(() => {
const { axios } = enivixAxios
console.log('> Calculate enivix ', JSON.stringify(body), ' <<')
// https://axios-http.com/ptbr/docs/req_config
const validateStatus = function (status) {
return status >= 200 && status <= 301
}
return axios.post('/get/bid', body, {
maxRedirects: 0,
validateStatus

return axios.post(
'https://oms.enivix.com.br/api/get/bid',
body,
{
headers: {
'Content-type': 'application/json'
}
},
{
timeout: (params.is_checkout_confirmation ? 8000 : 6000)
})
})
}
)
.then(result => {
const { data, status } = result
if (data && status === 200) {
Expand Down

0 comments on commit 99c4cbf

Please sign in to comment.