Merged in feat/sw-1948-point-transfer-endpoint (pull request #2353)
feat(SW-1948):Add SAS point transfer endpoint * Add SAS point transfer endpoint Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -123,6 +123,7 @@ export async function GET(
|
|||||||
"booking",
|
"booking",
|
||||||
"profile_link",
|
"profile_link",
|
||||||
"profile_matchtier",
|
"profile_matchtier",
|
||||||
|
"profile_point_transfer",
|
||||||
"availability",
|
"availability",
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export async function GET(
|
|||||||
"availability",
|
"availability",
|
||||||
"profile_link",
|
"profile_link",
|
||||||
"profile_matchtier",
|
"profile_matchtier",
|
||||||
|
"profile_point_transfer",
|
||||||
].join(" "),
|
].join(" "),
|
||||||
loginKey: loginKey,
|
loginKey: loginKey,
|
||||||
for_origin: publicURL,
|
for_origin: publicURL,
|
||||||
|
|||||||
@@ -262,15 +262,22 @@ async function handleTransferPoints({
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!res || error) {
|
if (!res || error || res.transferState === "error") {
|
||||||
console.error("[SAS] transfer points error", error)
|
console.error("[SAS] transfer points error", error)
|
||||||
return {
|
return {
|
||||||
// TODO better errors?
|
|
||||||
url: `/${lang}/sas-x-scandic/error`,
|
url: `/${lang}/sas-x-scandic/error`,
|
||||||
type: "replace",
|
type: "replace",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res.transferState === "notLinked") {
|
||||||
|
console.warn("[SAS] transfer points not linked")
|
||||||
|
return {
|
||||||
|
url: `/${lang}/sas-x-scandic/link`,
|
||||||
|
type: "replace",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log("[SAS] transfer points response", res)
|
console.log("[SAS] transfer points response", res)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ import styles from "./transferSuccess.module.css"
|
|||||||
import type { LangParams, PageArgs, SearchParams } from "@/types/params"
|
import type { LangParams, PageArgs, SearchParams } from "@/types/params"
|
||||||
import type { Lang } from "@/constants/languages"
|
import type { Lang } from "@/constants/languages"
|
||||||
|
|
||||||
export default async function SASxScandicTransferSuccessPage(props: PageArgs<LangParams> & SearchParams<{ p?: string }>) {
|
export default async function SASxScandicTransferSuccessPage(
|
||||||
const searchParams = await props.searchParams;
|
props: PageArgs<LangParams> & SearchParams<{ p?: string }>
|
||||||
const params = await props.params;
|
) {
|
||||||
|
const searchParams = await props.searchParams
|
||||||
|
const params = await props.params
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
const { lang } = params
|
const { lang } = params
|
||||||
const addedPoints = Number(searchParams.p) || 0
|
const addedPoints = Number(searchParams.p) || 0
|
||||||
@@ -75,7 +77,6 @@ async function TransactionCard({
|
|||||||
const profile = await getProfileSafely()
|
const profile = await getProfileSafely()
|
||||||
const transferredPoints = intl.formatNumber(addedPoints)
|
const transferredPoints = intl.formatNumber(addedPoints)
|
||||||
|
|
||||||
// TODO is this updated immediately?
|
|
||||||
const totalPoints = profile?.membership?.currentPoints ?? 0
|
const totalPoints = profile?.membership?.currentPoints ?? 0
|
||||||
|
|
||||||
const showBonusNight = totalPoints > 10_000
|
const showBonusNight = totalPoints > 10_000
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ export namespace endpoints {
|
|||||||
export const link = `${base.path.profile}/${version}/${base.enitity.Profile}/link`
|
export const link = `${base.path.profile}/${version}/${base.enitity.Profile}/link`
|
||||||
export const unlink = `${base.path.profile}/${version}/${base.enitity.Profile}/Unlink`
|
export const unlink = `${base.path.profile}/${version}/${base.enitity.Profile}/Unlink`
|
||||||
export const matchTier = `${base.path.profile}/${version}/${base.enitity.Profile}/MatchTier`
|
export const matchTier = `${base.path.profile}/${version}/${base.enitity.Profile}/MatchTier`
|
||||||
|
export const pointTransfer = `${base.path.profile}/${version}/${base.enitity.Profile}/PointTransfer/Partner`
|
||||||
|
|
||||||
export function deleteProfile(profileId: string) {
|
export function deleteProfile(profileId: string) {
|
||||||
return `${profile}/${profileId}`
|
return `${profile}/${profileId}`
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
|
import * as Sentry from "@sentry/nextjs"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
// import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
import { protectedProcedure } from "@/server/trpc"
|
import { protectedProcedure } from "@/server/trpc"
|
||||||
|
|
||||||
|
import { getOTPState } from "./otp/getOTPState"
|
||||||
import { getSasToken } from "./getSasToken"
|
import { getSasToken } from "./getSasToken"
|
||||||
|
|
||||||
const outputSchema = z.object({
|
const outputSchema = z.object({
|
||||||
transferState: z.enum(["success"]),
|
transferState: z.enum(["success", "notLinked", "error"]),
|
||||||
})
|
})
|
||||||
|
|
||||||
const transferPointsInputSchema = z.object({
|
const transferPointsInputSchema = z.object({
|
||||||
@@ -18,24 +20,53 @@ export const transferPoints = protectedProcedure
|
|||||||
.input(transferPointsInputSchema)
|
.input(transferPointsInputSchema)
|
||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
const sasAuthToken = await getSasToken()
|
const sasAuthToken = await getSasToken()
|
||||||
|
const { referenceId } = await getOTPState()
|
||||||
|
|
||||||
console.log("[SAS] transfer points")
|
const apiResponse = await api.post(api.endpoints.v1.Profile.pointTransfer, {
|
||||||
console.log({ sasAuthToken })
|
headers: {
|
||||||
console.log({ points: input.points })
|
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
partner: "sas_eb",
|
||||||
|
partnerPoints: input.points,
|
||||||
|
partnerSpecific: {
|
||||||
|
eurobonusAccessToken: sasAuthToken,
|
||||||
|
eurobonusOtpReferenceId: referenceId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
// const apiResponse = await api.post(api.endpoints.v1.Profile.link, {
|
if (apiResponse.status === 204) {
|
||||||
// headers: {
|
return { transferState: "success" }
|
||||||
// Authorization: `Bearer ${ctx.session.token.access_token}`,
|
}
|
||||||
// },
|
if (apiResponse.status === 400) {
|
||||||
// body: {
|
const result = await apiResponse.json()
|
||||||
// partner: "sas_eb",
|
const data = badRequestSchema.safeParse(result)
|
||||||
// tocDate: getCurrentDateWithoutTime(),
|
if (!data.success) {
|
||||||
// partnerSpecific: {
|
const transferPointsBadRequestSchemaError = `[SAS] failed to parse transfer points bad request schema ${JSON.stringify(data.error)}`
|
||||||
// eurobonusAccessToken: sasAuthToken,
|
console.error(transferPointsBadRequestSchemaError)
|
||||||
// },
|
Sentry.captureMessage(transferPointsBadRequestSchemaError)
|
||||||
// },
|
return { transferState: "error" }
|
||||||
// })
|
}
|
||||||
|
}
|
||||||
|
if (apiResponse.status === 404) {
|
||||||
|
const transferPointsNotFoundError = `[SAS] transfer points failed, no active partner link`
|
||||||
|
console.error(transferPointsNotFoundError)
|
||||||
|
Sentry.captureMessage(transferPointsNotFoundError)
|
||||||
|
return { transferState: "notLinked" }
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`[SAS] transfer points success`)
|
const errorMessage = `[SAS] transfer points error with status code ${apiResponse.status} and response ${await apiResponse.text()}`
|
||||||
return { transferState: "success" }
|
console.warn(errorMessage)
|
||||||
|
Sentry.captureMessage(errorMessage)
|
||||||
|
return { transferState: "error" }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const badRequestSchema = z.object({
|
||||||
|
errors: z.array(
|
||||||
|
z.object({
|
||||||
|
code: z.string(),
|
||||||
|
details: z.string().optional(),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user