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:
Anton Gunnarsson
2025-12-11 13:23:12 +00:00
parent eb90c382b8
commit 7faa9933a2
19 changed files with 489 additions and 110 deletions

View File

@@ -1,6 +1,12 @@
import { PaymentMethodEnum } from "@scandic-hotels/common/constants/paymentMethod"
import { logger } from "@scandic-hotels/common/logger"
import { env } from "../../../../env/client"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { CreditCard } from "@scandic-hotels/trpc/types/user"
import type { RedemptionType } from "../../../bookingFlowConfig/bookingFlowConfig"
import type { RoomState } from "../../../stores/enter-details/types"
export function isPaymentMethodEnum(value: string): value is PaymentMethodEnum {
@@ -123,3 +129,84 @@ export function mustGuaranteeBooking({
return room.mustBeGuaranteed
})
}
function createPaymentCallbackUrl(lang: Lang) {
return `${env.NEXT_PUBLIC_NODE_ENV === "development" ? `http://localhost:${env.NEXT_PUBLIC_PORT}` : ""}/${lang}/hotelreservation/payment-callback`
}
export function getPaymentData({
guarantee,
bookingMustBeGuaranteed,
hasOnlyFlexRates,
paymentMethod,
isRedemptionBooking,
savedCreditCard,
lang,
}: {
guarantee: boolean
bookingMustBeGuaranteed: boolean
hasOnlyFlexRates: boolean
paymentMethod: PaymentMethodEnum
isRedemptionBooking: boolean
savedCreditCard?: CreditCard
lang: Lang
}) {
const paymentRedirectUrl = createPaymentCallbackUrl(lang)
const redirectUrls = {
success: `${paymentRedirectUrl}/success`,
error: `${paymentRedirectUrl}/error`,
cancel: `${paymentRedirectUrl}/cancel`,
}
if (
isRedemptionBooking &&
paymentMethod === PaymentMethodEnum.PartnerPoints
) {
return {
paymentMethod: paymentMethod,
...redirectUrls,
}
}
const shouldUsePayment =
guarantee || bookingMustBeGuaranteed || !hasOnlyFlexRates
if (!shouldUsePayment) {
return null
}
return {
paymentMethod: paymentMethod,
...redirectUrls,
card: savedCreditCard
? {
alias: savedCreditCard.alias,
expiryDate: savedCreditCard.expirationDate,
cardType: savedCreditCard.cardType,
}
: undefined,
}
}
export const getPaymentMethod = ({
paymentMethod,
hasFlexRates,
isRedemptionBooking,
redemptionType,
}: {
paymentMethod: string | null | undefined
hasFlexRates: boolean
isRedemptionBooking: boolean
redemptionType: RedemptionType
}): PaymentMethodEnum => {
if (isRedemptionBooking && redemptionType === "partner") {
return PaymentMethodEnum.PartnerPoints
}
if (hasFlexRates) {
return PaymentMethodEnum.card
}
return paymentMethod && isPaymentMethodEnum(paymentMethod)
? paymentMethod
: PaymentMethodEnum.card
}