File tree Expand file tree Collapse file tree
packages/prisma-client/prisma/migrations/20260502000000_user_product_async_checkout Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ -- Treat checkout.session.completed as purchase-granting and revoke async
2+ -- Checkout Sessions only if Stripe later reports async_payment_failed.
3+ CREATE OR REPLACE VIEW "UserProduct " AS (
4+ SELECT
5+ " userId" ,
6+ " subscriptionId" ,
7+ " productId" ,
8+ " customerId" ,
9+ " customerEmail"
10+ FROM
11+ " TransactionLog" AS tl
12+ WHERE
13+ " status" = ' complete'
14+ AND " eventType" = ' checkout.session.completed'
15+ AND NOT EXISTS (
16+ SELECT
17+ 1
18+ FROM
19+ " TransactionLog" AS failed
20+ WHERE
21+ failed." eventType" = ' checkout.session.async_payment_failed'
22+ AND failed." eventData" # >>'{data,object,id}' =
23+ tl." eventData" # >>'{data,object,id}'
24+ AND failed." eventCreated" >= tl." eventCreated" )
25+ AND NOT EXISTS (
26+ SELECT
27+ 1
28+ FROM
29+ " TransactionLog" AS tlexsists
30+ WHERE
31+ tlexsists." subscriptionId" = tl." subscriptionId"
32+ AND tlexsists." eventType" = ' customer.subscription.deleted'
33+ AND tlexsists." status" = ' canceled'
34+ AND tlexsists." eventCreated" > tl." eventCreated" )
35+ AND NOT EXISTS (
36+ SELECT
37+ 1
38+ FROM
39+ " TransactionLog" AS tlexsists
40+ WHERE
41+ tlexsists." paymentIntent" = tl." paymentIntent"
42+ AND tlexsists." eventType" = ' charge.refunded'
43+ AND tlexsists." status" = ' succeeded'
44+ AND tlexsists." eventCreated" > tl." eventCreated" )
45+ ORDER BY
46+ " userId" ,
47+ " eventCreated" DESC )
48+ UNION ALL (
49+ SELECT
50+ " userId" ,
51+ " subscriptionId" ,
52+ " productId" ,
53+ " customerId" ,
54+ " customerEmail"
55+ FROM
56+ " TransactionLog"
57+ WHERE
58+ " eventType" = ' appsumo.activate' );
You can’t perform that action at this time.
0 commit comments