Merged in feat/sw-3642-inject-sas-eb-payment (pull request #3243)
feat(SW-3642): Enable SAS EB payments * Wip add SAS eb payment * Add validate payment call * Check booking status payment method to determine validation * Clean up getPaymentData * Fix PartnerPoints casing * Add comment for validatePartnerPayment error handling * Remove comment Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import "server-only"
|
||||
|
||||
import z from "zod"
|
||||
|
||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
|
||||
import * as api from "../../../api"
|
||||
import { serverErrorByStatus } from "../../../errors"
|
||||
import { safeProtectedServiceProcedure } from "../../../procedures"
|
||||
import { toApiLang } from "../../../utils"
|
||||
|
||||
const validatePartnerPaymentInput = z.object({
|
||||
confirmationNumber: z.string(),
|
||||
})
|
||||
|
||||
export const validatePartnerPayment = safeProtectedServiceProcedure
|
||||
.input(validatePartnerPaymentInput)
|
||||
.use(async ({ ctx, next }) => {
|
||||
const token = await ctx.getScandicUserToken()
|
||||
|
||||
return next({
|
||||
ctx: {
|
||||
token,
|
||||
},
|
||||
})
|
||||
})
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
const { confirmationNumber } = input
|
||||
const getValidateBooking = createCounter("booking.validate")
|
||||
const metricsValidateBooking = getValidateBooking.init({
|
||||
confirmationNumber,
|
||||
})
|
||||
|
||||
metricsValidateBooking.start()
|
||||
|
||||
const apiResponse = await api.put(
|
||||
api.endpoints.v1.Booking.validatePartnerPayment(confirmationNumber),
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.token ?? ctx.serviceToken}`,
|
||||
},
|
||||
},
|
||||
{ language: toApiLang(ctx.lang) }
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
await metricsValidateBooking.httpError(apiResponse)
|
||||
|
||||
// If the booking is not found, return null.
|
||||
if (apiResponse.status === 404) {
|
||||
return null
|
||||
}
|
||||
|
||||
throw serverErrorByStatus(apiResponse.status, apiResponse)
|
||||
}
|
||||
|
||||
metricsValidateBooking.success()
|
||||
|
||||
return null
|
||||
})
|
||||
Reference in New Issue
Block a user