const {
get_date_header_parser,
parsers_html_wrapper
} = require('./helpers');
const time = require('../../../utils/time');
module.exports = {
q: `from:polestar@polestar-email.com subject:"Auto Pay Reminder"`,
headers: get_date_header_parser('created_date'),
html: parsers_html_wrapper(function (root) {
const transaction = {};
let values_to_match_remaining = 2;
const ps = root.querySelectorAll('p');
for (const p of ps) {
if (p.innerText) {
for (let line of p.innerText.split('\n')) {
line = line.trim();
if (line.startsWith('Payment amount')) {
transaction.value = line.split(':')[1].trim().replace('$', '').replace(',', '') * -1;
if (--values_to_match_remaining === 0) return transaction;
} else if (line.startsWith('Auto Pay processing date')) {
transaction.date = time.iso(time.now(line.split(':')[1].trim(), 'MMMM D, YYYY'));
if (--values_to_match_remaining === 0) return transaction;
}
}
}
}
console.error('Polestar parser failed to find all data');
return transaction;
})
};