From 400e1b4ab6a00a6d21091ad6e435b19bff381dca Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Thu, 9 Mar 2023 15:26:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=203D=20secure=20payment=20?= =?UTF-8?q?not=20counted=20as=20paid=20subscription=20in=20graph?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes https://github.com/TryGhost/Team/issues/2644 A 3D secure payment first has a status of incomplete, then active. With the current logic, this creates 2 MemberPaidSubscriptionEvents: - `created` with mrr_delta of 0 - `active` with mrr_delta of 5 We need to also count 'active' events. And to complement that, also 'inactive' events to make sure we balance out in rare cases. --- ghost/stats-service/lib/subscriptions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ghost/stats-service/lib/subscriptions.js b/ghost/stats-service/lib/subscriptions.js index 8909fc43f9..4f3a758cfa 100644 --- a/ghost/stats-service/lib/subscriptions.js +++ b/ghost/stats-service/lib/subscriptions.js @@ -93,27 +93,27 @@ class SubscriptionStatsService { `)) .select(knex.raw(`SUM( CASE - WHEN members_paid_subscription_events.type IN ('created','reactivated') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 + WHEN members_paid_subscription_events.type IN ('created','reactivated','active') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 WHEN members_paid_subscription_events.type='updated' AND price.id = to_price.id THEN 1 ELSE 0 END ) as positive_delta`)) .select(knex.raw(`SUM( CASE - WHEN members_paid_subscription_events.type IN ('canceled', 'expired') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 + WHEN members_paid_subscription_events.type IN ('canceled', 'expired','inactive') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 WHEN members_paid_subscription_events.type='updated' AND price.id = from_price.id THEN 1 ELSE 0 END ) as negative_delta`)) .select(knex.raw(`SUM( CASE - WHEN members_paid_subscription_events.type IN ('created','reactivated') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 + WHEN members_paid_subscription_events.type IN ('created','reactivated','active') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 ELSE 0 END ) as signups`)) .select(knex.raw(`SUM( CASE - WHEN members_paid_subscription_events.type IN ('canceled', 'expired') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 + WHEN members_paid_subscription_events.type IN ('canceled', 'expired','inactive') AND members_paid_subscription_events.mrr_delta != 0 THEN 1 ELSE 0 END ) as cancellations`))