refund roadmap pr-1 and pr-2
This commit is contained in:
@@ -5,6 +5,7 @@ import { authOptions } from "@/lib/auth";
|
||||
import { tripService } from "@/server/services/trip.service";
|
||||
import { paymentService } from "@/server/services/payment.service";
|
||||
import { bookingService } from "@/server/services/booking.service";
|
||||
import { refundService } from "@/server/services/refund.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export async function markParticipantPaidAction(tripId: string) {
|
||||
@@ -94,3 +95,45 @@ export async function confirmParticipantPaymentAction(
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Peserta cancel booking PAID dengan refund request. Server menghitung
|
||||
* nominal refund pakai policy default (lib/refund-policy.ts) — client
|
||||
* cuma kirim bookingId untuk cegah tampering.
|
||||
*/
|
||||
export async function cancelBookingWithRefundAction(tripId: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) {
|
||||
return { error: "Kamu harus login terlebih dahulu" };
|
||||
}
|
||||
|
||||
try {
|
||||
const booking = await bookingService.getByTripAndUser(
|
||||
tripId,
|
||||
session.user.id
|
||||
);
|
||||
if (!booking) {
|
||||
return { error: "Kamu tidak terdaftar di trip ini" };
|
||||
}
|
||||
|
||||
const result = await refundService.requestUserCancellation({
|
||||
bookingId: booking.id,
|
||||
userId: session.user.id,
|
||||
});
|
||||
|
||||
revalidatePath(`/trips/${tripId}`);
|
||||
revalidatePath("/trips");
|
||||
revalidatePath("/");
|
||||
revalidatePath("/profile");
|
||||
revalidatePath("/admin/refunds");
|
||||
|
||||
return {
|
||||
success: true as const,
|
||||
kind: result.kind,
|
||||
refundAmount: result.refundAmount,
|
||||
days: result.days,
|
||||
};
|
||||
} catch (err) {
|
||||
return { error: (err as Error).message };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user