async function _post(module, method, body={}, formData=false) {
if (formData == true) {
headers = {headers: { "Content-Type": "multipart/form-data" }}
if (body.get("method") == null) {
body.append("method", method)
}
body.append("token", "");
}
else {
headers = {headers: {'Content-Type': 'application/json'}}
if (!("method" in body)) {
body["method"] = method;
}
body["origin"] = window.location.href;
body["token"] = ""
body = JSON.stringify(body);
}
if ( module.toLowerCase().includes('tfadmin') || method == "error") {
ep = 'https://24pound.com/'+module+'.cfc?method='+method;
res = await axios.post(ep, body, headers)
}
else {
ep = 'https://24pound.com/api/api.cfc?method=ep';
res = await axios.post(ep, body, headers)
}
return res;
}
async function validateAddress(newAddr, parent, callback, addrObj) {
try {
for (k in newAddr) {
if (newAddr[k] === null) {
newAddr[k] = '';
parent[addrObj][k] = '';
}
}
}
catch(err) {}
r = await _post("api/api", "validateAddress", {"shipTo": newAddr});
res = r.data;
if (parent[addrObj].add1.match(/\b(P\.?O\.?)\b\D+\d+/g) || ( !!parent[addrObj].add2 && parent[addrObj].add2.match(/\b(P\.?O\.?)\b\D+\d+/g) ) || res.status == 'PO_BOX' ) {
parent.$buefy.dialog.alert({
title: "PO Box Address",
message: "Please Note: We are unable to ship to a PO Box address. Please enter a commercial or residential address to proceed. Residential addresses do not qualify for VIP shipment discount.",
confirmText: "Go Back and Edit Address"
})
return 0
}
else if ("error" in res) {
if (true === false) {console.log('')}
if (
'validatedBy' in parent[addrObj]
&& (
parent[addrObj].validatedBy == 'client'
||
parent[addrObj].validatedBy.match(/^\d+$/g)
)
) {
parent[callback](parent[addrObj].validatedBy)
}
else {
parent[addrObj].isResidential = 0
parent.$buefy.dialog.confirm({
title: "Address Validation Error",
message: "We were unable to validate parent address.
Error: " + res.error + "
Please confirm the address is correct before proceeding or adjust if needed.",
cancelText: "Go Back and Edit Address",
confirmText: "Proceed with the Address",
onConfirm: () => parent[callback]("client")
})
}
}
else if (res.status == 'valid') {
parent[addrObj].isResidential = res.type=='residential'? 1:0;
if (res.type=='residential' && callback != 'quoteShipping' && !('validatedBy' in parent[addrObj]) ) {
parent.$buefy.dialog.confirm({
title: "Residential Address",
message: "This address validated as a Residential Address with the USPS and does not qualify for VIP Delivery. Please choose one of the following options.
FedEx determines if your address is commercial or residential. If you believe your address should qualify as a commercial address, please contact FedEx and let us know if there are any changes to it.
", cancelText: "Enter a different Shipping Address", confirmText: "Proceed with Residential Shipping Address", onConfirm: () => proceedValidation(parent, callback, newAddr, addrObj, res) }) } else { proceedValidation(parent, callback, newAddr, addrObj, res) } } return res; } async function proceedValidation(parent, callback, newAddr, addrObj, res) { if ('validatedBy' in parent[addrObj] && (parent[addrObj].validatedBy == 'api' || parent[addrObj].validatedBy == 'client' || parent[addrObj].validatedBy.match(/^\d+$/g)) ) { parent[callback](parent[addrObj].validatedBy) } else { if ('changed' in res && Object.keys(res.changed).length > 0) { console.log("ding changed") parent.$buefy.dialog.confirm({ title: "Address Recommendation", message: `Address standardization suggested the following changes. Would you like to update this address?
Address Entered
${parent[addrObj].add1} ${parent[addrObj].add2 != ''? '
'+parent[addrObj].add2:''}
${parent[addrObj].city}, ${parent[addrObj].state} ${parent[addrObj].zip}
Suggested Address
${res.suggestedAddr.add1} ${res.suggestedAddr.add2!=''? '
'+res.suggestedAddr.add2:''}
${res.suggestedAddr.city}, ${res.suggestedAddr.state} ${res.suggestedAddr.zip}
Payment type: ';
if (pmt.nickname != "") {
msg += "(CC) "+pmt.nickname;
}
else {
msg += pmt.cardType+" "+pmt.acctNo;
}
msg += "
Transaction date: "+pmt.paidDate+"
Transaction amount: "+pmt.amount+"
Payment type: ';
if (pmt.nickname != "") {
msg += "(ACH) "+pmt.nickname;
}
else {
msg += "Bank Account "+pmt.acctNo;
}
msg += "
Transaction date: "+pmt.paidDate+"
Transaction amount: "+pmt.amount+"