Compute Monthly earnings details

Hey, I’m working on an app to update my Smiirl physical counter to display the “In progress” Monthly earnings details as shown here: Insights | Patreon.

I’m using the T0shik/PatreonClient: Patreon v2 api c# client (github.com) library.

Right now, I’m collecting all active_patron members and their respective pledges through the below code, but I’m not getting the same value as the one from patreon web interface.

private enum ChargeStatus
{
    Paid,
    Declined,
    Deleted,
    Pending,
    Refunded,
    Fraud,
    Other
};
// Get the first day of the current month
DateTime currentDate = DateTime.Today;
DateTime firstDayOfMonth = new DateTime(currentDate.Year, currentDate.Month, 1);

Task<List<PatreonData<Member, MemberRelationships>>> membersResponse = Task.Run(() => GetMembers(patreonCampaignId));
List<PatreonData<Member, MemberRelationships>> members = membersResponse.Result;

IEnumerable<PatreonData<Member, MemberRelationships>> members_active = members.Where(data => data.Attributes.PatreonStatus is not null && data.Attributes.PatreonStatus.Equals("active_patron"));

// Loop through each enum value and calculate the sum
foreach (ChargeStatus status in Enum.GetValues(typeof(ChargeStatus)))
{
    // reset value
    CurrentlyEntitledAmountCents[status] = 0;

    foreach(Member member in members.Select(mem => mem.Attributes))
    {
        if (member.LastChargeStatus != Enum.GetName(status))
            continue;

        DateTimeOffset LastChargeDate = member.LastChargeDate.Value;
        DateTimeOffset NextChargeDate = member.NextChargeDate.Value;

        if (NextChargeDate >= firstDayOfMonth && NextChargeDate < DateTime.Today.AddDays(1))
            CurrentlyEntitledAmountCents[status] += member.CurrentlyEntitledAmountCents;
        else if (LastChargeDate >= firstDayOfMonth)
            CurrentlyEntitledAmountCents[status] += member.CurrentlyEntitledAmountCents;
    }

    // from cents to dollars
    CurrentlyEntitledAmountCents[status] /= 100.0f;
}

CurrentlyEntitledAmountCents[ChargeStatus.Paid] -= CurrentlyEntitledAmountCents[ChargeStatus.Declined];

// compute fees
float platformfees = CurrentlyEntitledAmountCents[ChargeStatus.Paid] / 100f * 5.0f;
float paymentfees = CurrentlyEntitledAmountCents[ChargeStatus.Paid] / 100f * 15.0f;

float earnings = CurrentlyEntitledAmountCents[ChargeStatus.Paid] - (platformfees + paymentfees);

Anyone here to help figure out what I’m doing wrong ?

Asking this in the support forum of that specific lib may be more appropriate.

The logic should be independent of the library itself, yet I couldn’t find anything online to expressively reproduce the insights logic.

So is there a difference in between the value you receive for the patronage amounts and what you see in those members’ details at patreon.com?

Yes. I can’t get the exact logic right. Let’s take C# aside, I guess if I could get the compute logic in generic terms that’d be enough.

Right now, I’m:

  • Pulling all members
  • Sorting them based on their respective status (paid, declined, deleted, …)
  • Storing the sum of all CurrentlyEntitledAmountCents (per status) of member where: nextcharge date or lastcharge date is >= first day of current month.

But even here, the sum of all “Paid” is not the same gross revenue value as displayed in insights/earnings.

Now, the thing is that the values are important before the compute logic of anything. So are you saying that when you make a call for the patron’s details, the raw return from the api for that payment data does not match what you see at patreon.com? That’s the key thing and everything else is secondary.