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

Cancel & Modify Subscriptions #4624

Merged
merged 8 commits into from
Jan 3, 2025
Merged

Cancel & Modify Subscriptions #4624

merged 8 commits into from
Jan 3, 2025

Conversation

birkjernstrom
Copy link
Member

@birkjernstrom birkjernstrom commented Dec 11, 2024

Closes #4595

Remaining (API)

  • Tests for DELETE /subscriptions/{id}
  • Better documentation for customer_reason
  • Fix reliance/usage of cancel_at_period_end now with cancel_at
  • Figure out a better cancel_at timestamp to avoid issues on slower networks...
  • Allow DELETE /subscriptions to set customer comment too
  • Tweak customer Cancellation notification email (subscription ending)
  • Send customer a Revoked notification email (fully cancelled)
  • Set cancel_at_period_end optimistically to keep API response up-to-date
  • Uncancel in subscription update

Remaining (UI)

  • Expose cancellation_reason & comment flag with the actual comment in details view
  • Better copy
  • Make it look beautiful 🤓

Follow-up enhancements

Copy link

vercel bot commented Dec 11, 2024

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 3, 2025 1:28pm
polar-sandbox ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2025 1:28pm

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 :)

server/polar/integrations/stripe/service.py Outdated Show resolved Hide resolved
clients/apps/web/src/hooks/queries/subscriptions.ts Outdated Show resolved Hide resolved
clients/apps/web/src/hooks/queries/subscriptions.ts Outdated Show resolved Hide resolved
server/polar/subscription/schemas.py Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jan 2, 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 155.27 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!

One Hundred Eighteen 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)
/_not-found/page 362 B 155.62 KB 44.46% (+/- <0.01%)
/layout 113.77 KB 269.04 KB 76.87% (🟡 +0.01%)
/checkout/[clientSecret]/confirmation/page 279.46 KB 434.72 KB 124.21% (🟡 +0.02%)
/checkout/[clientSecret]/page 273.99 KB 429.26 KB 122.65% (🟡 +0.03%)
/(main)/signup/page 138.55 KB 293.82 KB 83.95% (🟡 +0.01%)
/(main)/layout 83.19 KB 238.46 KB 68.13% (🟡 +0.01%)
/(main)/login/page 165.34 KB 320.61 KB 91.60% (🟡 +0.01%)
/(main)/verify-email/page 362 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/(installation)/github/installation/page 127.88 KB 283.15 KB 80.90% (🟡 +0.01%)
/(main)/(installation)/github/layout 361 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/[organization]/(header)/layout 277.27 KB 432.54 KB 123.58% (🟡 +0.21%)
/(main)/(topbar)/layout 242.2 KB 397.47 KB 113.56% (🟡 +0.02%)
/(main)/[organization]/(header)/page 138.36 KB 293.63 KB 83.89% (🟡 +0.06%)
/(main)/[organization]/(header)/issues/page 124.41 KB 279.68 KB 79.91% (🟡 +0.01%)
/(main)/[organization]/(header)/products/[productId]/page 192.44 KB 347.71 KB 99.34% (🟡 +0.04%)
/(main)/[organization]/[repo]/issues/[number]/status/page 227.77 KB 383.04 KB 109.44% (🟡 +0.05%)
/(main)/[organization]/[repo]/layout 233.63 KB 388.9 KB 111.12% (🟡 +0.01%)
/(main)/[organization]/[repo]/page 204.97 KB 360.24 KB 102.93% (🟡 +0.01%)
/(main)/[organization]/[repo]/issues/[number]/(create)/page 201.23 KB 356.5 KB 101.86% (🟡 +0.03%)
/(main)/[organization]/portal/page 220.8 KB 376.07 KB 107.45% (🟡 +4.60%)
/(main)/backoffice/badge/page 43.35 KB 198.62 KB 56.75% (🟡 +0.02%)
/(main)/backoffice/layout 571.05 KB 726.32 KB 207.52% (🟡 +0.09%)
/(main)/backoffice/issue/[id]/page 53.27 KB 208.54 KB 59.58% (🟡 +0.02%)
/(main)/backoffice/pledges/page 55.54 KB 210.81 KB 60.23% (🟡 +0.02%)
/(main)/backoffice/rewards_pending/page 57.37 KB 212.64 KB 60.75% (🟡 +0.02%)
/(main)/backoffice/rebadge/page 41.49 KB 196.76 KB 56.22% (🟡 +0.01%)
/(main)/dashboard/layout 362 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/docs/api/[...endpoint]/page 501.19 KB 656.46 KB 187.56% (🟡 +0.07%)
/(main)/(landing)/page 261.56 KB 416.83 KB 119.09% (🟡 +0.04%)
/(main)/(landing)/layout 216.04 KB 371.31 KB 106.09% (🟡 +0.01%)
/(main)/(topbar)/(backer)/purchases/file-downloads/page 174.16 KB 329.43 KB 94.12% (🟡 +0.02%)
/(main)/(topbar)/(backer)/layout 81.33 KB 236.6 KB 67.60% (🟡 +0.01%)
/(main)/(topbar)/(backer)/purchases/license-keys/page 90.21 KB 245.48 KB 70.14% (🟡 +0.01%)
/(main)/(topbar)/(backer)/purchases/page 361 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/(topbar)/(backer)/purchases/products/[id]/page 195.19 KB 350.46 KB 100.13% (🟡 +0.02%)
/(main)/(topbar)/(backer)/purchases/subscriptions/[id]/page 216.17 KB 371.44 KB 106.13% (🟡 +4.46%)
/(main)/(topbar)/(backer)/purchases/products/page 90.27 KB 245.54 KB 70.15% (🟡 +0.02%)
/(main)/(topbar)/(backer)/purchases/subscriptions/page 90.19 KB 245.46 KB 70.13% (🟡 +0.03%)
/(main)/(topbar)/(backer)/settings/page 263.56 KB 418.83 KB 119.66% (🟡 +0.02%)
/(main)/[organization]/portal/(topbar)/orders/[id]/page 195.07 KB 350.34 KB 100.10% (🟡 +0.01%)
/(main)/[organization]/portal/(topbar)/authenticate/page 71.88 KB 227.15 KB 64.90% (🟡 +0.02%)
/(main)/[organization]/portal/(topbar)/request/page 67.59 KB 222.86 KB 63.67% (🟡 +0.02%)
/(main)/[organization]/portal/(topbar)/subscriptions/[id]/page 213.8 KB 369.07 KB 105.45% (🟡 +4.48%)
/(main)/dashboard/(create)/create/page 154.15 KB 309.42 KB 88.40% (🟡 +0.02%)
/(main)/dashboard/(create)/layout 362 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/dashboard/[organization]/storefront/page 381 KB 536.27 KB 153.22% (🟡 +1.20%)
/(main)/dashboard/[organization]/layout 45.79 KB 201.06 KB 57.44% (🟡 +0.02%)
/(main)/(landing)/(mdx)/layout 362 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/(landing)/(mdx)/legal/privacy/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/(mdx)/layout 501.01 KB 656.28 KB 187.51% (🟡 +0.07%)
/(main)/docs/(mdx)/customers/purchases/page 33.54 KB 188.81 KB 53.94% (🟡 +0.01%)
/(main)/docs/(mdx)/finance/payouts/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/(mdx)/github/funding-yaml/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/(mdx)/merchant-of-record/compliance/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/(mdx)/onboarding/page 179.62 KB 334.89 KB 95.68% (🟡 +0.01%)
/(main)/docs/(mdx)/payments-taxes/page 33.54 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/(mdx)/subscriptions/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/api/(mdx)/authentication/page 228.21 KB 383.48 KB 109.57% (🟡 +0.01%)
/(main)/docs/api/(mdx)/layout 501 KB 656.27 KB 187.51% (🟡 +0.07%)
/(main)/docs/api/(mdx)/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/developers/(mdx)/layout 501 KB 656.27 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/open-source/layout 501.01 KB 656.28 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/sandbox/layout 501.01 KB 656.28 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/guides/layout 501.01 KB 656.28 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/guides/nextjs/page 34.02 KB 189.29 KB 54.08% (+/- <0.01%)
/(main)/docs/developers/guides/node/page 34.02 KB 189.29 KB 54.08% (+/- <0.01%)
/(main)/docs/developers/sdk/checkout-link/page 34.02 KB 189.29 KB 54.08% (+/- <0.01%)
/(main)/docs/developers/sdk/layout 501 KB 656.27 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/sdk/github-actions/page 34.02 KB 189.29 KB 54.08% (+/- <0.01%)
/(main)/docs/developers/sdk/polar-for-framer/page 33.54 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/developers/sdk/python/page 33.54 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/developers/sdk/page 33.54 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/developers/sdk/typescript/page 33.54 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/support/(mdx)/page 33.53 KB 188.8 KB 53.94% (+/- <0.01%)
/(main)/docs/support/layout 501.01 KB 656.28 KB 187.51% (🟡 +0.07%)
/(main)/docs/developers/webhooks/layout 501.28 KB 656.55 KB 187.58% (🟡 +0.07%)
/(main)/(topbar)/(backer)/(sidebar)/funding/page 251.12 KB 406.39 KB 116.11% (🟡 +0.05%)
/(main)/(topbar)/(backer)/(sidebar)/layout 137.57 KB 292.84 KB 83.67% (🟡 +0.02%)
/(main)/(topbar)/(backer)/finance/account/page 201.66 KB 356.93 KB 101.98% (🟡 +0.02%)
/(main)/(topbar)/(backer)/finance/layout 213.77 KB 369.04 KB 105.44% (🟡 +0.04%)
/(main)/(topbar)/(backer)/finance/outgoing/page 188.09 KB 343.36 KB 98.10% (🟡 +0.02%)
/(main)/(topbar)/(backer)/finance/incoming/page 236.03 KB 391.3 KB 111.80% (🟡 +0.05%)
/(main)/(topbar)/(backer)/finance/rewards/page 115.77 KB 271.04 KB 77.44% (🟡 +0.02%)
/(main)/dashboard/[organization]/(header)/(home)/page 670.51 KB 825.78 KB 235.94% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/layout 571.05 KB 726.32 KB 207.52% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/@breadcrumb/[...all]/page 38.07 KB 193.34 KB 55.24% (+/- <0.01%)
/(main)/dashboard/[organization]/(header)/analytics/page 704.04 KB 859.31 KB 245.52% (🟡 +0.08%)
/(main)/dashboard/[organization]/(header)/benefits/page 671.94 KB 827.21 KB 236.34% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/benefits/license-keys/page 604.91 KB 760.18 KB 217.19% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/customers/page 608.4 KB 763.67 KB 218.19% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/initialize/page 144.08 KB 299.35 KB 85.53% (🟡 +0.02%)
/(main)/dashboard/[organization]/(header)/issues/badge/page 598.04 KB 753.31 KB 215.23% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/issues/embed/page 573.5 KB 728.77 KB 208.22% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/issues/organizations/page 573.42 KB 728.69 KB 208.20% (🟡 +0.08%)
/(main)/dashboard/[organization]/(header)/members/page 571.91 KB 727.18 KB 207.77% (🟡 +0.08%)
/(main)/dashboard/[organization]/(header)/issues/overview/page 613.17 KB 768.44 KB 219.55% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/products/discounts/page 635.38 KB 790.65 KB 225.90% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/products/benefits/page 671.46 KB 826.73 KB 236.21% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/products/new/page 658.95 KB 814.22 KB 232.63% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/products/[id]/page 667.03 KB 822.3 KB 234.94% (🟡 +0.10%)
/(main)/dashboard/[organization]/(header)/@breadcrumb/products/page 362 B 155.62 KB 44.46% (+/- <0.01%)
/(main)/dashboard/[organization]/(header)/products/page 607.55 KB 762.82 KB 217.95% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/sales/[id]/page 584.09 KB 739.36 KB 211.25% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/sales/page 615.6 KB 770.87 KB 220.25% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/sales/subscriptions/page 609.44 KB 764.71 KB 218.49% (🟡 +0.49%)
/(main)/dashboard/[organization]/(header)/settings/page 590.76 KB 746.03 KB 213.15% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/@breadcrumb/settings/layout 38.07 KB 193.34 KB 55.24% (+/- <0.01%)
/(main)/dashboard/[organization]/(header)/settings/webhooks/endpoints/[id]/page 609.64 KB 764.91 KB 218.55% (🟡 +0.08%)
/(main)/dashboard/[organization]/(header)/settings/custom-fields/page 611.16 KB 766.43 KB 218.98% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/settings/webhooks/page 591.66 KB 746.93 KB 213.41% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/finance/incoming/page 184.03 KB 339.3 KB 96.94% (🟡 +0.05%)
/(main)/dashboard/[organization]/(header)/finance/layout 571.05 KB 726.32 KB 207.52% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/finance/account/page 149.43 KB 304.7 KB 87.06% (🟡 +0.01%)
/(main)/dashboard/[organization]/(header)/finance/outgoing/page 136.03 KB 291.3 KB 83.23% (🟡 +0.02%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/contributors/page 63.62 KB 218.89 KB 62.54% (🟡 +0.02%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/layout 571.05 KB 726.32 KB 207.52% (🟡 +0.09%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/page 64.33 KB 219.6 KB 62.74% (🟡 +0.02%)
/(main)/dashboard/[organization]/(header)/finance/issue-funding/rewarded/page 63.62 KB 218.89 KB 62.54% (🟡 +0.02%)
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.

Looks really good! The API for update/cancellation/revokation is really well thought. Just a few nitpick and it'll be good to go 🚀

server/polar/subscription/endpoints.py Outdated Show resolved Hide resolved
server/polar/subscription/endpoints.py Show resolved Hide resolved
server/polar/subscription/service.py Outdated Show resolved Hide resolved
server/polar/subscription/service.py Outdated Show resolved Hide resolved
server/polar/webhook/webhooks.py Show resolved Hide resolved
server/polar/customer_portal/endpoints/subscription.py Outdated Show resolved Hide resolved
server/tests/subscription/test_endpoints.py Outdated Show resolved Hide resolved
server/tests/subscription/test_endpoints.py Outdated Show resolved Hide resolved
@birkjernstrom birkjernstrom force-pushed the feat/cancel-subscription branch from 48bb4da to 2833892 Compare January 3, 2025 13:27
@birkjernstrom birkjernstrom dismissed frankie567’s stale review January 3, 2025 13:28

Completed all feedback. No need to go through again :)

@birkjernstrom birkjernstrom marked this pull request as ready for review January 3, 2025 13:31
@birkjernstrom birkjernstrom merged commit 4bf0212 into main Jan 3, 2025
14 of 15 checks passed
@birkjernstrom birkjernstrom deleted the feat/cancel-subscription branch January 3, 2025 13:38
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.

Subscriptions API: HTTP DELETE /subscriptions/{id}
2 participants