I’m creating a prorated charge for the 1st subscription month using billing_cycle_anchor to make sure that the 1st full invoice is charged on the 1st of the next month.
This part works well but then Stripe calculates a prorated rate for the current invoice to be between (right now) & the future billing date (set by the billing cycle anchor).
How can I calculate and show this prorated charge to my customer before actually charging their card?
Currently we are using the below logic to calculate the current month’s prorated charge using unix timestamp but its not exact. Our formula displayed 3.54 USD but Stripe ended up charging 3.87 USD . Sometimes it does show the exact value but we need a foolproof solution.
async function getThisMonth(pmtdata) {
let now = Date.now();
var lastday = function(y,m){
return new Date(y, m +1, 0).getDate();
}
let seconds = now / 1000;
let year = new Date().getFullYear();
let month = new Date().getMonth();
if(month <= 10) {
let date = lastday(year,month);
let l1 = 86400 * Number(date);
let l2 = Number(pmtdata.numberPrice) / l1;
let todayD = new Date().getUTCDate();
let l3 = date - todayD;
let l4 = 86400 * l3;
let finalOut = Number(l2 * l4).toFixed(2);
$w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
} else if(month === 11) {
month = await -1;
let date = lastday(year,month);
let l1 = 86400 * Number(date);
let l2 = Number(pmtdata.numberPrice) / l1;
let todayD = new Date().getUTCDate();
let l3 = date - todayD;
let l4 = 86400 * l3;
let finalOut = Number(l2 * l4).toFixed(2);
$w("#thisMonth").text = finalOut + ' ' + pmtdata.currency;
}
}
Is there any way to get the exact amount that Stripe will charge? Went over the internet but could not find any resource that would return the exact amount Stripe would charge. Any hacks?