Skip to content

Instantly share code, notes, and snippets.

@johntran johntran/wineTax.js

Last active Aug 1, 2020
Embed
What would you like to do?
ES7 async/await with SOAP requests in NodeJS
import soap from 'soap';
import moment from 'moment';
const taxServiceUrl = 'http://hehexd.com/services/1.2/taxservice.asmx?WSDL'
export function generateJsonForTaxRate(json) {
const EffectiveDate = moment().toISOString();
const {
city: City,
state: State,
addressLineOne: Street1,
addressLineTwo: Street2,
Zip1,
Username,
Password,
PartnerKey
} = json;
return ({
'Request': {
'Security': {
PartnerKey,
Password,
Username,
},
'Address': {
City,
State,
Street1,
Street2,
Zip1,
},
EffectiveDate,
'TaxSaleType': 'Offsite'
}
});
}
export function getTaxRate(xml) {
return new Promise ((resolve, reject) => {
soap.createClient(taxServiceUrl, (err, client) => {
client.GetSalesTaxRatesByAddress(xml, (err, result, body) => {
const wineTax = result['GetSalesTaxRatesByAddressResult']['TaxRates']['WineSalesTaxPercent'];
return resolve(wineTax)
})
});
});
}
export async function shipCompliantTaxRateGet(request, response) {
try {
const { zip } = request.body;
const json = generateJsonForTaxRate(zip)
const wineTax = await getTaxRate(json);
response.status(200).json({ wineTax });
} catch (error) {
response.status(200).json({ error: 'No Results' });
}
}
@dardanos

This comment has been minimized.

Copy link

dardanos commented Aug 1, 2020

@johntran you are the real MVP

@johntran

This comment has been minimized.

Copy link
Owner Author

johntran commented Aug 1, 2020

@dardanos Good luck dealing with ShipCompliant / SOAP Requests. lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.