Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/storefront/lib/ai/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ export function createTools(customerId: string, _conversationId?: string) {
}

const payment = await db.selectPayment(orderId);
if (!payment) {
return {
refunded: false as const,
reason: `No payment record found for order ${orderId}`,
};
}
const refund = await issueRefund({
chargeId: payment.chargeId,
amount: order.total.amount,
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/lib/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ export async function selectOrder(
}

// Orders placed before the payments launch have no payment row.
export async function selectPayment(orderId: string): Promise<Payment> {
export async function selectPayment(orderId: string): Promise<Payment | undefined> {
const [row] = await db
.select()
.from(payments)
.where(eq(payments.orderId, orderId))
.limit(1);

return row as Payment;
return row;
}

export async function selectOrders(
Expand Down
Loading