Last active
December 17, 2020 16:53
-
-
Save shahriar-shojib/78d0be68110cad4b21666cf5172de62e to your computer and use it in GitHub Desktop.
PaperFly Courier Delivery Tracking API [Bangladesh]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if you're using node.js uncomment below line and run "npm install node-fetch" | |
// const fetch = require('node-fetch') | |
async function paperfly (id, number) { | |
const res = await fetch('http://paperfly.com.bd/trackerapi.php', { | |
headers: { | |
'content-type': 'application/x-www-form-urlencoded' | |
}, | |
body: `orderid=${id}&phone=${number}`, | |
method: 'POST' | |
}).then(res => res.text()); | |
const matches = res.match(/(?<=\$\("#|.val\("|.html\(").*?(?="\))/g); | |
let obj = {}; | |
matches.forEach((e, i, arr) => { | |
if (i % 2 !== 0) { | |
obj[arr[i - 1]] = arr[i]; | |
} | |
}); | |
for (let key of Object.keys(obj)) { | |
obj[key] = obj[key].replace(/<span>|<\/span>/g, ''); | |
} | |
return { | |
orderID: obj.order_id_eng, | |
merchantRef: obj.merOrderRefeng, | |
type: obj.ordertypeeng, | |
estimatedDate: obj.deliverydate_eng, | |
name: obj.custnameeng, | |
phone: obj.custphoneeng, | |
address: obj.custaddresseng, | |
merchantName: obj.merchantnameeng, | |
productID: obj.productbriefeng, | |
price: obj.priceeng, | |
history: [ | |
{ | |
pickedTime: obj.picktimeeng | |
}, | |
{ | |
shipped: obj.shuttletimeeng | |
}, | |
{ | |
deliveryPoint: obj.dp2timeeng | |
}, | |
{ | |
outForDelivery: obj.pickdroptimeeng | |
}, | |
{ | |
delivered: obj.cashtimeeng | |
} | |
] | |
}; | |
} | |
//usage | |
paperfly('<tracking id>', 'phoneNumber').then(console.log).catch(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment