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 ?