BREAKING CHANGE(booking API schema changes): Merged in feat/SW-1342-booking-api-updates (pull request #1160)
fix: update booking status schema and affected code * fix: update booking api schema and affected code * fix: update meta prop in booking response schema Approved-by: Arvid Norlin
This commit is contained in:
@@ -41,10 +41,14 @@ export default async function PaymentCallbackPage({
|
||||
const bookingStatus = await serverClient().booking.status({
|
||||
confirmationNumber,
|
||||
})
|
||||
|
||||
// TODO: how to handle errors for multiple rooms?
|
||||
const error = bookingStatus.errors.find((e) => e.errorCode)
|
||||
|
||||
searchObject.set(
|
||||
"errorCode",
|
||||
bookingStatus?.metadata?.errorCode
|
||||
? bookingStatus.metadata.errorCode.toString()
|
||||
error
|
||||
? error.errorCode.toString()
|
||||
: PaymentErrorCodeEnum.Failed.toString()
|
||||
)
|
||||
} catch (error) {
|
||||
|
||||
@@ -75,7 +75,7 @@ export default function PaymentClient({
|
||||
(state) => state.actions.setIsSubmittingDisabled
|
||||
)
|
||||
|
||||
const [confirmationNumber, setConfirmationNumber] = useState<string>("")
|
||||
const [bookingNumber, setBookingNumber] = useState<string>("")
|
||||
const [isPollingForBookingStatus, setIsPollingForBookingStatus] =
|
||||
useState(false)
|
||||
|
||||
@@ -105,13 +105,17 @@ export default function PaymentClient({
|
||||
|
||||
const initiateBooking = trpc.booking.create.useMutation({
|
||||
onSuccess: (result) => {
|
||||
if (result?.confirmationNumber) {
|
||||
setConfirmationNumber(result.confirmationNumber)
|
||||
if (result) {
|
||||
setBookingNumber(result.id)
|
||||
|
||||
if (result.metadata?.priceChangedMetadata) {
|
||||
const priceChange = result.rooms.find(
|
||||
(r) => r.priceChangedMetadata
|
||||
)?.priceChangedMetadata
|
||||
|
||||
if (priceChange) {
|
||||
setPriceChangeData({
|
||||
oldPrice: roomPrice.publicPrice,
|
||||
newPrice: result.metadata.priceChangedMetadata.totalPrice,
|
||||
newPrice: priceChange.totalPrice,
|
||||
})
|
||||
} else {
|
||||
setIsPollingForBookingStatus(true)
|
||||
@@ -136,7 +140,7 @@ export default function PaymentClient({
|
||||
|
||||
const priceChange = trpc.booking.priceChange.useMutation({
|
||||
onSuccess: (result) => {
|
||||
if (result?.confirmationNumber) {
|
||||
if (result?.id) {
|
||||
setIsPollingForBookingStatus(true)
|
||||
} else {
|
||||
toast.error(intl.formatMessage({ id: "payment.error.failed" }))
|
||||
@@ -152,7 +156,7 @@ export default function PaymentClient({
|
||||
})
|
||||
|
||||
const bookingStatus = useHandleBookingStatus({
|
||||
confirmationNumber,
|
||||
confirmationNumber: bookingNumber,
|
||||
expectedStatus: BookingStatusEnum.BookingCompleted,
|
||||
maxRetries,
|
||||
retryInterval,
|
||||
@@ -430,7 +434,9 @@ export default function PaymentClient({
|
||||
: ""
|
||||
router.push(`${selectRate(lang)}${allSearchParams}`)
|
||||
}}
|
||||
onAccept={() => priceChange.mutate({ confirmationNumber })}
|
||||
onAccept={() =>
|
||||
priceChange.mutate({ confirmationNumber: bookingNumber })
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
|
||||
@@ -11,23 +11,36 @@ export const createBookingSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
confirmationNumber: z.string(),
|
||||
cancellationNumber: z.string().nullable(),
|
||||
reservationStatus: z.string(),
|
||||
paymentUrl: z.string().nullable(),
|
||||
metadata: z
|
||||
.object({
|
||||
errorCode: z.number().nullable().optional(),
|
||||
errorMessage: z.string().nullable().optional(),
|
||||
priceChangedMetadata: z
|
||||
.object({
|
||||
roomPrice: z.number(),
|
||||
totalPrice: z.number(),
|
||||
})
|
||||
.nullable()
|
||||
.optional(),
|
||||
})
|
||||
.nullable(),
|
||||
rooms: z
|
||||
.array(
|
||||
z.object({
|
||||
confirmationNumber: z.string(),
|
||||
cancellationNumber: z.string().nullable(),
|
||||
priceChangedMetadata: z
|
||||
.object({
|
||||
roomPrice: z.number(),
|
||||
totalPrice: z.number(),
|
||||
})
|
||||
.nullable()
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
.default([]),
|
||||
errors: z
|
||||
.array(
|
||||
z.object({
|
||||
confirmationNumber: z.string(),
|
||||
errorCode: z.string(),
|
||||
description: z.string(),
|
||||
meta: z
|
||||
.record(z.string(), z.union([z.string(), z.number()]))
|
||||
.nullable()
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
.default([]),
|
||||
}),
|
||||
type: z.string(),
|
||||
id: z.string(),
|
||||
@@ -45,11 +58,10 @@ export const createBookingSchema = z
|
||||
id: d.data.id,
|
||||
links: d.data.links,
|
||||
type: d.data.type,
|
||||
confirmationNumber: d.data.attributes.confirmationNumber,
|
||||
cancellationNumber: d.data.attributes.cancellationNumber,
|
||||
reservationStatus: d.data.attributes.reservationStatus,
|
||||
paymentUrl: d.data.attributes.paymentUrl,
|
||||
metadata: d.data.attributes.metadata,
|
||||
rooms: d.data.attributes.rooms,
|
||||
errors: d.data.attributes.errors,
|
||||
}))
|
||||
|
||||
// QUERY
|
||||
|
||||
Reference in New Issue
Block a user