Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refunds #4837

Merged
merged 11 commits into from
Jan 23, 2025
Merged

Refunds #4837

merged 11 commits into from
Jan 23, 2025

Conversation

birkjernstrom
Copy link
Member

@birkjernstrom birkjernstrom commented Jan 16, 2025

Fortunately refunds across sellers on Polar has historically been super low (< 1%). Given our fast support, we've been able to help sellers in those cases with refunds within minutes/hours. But of course, a billing platform cannot live without built-in refund support 🙊 So time to solve this table stake once and for all.

Before merge:

  • Sync order aggregated refund stats on refunds
  • Handle refund.failed from Stripe (upsert - we don't know if it's possible and cannot trigger...)
  • Remove embedding order.refunds
  • Remove charge.refunded handler in favour of refund.created|updated
  • Webhooks for refund.created and refund.updated
  • GET /v1/refunds with filters on order_id, subscription_id, customer_id
  • UI to show refunds in order list view
  • Setting to revoke benefits on refund, i.e one-time purchases

UI Follow-up (Quick)

  • UI: Create refund from order dashboard
  • UI: Show orders on cancellation of subscription - prompt to refund latest charge?

Copy link

vercel bot commented Jan 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
polar ⬜️ Ignored (Inspect) Visit Preview Jan 23, 2025 8:50am
polar-sandbox ⬜️ Ignored (Inspect) Visit Preview Jan 23, 2025 8:50am

Copy link
Contributor

github-actions bot commented Jan 16, 2025

