Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Treat checkout.session.completed as purchase-granting and revoke async
-- Checkout Sessions only if Stripe later reports async_payment_failed.
CREATE OR REPLACE VIEW "UserProduct" AS (
SELECT
"userId",
"subscriptionId",
"productId",
"customerId",
"customerEmail"
FROM
"TransactionLog" AS tl
WHERE
"status" = 'complete'
AND "eventType" = 'checkout.session.completed'
AND NOT EXISTS (
SELECT
1
FROM
"TransactionLog" AS failed
WHERE
failed."eventType" = 'checkout.session.async_payment_failed'
AND failed."eventData"#>>'{data,object,id}' =
tl."eventData"#>>'{data,object,id}'
AND failed."eventCreated" >= tl."eventCreated")
AND NOT EXISTS (
SELECT
1
FROM
"TransactionLog" AS tlexsists
WHERE
tlexsists."subscriptionId" = tl."subscriptionId"
AND tlexsists."eventType" = 'customer.subscription.deleted'
AND tlexsists."status" = 'canceled'
AND tlexsists."eventCreated" > tl."eventCreated")
AND NOT EXISTS (
SELECT
1
FROM
"TransactionLog" AS tlexsists
WHERE
tlexsists."paymentIntent" = tl."paymentIntent"
AND tlexsists."eventType" = 'charge.refunded'
AND tlexsists."status" = 'succeeded'
AND tlexsists."eventCreated" > tl."eventCreated")
ORDER BY
"userId",
"eventCreated" DESC)
UNION ALL (
SELECT
"userId",
"subscriptionId",
"productId",
"customerId",
"customerEmail"
FROM
"TransactionLog"
WHERE
"eventType" = 'appsumo.activate');
Loading