Skip to content

Instantly share code, notes, and snippets.

@benmacleod
Created May 20, 2022 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmacleod/46140a29bfe33f46ae253f5caa3c8a0b to your computer and use it in GitHub Desktop.
Save benmacleod/46140a29bfe33f46ae253f5caa3c8a0b to your computer and use it in GitHub Desktop.
Capturing where a donation's amount doesn't match a subscription's amount
SELECT s.region_id, s.frequency, s.payment_provider, s.payment_method, s.created_at, s.id, s.email, s.amount_in_local, d.amount_in_local, >
FROM subscriptions s
JOIN donations d ON s.id = d.subscription_id
WHERE d.amount_in_local != s.amount_in_local
AND s.created_at > CURRENT_TIMESTAMP - INTERVAL '3 years'
GROUP BY 1,2,3,4,5,6,7,8,9
ORDER BY 1,2,3,4,5
;
-- Some reasons:
-- 1. donor/admin changes amount via Stripe or PayPal
-- 2. for PayPal, billing failed one month, then doubles up the following month
-- 3. when admins increased a monthly donation in Stripe, there is sometimes an extra "pro-rated" payment which makes up for supposed missing revenue coming from the part of the month that has already happened which "should have been" charged at the new amount
-- 4. for a time, we would round pledges down to the nearest dollar/pound/euro (source PR?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment