Chart built-in membership revenue from what was actually charged
Monthly net revenue for a show, per currency, from Benecaster’s record of what each payment actually charged rather than from today’s prices — with the “recorded since” date the chart needs to be honest about where the record begins.
It reads benecaster_get_membership_payments() for the last twelve months and benecaster_get_membership_payments_recorded_since() for the start of the record.
Code
<?php
function my_monthly_membership_revenue( int $show_id ): array {
$rows = benecaster_get_membership_payments( $show_id, [
'date_from' => gmdate( 'Y-m-01', strtotime( '-11 months' ) ),
] );
$months = [];
foreach ( $rows as $row ) {
$month = substr( $row['paid_at'], 0, 7 ); // UTC month
$currency = $row['currency']; // never sum across currencies
$net = $row['amount_paid'] - $row['amount_tax'] - $row['amount_refunded'];
$months[ $currency ][ $month ] = ( $months[ $currency ][ $month ] ?? 0 ) + $net; // minor units
}
return [
'by_currency' => $months,
'recorded_since' => benecaster_get_membership_payments_recorded_since(), // say so on the chart
];
}
Need this built rather than just documented? See our services →