-
Notifications
You must be signed in to change notification settings - Fork 501
show transaction refunds in table #1013
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "Subscription" ADD COLUMN "refundedAt" TIMESTAMP(3); | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { useAdminApp } from '@/app/(main)/(protected)/projects/[projectId]/use-a | |||||
| import type { Transaction, TransactionEntry, TransactionType } from '@stackframe/stack-shared/dist/interface/crud/transactions'; | ||||||
| import { TRANSACTION_TYPES } from '@stackframe/stack-shared/dist/interface/crud/transactions'; | ||||||
| import { deepPlainEquals } from '@stackframe/stack-shared/dist/utils/objects'; | ||||||
| import { ActionCell, ActionDialog, AvatarCell, DataTableColumnHeader, DataTableManualPagination, DateCell, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, TextCell, Tooltip, TooltipContent, TooltipTrigger } from '@stackframe/stack-ui'; | ||||||
| import { ActionCell, ActionDialog, AvatarCell, Badge, DataTableColumnHeader, DataTableManualPagination, DateCell, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, TextCell, Tooltip, TooltipContent, TooltipTrigger } from '@stackframe/stack-ui'; | ||||||
| import type { ColumnDef, ColumnFiltersState, SortingState } from '@tanstack/react-table'; | ||||||
| import type { LucideIcon } from 'lucide-react'; | ||||||
| import { Ban, CircleHelp, RefreshCcw, RotateCcw, Settings, ShoppingCart, Shuffle } from 'lucide-react'; | ||||||
|
|
@@ -26,6 +26,7 @@ type TransactionSummary = { | |||||
| detail: string, | ||||||
| amountDisplay: string, | ||||||
| refundTarget: RefundTarget | null, | ||||||
| refunded: boolean, | ||||||
| }; | ||||||
|
|
||||||
| type EntryWithCustomer = Extract<TransactionEntry, { customer_type: string, customer_id: string }>; | ||||||
|
|
@@ -173,6 +174,7 @@ function getTransactionSummary(transaction: Transaction): TransactionSummary { | |||||
| const customerEntry = transaction.entries.find(isEntryWithCustomer); | ||||||
| const moneyTransferEntry = transaction.entries.find(isMoneyTransferEntry); | ||||||
| const refundTarget = getRefundTarget(transaction); | ||||||
| const refunded = transaction.adjusted_by.length > 0; | ||||||
|
|
||||||
| return { | ||||||
| sourceType, | ||||||
|
|
@@ -182,14 +184,17 @@ function getTransactionSummary(transaction: Transaction): TransactionSummary { | |||||
| detail: describeDetail(transaction, sourceType), | ||||||
| amountDisplay: transaction.test_mode ? 'Test mode' : pickChargedAmountDisplay(moneyTransferEntry), | ||||||
| refundTarget, | ||||||
| refunded, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| function RefundActionCell({ transaction, refundTarget }: { transaction: Transaction, refundTarget: RefundTarget | null }) { | ||||||
| const app = useAdminApp(); | ||||||
| const [isDialogOpen, setIsDialogOpen] = React.useState(false); | ||||||
| const target = transaction.type === 'purchase' ? refundTarget : null; | ||||||
| const canRefund = !!target && !transaction.test_mode; | ||||||
| const alreadyRefunded = transaction.adjusted_by.length > 0; | ||||||
| const productEntry = transaction.entries.find(isProductGrantEntry); | ||||||
| const canRefund = !!target && !transaction.test_mode && !alreadyRefunded && productEntry?.price_id; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The refund button is now disabled for transactions with View DetailsAnalysisFrontend prevents refunding server-granted subscriptions with null price_idWhat fails: RefundActionCell.canRefund() in transaction-table.tsx checks How to reproduce:
Result: Refund button disabled in UI, users cannot attempt refunds Expected: Refund button should be enabled, allowing users to attempt refunds (backend will handle validation and return appropriate errors for non-refundable items) Technical details: Server-granted subscriptions use |
||||||
|
|
||||||
| return ( | ||||||
| <> | ||||||
|
|
@@ -217,6 +222,7 @@ function RefundActionCell({ transaction, refundTarget }: { transaction: Transact | |||||
| item: "Refund", | ||||||
| danger: true, | ||||||
| disabled: !canRefund, | ||||||
| disabledTooltip: "This transaction cannot be refunded", | ||||||
| onClick: () => { | ||||||
| if (!target) return; | ||||||
| setIsDialogOpen(true); | ||||||
|
|
@@ -307,9 +313,18 @@ export function TransactionTable() { | |||||
| header: ({ column }) => <DataTableColumnHeader column={column} columnTitle="Details" />, | ||||||
| cell: ({ row }) => { | ||||||
| const summary = summaryById.get(row.original.id); | ||||||
| return <TextCell> | ||||||
| {summary?.detail ?? '—'} | ||||||
| </TextCell>; | ||||||
| return ( | ||||||
| <TextCell size={120}> | ||||||
| <div className="flex items-center gap-2"> | ||||||
| <span className="truncate">{summary?.detail ?? '—'}</span> | ||||||
| {summary?.refunded ? ( | ||||||
| <Badge variant="outline" className="text-xs"> | ||||||
| Refunded | ||||||
| </Badge> | ||||||
| ) : null} | ||||||
| </div> | ||||||
| </TextCell> | ||||||
| ); | ||||||
| }, | ||||||
| enableSorting: false, | ||||||
| }, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: the initial query only selects
refundedAt, but subscriptions also have acreationSourcefield that needs checking (subscriptions can be TEST_MODE like one-time purchases)Prompt To Fix With AI