feat: add refund reason handling to transaction updates and details#357
feat: add refund reason handling to transaction updates and details#357Dprof-in-tech wants to merge 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughThe changes implement refund reason tracking and display throughout the application. A new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/components/transaction/TransactionList.tsx (1)
306-324:⚠️ Potential issue | 🟡 MinorInconsistent refund reason display between
TransactionListItemand inline list rendering.The
TransactionListItemcomponent (lines 80-105) now displays the refund reason for refunded transactions, but the inline transaction rendering in the main list (this section) does not include this feature. This creates an inconsistent user experience depending on which code path renders the transaction.Consider adding the refund reason display here as well, or extracting the shared rendering logic to use
TransactionListItemconsistently.🔧 Proposed fix to add refund reason display
<div className="flex items-center gap-x-2"> <span className="text-text-disabled dark:text-white/30"> {new Date( transaction.created_at, ).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", })} </span> <span className="size-1 bg-icon-outline-disabled dark:bg-white/5"></span> <span className={classNames( STATUS_COLOR_MAP[transaction.status] || "text-text-secondary dark:text-white/50", )} > {transaction.status} </span> </div> + {transaction.status === "refunded" && + transaction.refund_reason && + transaction.refund_reason.trim() !== "" && ( + <span className="text-xs text-text-secondary dark:text-white/50 line-clamp-1"> + {transaction.refund_reason} + </span> + )} </div>
🧹 Nitpick comments (3)
app/api/aggregator.ts (1)
447-458: Consider updating the JSDoc to document the newrefundReasonparameter.The function signature now accepts
refundReason, but it's not documented in the JSDoc block above.📝 Proposed JSDoc update
/** * Updates the details of a transaction including status, hash, and time spent * `@param` {Object} params - The parameters object * `@param` {string} params.transactionId - The ID of the transaction to update * `@param` {string} params.status - The new status to set * `@param` {string} [params.txHash] - The transaction hash (optional) * `@param` {string} [params.timeSpent] - The time spent on the transaction (optional) + * `@param` {string} [params.refundReason] - The reason for refund when status is refunded (optional) * `@param` {string} params.accessToken - The access token for authentication * `@param` {string} params.walletAddress - The wallet address for authorization * `@returns` {Promise<SaveTransactionResponse>} The update response * `@throws` {Error} If the API request fails */app/pages/TransactionStatus.tsx (1)
372-380: Inconsistent handling: uses first reason only, whilesaveTransactionDatajoins all reasons.This uses only the first cancellation reason for analytics, whereas
saveTransactionData(lines 225-228) joins all reasons. While this may be intentional (keeping analytics concise), consider aligning the approach or adding a comment explaining the difference.Option: Use consistent handling or document the difference
If intentional, add a clarifying comment:
} else if (transactionStatus === "refunded") { + // Use first reason for concise analytics tracking (full list stored in DB) const reason = orderDetails?.cancellationReasons?.length && orderDetails.cancellationReasons[0] ? orderDetails.cancellationReasons[0] : "Transaction failed and refunded";app/context/TransactionsContext.tsx (1)
139-153: Good change detection logic; minor redundancy on line 150.The
refundReasonChangedcheck correctly prevents unnecessary backend calls when the reason hasn't changed.Line 150:
refundReason ?? undefinedis redundant sincerefundReasonis already typed asstring | undefined.Simplify null coalescing
await updateTransactionDetails({ transactionId: tx.id, status: orderData.status, txHash: newTxHash, - refundReason: refundReason ?? undefined, + refundReason, accessToken, walletAddress, });
Description
This pull request adds support for tracking and displaying the reason for refunded transactions throughout the application. It introduces a new
refund_reasonfield to thetransactionstable, updates backend and frontend logic to handle this field, and ensures the refund reason is shown to users when relevant.Database and API updates:
refund_reasoncolumn to thetransactionstable to store the reason for refunds, and updated Supabase queries and API payloads to include this field when a transaction is refunded. [1] app/api/v1/transactions/[id]/route.tsL67-R79, [2] F239bae5L322R322, F239bae5L339R339, F239bae5L385R385, [3] [4]Backend logic enhancements:
refund_reasonwhen present, ensuring the backend accurately reflects the reason for refunds. (app/api/v1/transactions/[id]/route.tsL42-R42, app/api/v1/transactions/[id]/route.tsL67-R79, [1] [2] [3] [4]Frontend UI improvements:
Type and data structure updates:
refundReasonand related fields, ensuring type safety across the application. [1] [2] [3] [4]User experience enhancements:
References
closes #356
Testing
Checklist
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.
Summary by CodeRabbit
Release Notes