Last active
January 15, 2023 02:49
-
-
Save mychaelgo/046beecea4e6c4f44f1e40f6cb38a731 to your computer and use it in GitHub Desktop.
Tokopedia transaction
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
const data = require('./data.json'); | |
const convertToReadable = (data) => { | |
const result = []; | |
data[0].data.uohOrders.orders.forEach((order) => { | |
const invoiceUrl = JSON.parse(order.metadata.queryParams).invoice_url || `https://tokopedia.com${order.metadata.detailURL.webURL}`; | |
const paymentDate = order.metadata.paymentDate; | |
const products = order.metadata.products.map((product) => { | |
const title = product.title; | |
const inline1 = product.inline1.label; | |
return `${title} (${inline1})`; | |
}).join(', '); | |
const totalPrice = order.metadata.totalPrice.value; | |
result.push({ | |
invoiceUrl, | |
paymentDate, | |
products, | |
totalPrice | |
}); | |
}); | |
return result; | |
}; | |
const convertToTransaction = (data) => { | |
data.forEach((order) => { | |
const invoiceUrl = order.invoiceUrl; | |
// format 2022-03-30T14:17:44.011204331+07:00 to 30/03/2022 | |
const paymentDate = order.paymentDate.split('T')[0].split('-').reverse().join('/'); | |
const products = order.products; | |
const totalPrice = order.totalPrice.replace(new RegExp(/(Rp|\.| )/g), ''); | |
console.log(`;${paymentDate};;Kategori;${totalPrice};${invoiceUrl} ${products}`); | |
}); | |
}; | |
const readableData = convertToReadable(data); | |
const transactions = convertToTransaction(readableData); |
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
const data = require('./shopee.json'); | |
const convertToReadable = () => { | |
const result = []; | |
data.data.order_data.details_list.forEach((order) => { | |
const products = order.info_card.order_list_cards[0].items.map(i => { | |
return i.name; | |
}).join(', '); | |
const orderId = order.info_card.order_id; | |
result.push({ | |
final_total: order.info_card.final_total / 100000, | |
link: `https://shopee.co.id/user/purchase/order/${orderId}`, | |
products, | |
}); | |
}); | |
return result; | |
}; | |
const convertToTransaction = (data) => { | |
data.forEach((order) => { | |
const invoiceUrl = order.link; | |
// format 2022-03-30T14:17:44.011204331+07:00 to 30/03/2022 | |
// const paymentDate = order.paymentDate.split('T')[0].split('-').reverse().join('/'); | |
const products = order.products; | |
const totalPrice = order.final_total; | |
console.log(`;;;Kategori;${totalPrice};${invoiceUrl} ${products}`); | |
}); | |
}; | |
const readableData = convertToReadable(data); | |
const convertedData = convertToTransaction(readableData); | |
// console.log({ readableData }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment