Skip to content

feat(payments): admin Polar refunds with fee-adjusted policy, admin e… - #236

Open
asifrazadev wants to merge 9 commits into
mainfrom
polar-refunds
Open

asifrazadev wants to merge 9 commits into
mainfrom
polar-refunds

Conversation

@asifrazadev

Copy link
Copy Markdown
Collaborator

Summary

Adds admin refunds for courses bought through Polar, a new admin enrollments page, and free access for instructors to their own courses.

Polar refunds

  • Refund policy (services/payments/refund-policy.ts): a refund returns the amount paid minus Polar's fees: $0.50 transaction fee, 1.5% international fee and 5% Polar fee. Edorax adds no fee of its own. The admin refund, the webhook and the UI all read these numbers from this one file.
  • Admin refund (refund-course-payment.ts): an admin can preview and then issue a refund from the user detail page. The confirm dialog shows every amount. Access ends immediately. It is recorded in the admin audit log.
  • order.refunded webhook (refund-polar-order.ts, routes/webhook/polar.ts):
    • A refund at or above the policy amount ends access: the enrollment becomes CANCELLED/DROPPED and the payment REFUNDED.
    • A smaller refund counts as goodwill, and access stays.
    • It is idempotent with the admin refund and with Polar's retries, so only the first call changes anything.
    • An instructor payout that hasn't been paid yet is no longer owed. One that was already paid is logged so it can be adjusted manually.

Admin enrollments page

  • New /admin/enrollments list and /admin/enrollments/[id] detail page. They show what each learner was charged, the coupons or campaigns applied, and the payment status.
  • Admins can edit course access (lifecycle) and payment status, or delete an enrollment. Edits change only our records; no money moves through Polar.
  • Admin enrollments and admin course previews are labelled using a payment row with provider admin.
  • Added to the admin sidebar navigation.

Instructors get their own courses free

  • New own-course.ts. A course's instructor is never asked to pay; this applies to the catalog, overview, checkout, self-enroll and learn entry points.
  • An earlier enrollment that was left awaitiof creating a duplicate.

Tests

  • Unit tests: refund-policy, refund-course-payment, refund-polar-order, own-course.
  • Updated tests: polar-webhook-route, `admtests.

Not included

  • The one-off backfill for older admin and self enrollments (scripts/backfill-admin-enrollments.ts) will ship
    separately.

Test plan

  • pnpm test and pnpm typecheck in server/
  • Refund a Polar test-mode order from tht the amounts match the confirm dialog andthat access ends.
  • Replay order.refunded and check thate.
  • Open your own paid course as its instructor. There should be no checkout, and you should get straight in.
  • On /admin/enrollments, filter, edit d delete an enrollment.

…nrollments page, and free access for course instructors
@asifrazadev
asifrazadev marked this pull request as draft November 14, 2026 09:32
# Conflicts:
#	frontend/src/components/admin/admin-workspace-shell.tsx
#	server/src/services/admin/audit.ts
#	server/src/validations/admin.ts

@AQIB-NAWAB AQIB-NAWAB left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we needs dynamic

@asifrazadev

Copy link
Copy Markdown
Collaborator Author

I've made a few updates. I still need to test the refund functionality before marking it as ready for merge. Everything else has been confirmed to be working as intended.

@asifrazadev

Copy link
Copy Markdown
Collaborator Author

The admin enrollment page now lets admins preview refund options and issue full, standard, or custom refunds. The server validates the selected mode and amount, records the decision in the audit log, and revokes course access by default when a refund is issued. The shared admin API types were also synced to the frontend.

cc @AQIB-NAWAB

@asifrazadev
asifrazadev marked this pull request as ready for review November 18, 2026 07:56
@asifrazadev
asifrazadev added this pull request to stack #250 November 18, 2026 14:57

This branch has not been deployed

No deployments
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