📦 Next.js Bundle Analysis for web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 154.81 KB (🟡 +1 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Eighty-four Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/layout 114.12 KB 268.93 KB 76.84% (🟡 +0.08%)
/checkout/[clientSecret]/confirmation/page 279.28 KB 434.08 KB 124.02% (🟡 +0.11%)
/checkout/[clientSecret]/page 273.3 KB 428.1 KB 122.32% (🟡 +0.07%)
/(main)/layout 83.5 KB 238.31 KB 68.09% (🟡 +0.07%)
/(main)/signup/page 139.05 KB 293.86 KB 83.96% (🟡 +0.08%)
/(main)/login/page 166.58 KB 321.39 KB 91.83% (🟡 +0.07%)
/(main)/(installation)/github/installation/page 128.23 KB 283.04 KB 80.87% (🟡 +0.07%)
/(main)/(topbar)/layout 244.48 KB 399.29 KB 114.08% (🟡 +0.11%)
/(main)/[organization]/(header)/layout 278.11 KB 432.91 KB 123.69% (🟡 +0.11%)
/(main)/[organization]/(header)/issues/page 124.98 KB 279.79 KB 79.94% (🟡 +0.10%)
/(main)/[organization]/(header)/page 137.68 KB 292.48 KB 83.57% (🟡 +0.10%)
/(main)/[organization]/(header)/products/[productId]/page 191.79 KB 346.6 KB 99.03% (🟡 +0.07%)
/(main)/[organization]/[repo]/issues/[number]/(create)/page 201.09 KB 355.9 KB 101.69% (🟡 +0.10%)
/(main)/[organization]/[repo]/layout 234.86 KB 389.66 KB 111.33% (🟡 +0.11%)
/(main)/[organization]/[repo]/issues/[number]/status/page 229.13 KB 383.93 KB 109.70% (🟡 +0.10%)
/(main)/[organization]/[repo]/page 205.49 KB 360.3 KB 102.94% (🟡 +0.11%)
/(main)/backoffice/badge/page 43.96 KB 198.77 KB 56.79% (🟡 +0.10%)
/(main)/backoffice/layout 259.99 KB 414.79 KB 118.51% (🟡 +0.11%)
/(main)/backoffice/issue/[id]/page 53.91 KB 208.72 KB 59.63% (🟡 +0.10%)
/(main)/[organization]/portal/page 222.51 KB 377.32 KB 107.80% (🟡 +0.11%)
/(main)/backoffice/pledges/page 56.18 KB 210.98 KB 60.28% (🟡 +0.10%)
/(main)/backoffice/rebadge/page 41.84 KB 196.64 KB 56.18% (🟡 +0.08%)
/(main)/backoffice/rewards_pending/page 58.01 KB 212.81 KB 60.80% (🟡 +0.10%)
/(main)/(landing)/page 260.87 KB 415.68 KB 118.76% (🟡 +0.08%)
/(main)/(landing)/layout 217.65 KB 372.46 KB 106.42% (🟡 +0.08%)
/(main)/(topbar)/(backer)/purchases/license-keys/page 91.65 KB 246.45 KB 70.42% (🟡 +0.10%)
/(main)/(topbar)/(backer)/layout 81.65 KB 236.46 KB 67.56% (🟡 +0.07%)
/(main)/(topbar)/(backer)/purchases/file-downloads/page 176.48 KB 331.29 KB 94.65% (🟡 +0.11%)
/(main)/(topbar)/(backer)/purchases/products/[id]/page 195.56 KB 350.37 KB 100.11% (🟡 +0.10%)
/(main)/(topbar)/(backer)/purchases/products/page 90.86 KB 245.66 KB 70.19% (🟡 +0.11%)
/(main)/(topbar)/(backer)/purchases/subscriptions/[id]/page 216.25 KB 371.05 KB 106.02% (🟡 +0.10%)
/(main)/(topbar)/(backer)/purchases/subscriptions/page 90.91 KB 245.72 KB 70.21% (🟡 +0.10%)
/(main)/(topbar)/(backer)/settings/page 262.34 KB 417.14 KB 119.18% (🟡 +0.11%)
/(main)/[organization]/portal/(topbar)/authenticate/page 72.54 KB 227.35 KB 64.96% (🟡 +0.10%)
/(main)/[organization]/portal/(topbar)/orders/[id]/page 195.45 KB 350.26 KB 100.07% (🟡 +0.11%)
/(main)/[organization]/portal/(topbar)/request/page 68.26 KB 223.07 KB 63.73% (🟡 +0.10%)
/(main)/[organization]/portal/(topbar)/subscriptions/[id]/page 213.88 KB 368.68 KB 105.34% (🟡 +0.10%)
/(main)/dashboard/(create)/create/page 155.58 KB 310.39 KB 88.68% (🟡 +0.10%)
/(main)/dashboard/[organization]/storefront/page 383.11 KB 537.92 KB 153.69% (🟡 +0.11%)
/(main)/dashboard/[organization]/layout 46.4 KB 201.21 KB 57.49% (🟡 +0.10%)
/(main)/(landing)/(mdx)/blog/(header)/better-pricing/page 33.58 KB 188.39 KB 53.83% (+/- <0.01%)
/(main)/(landing)/(mdx)/legal/terms/page 33.58 KB 188.39 KB 53.83% (+/- <0.01%)
/(main)/(topbar)/(backer)/(sidebar)/funding/page 253.27 KB 408.08 KB 116.59% (🟡 +0.11%)
/(main)/(topbar)/(backer)/(sidebar)/layout 138.23 KB 293.03 KB 83.72% (🟡 +0.10%)
/(main)/(topbar)/(backer)/finance/account/page 201.52 KB 356.33 KB 101.81% (🟡 +0.10%)
/(main)/(topbar)/(backer)/finance/layout 215.76 KB 370.57 KB 105.88% (🟡 +0.10%)
/(main)/(topbar)/(backer)/finance/incoming/page 236.44 KB 391.25 KB 111.79% (🟡 +0.10%)
/(main)/(topbar)/(backer)/finance/outgoing/page 187.89 KB 342.7 KB 97.91% (🟡 +0.11%)
/(main)/(topbar)/(backer)/finance/rewards/page 116.39 KB 271.2 KB 77.49% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/(home)/page 340.95 KB 495.76 KB 141.64% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/layout 259.98 KB 414.79 KB 118.51% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/benefits/license-keys/page 293.32 KB 448.13 KB 128.04% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/analytics/page 397.14 KB 551.95 KB 157.70% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/benefits/page 360.31 KB 515.11 KB 147.18% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/customers/[id]/page 390.92 KB 545.73 KB 155.92% (🟡 +0.06%)
/(main)/dashboard/[organization]/(header)/customers/page 291.95 KB 446.76 KB 127.65% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/initialize/page 144.3 KB 299.11 KB 85.46% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/issues/badge/page 287.25 KB 442.06 KB 126.30% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/issues/organizations/page 262.5 KB 417.31 KB 119.23% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/issues/embed/page 262.59 KB 417.4 KB 119.26% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/issues/overview/page 302.29 KB 457.1 KB 130.60% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/members/page 260.93 KB 415.74 KB 118.78% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/meters/page 291.96 KB 446.76 KB 127.65% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/meters/[slug]/page 431.7 KB 586.51 KB 167.57% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/products/benefits/page 359.82 KB 514.63 KB 147.04% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/products/[id]/page 355.56 KB 510.37 KB 145.82% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/products/discounts/page 328.49 KB 483.3 KB 138.09% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/products/page 295.67 KB 450.48 KB 128.71% (🟡 +0.12%)
/(main)/dashboard/[organization]/(header)/products/new/page 347.43 KB 502.24 KB 143.50% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/sales/[id]/page 307.23 KB 462.03 KB 132.01% (🟡 +9.21%)
/(main)/dashboard/[organization]/(header)/sales/page 308.89 KB 463.7 KB 132.49% (🟡 +0.13%)
/(main)/dashboard/[organization]/(header)/sales/subscriptions/page 298.8 KB 453.61 KB 129.60% (🟡 +0.13%)
/(main)/dashboard/[organization]/(header)/settings/custom-fields/page 299.52 KB 454.33 KB 129.81% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/settings/webhooks/endpoints/[id]/page 299.22 KB 454.03 KB 129.72% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/settings/page 280.22 KB 435.03 KB 124.29% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/settings/webhooks/page 280.82 KB 435.63 KB 124.47% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/finance/incoming/page 184.44 KB 339.24 KB 96.93% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/finance/layout 259.99 KB 414.79 KB 118.51% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/finance/account/page 149.66 KB 304.47 KB 86.99% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/finance/outgoing/page 135.51 KB 290.32 KB 82.95% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/contributors/page 64.24 KB 219.05 KB 62.59% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/layout 259.99 KB 414.79 KB 118.51% (🟡 +0.11%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/page 64.96 KB 219.77 KB 62.79% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/rewarded/page 64.23 KB 219.04 KB 62.58% (🟡 +0.10%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

Copy link
Member

@frankie567 frankie567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things there and there, the main thing being that PaymentProcessor enum thing :)

server/polar/kit/db/models/base.py Outdated Show resolved Hide resolved
server/polar/models/order.py Outdated Show resolved Hide resolved
server/polar/models/transaction.py Show resolved Hide resolved
server/polar/pledge/service.py Show resolved Hide resolved
server/polar/refund/endpoints.py Outdated Show resolved Hide resolved
server/polar/webhook/webhooks.py Show resolved Hide resolved
server/polar/webhook/webhooks.py Show resolved Hide resolved
server/polar/webhook/webhooks.py Outdated Show resolved Hide resolved
server/polar/webhook/webhooks.py Outdated Show resolved Hide resolved
server/polar/webhook/webhooks.py Outdated Show resolved Hide resolved
Refunds can be created from Polar API & Stripe Webhook `refund.created`
and our API triggers the latter too.

Since we want to return the refund in our API response, we cannot rely
on `refund.created` handling only.

Therefore, we need to upsert on both to avoid race condition issues.
Better to listen to `order.refunded` for the intent and
`refund.succeeded` and `refund.created` would cause a race condition and
more nuanced implementations.

Good idea, but not entirely clear in practice.
@birkjernstrom birkjernstrom dismissed frankie567’s stale review January 23, 2025 09:03

Already fixed everything :)

@birkjernstrom birkjernstrom merged commit 37bdc8d into main Jan 23, 2025
11 checks passed
@birkjernstrom birkjernstrom deleted the feat/refunds branch January 23, 2025 09:03
Copy link

sentry-io bot commented Jan 23, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ InvalidRequestError: Request req_zx8xpTSitTKCNZ: Charge py_3Qjk3oDIA9pgt25r0ss8f44M has already been refunded. polar.refund.endpoints.create View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants