Skip to content

Commit 9eed77a

Browse files
authored
Fix cleared at use in contribution time series (#11165)
* Record stripe transaction cleared at on the date balance transactions indicates its cleared * Filter contributions timeseries based on clearedAt first, coalescing to created at * Add fallback to charge created at date
1 parent 8030138 commit 9eed77a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

server/graphql/v2/object/AccountStats.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ export const GraphQLAccountStats = new GraphQLObjectType({
800800
const results = await sequelize.query(
801801
`
802802
SELECT
803-
DATE_TRUNC(:timeUnit, t."createdAt") AS "date",
803+
DATE_TRUNC(:timeUnit, COALESCE(t."clearedAt", t."createdAt")) AS "date",
804804
(CASE WHEN o."SubscriptionId" IS NOT NULL THEN 'recurring' ELSE 'one-time' END) as "label",
805805
ABS(SUM(t."amount")) as "amount",
806806
t."currency"
@@ -813,8 +813,8 @@ export const GraphQLAccountStats = new GraphQLObjectType({
813813
AND o."FromCollectiveId" NOT IN (:collectiveIds)
814814
AND t."type" = 'CREDIT'
815815
AND t."kind" = 'CONTRIBUTION'
816-
${dateFrom ? `AND t."createdAt" >= :startDate` : ``}
817-
${dateTo ? `AND t."createdAt" <= :endDate` : ``}
816+
${dateFrom ? `AND COALESCE(t."clearedAt", t."createdAt") >= :startDate` : ``}
817+
${dateTo ? `AND COALESCE(t."clearedAt", t."createdAt") <= :endDate` : ``}
818818
GROUP BY "date", "label", t."currency"
819819
ORDER BY "date", ABS(SUM(t."amount")) DESC
820820
`,

server/paymentProviders/stripe/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ export const createChargeTransactions = async (
174174
platformFeeInHostCurrency = fees.applicationFee;
175175
}
176176

177-
const clearedAt = charge.created ? moment.unix(charge.created).toDate() : null;
177+
const clearedAtField = balanceTransaction.available_on || charge.created || null;
178+
const clearedAt = clearedAtField ? moment.unix(clearedAtField).toDate() : null;
178179

179180
const paymentProcessorFeeInHostCurrency = fees.stripeFee;
180181

0 commit comments

Comments
 (0)