|
@@ -29,6 +29,28 @@ export class PaymentService {
|
|
|
private userService: UserService
|
|
private userService: UserService
|
|
|
private teamService: TeamService
|
|
private teamService: TeamService
|
|
|
|
|
|
|
|
|
|
+ private static readonly ORDER_TYPE_TO_VIP_LEVEL_MAP: Record<OrderType, VipLevel> = {
|
|
|
|
|
+ [OrderType.SINGLE_TIP]: VipLevel.FREE,
|
|
|
|
|
+ [OrderType.HOURLY]: VipLevel.HOURLY,
|
|
|
|
|
+ [OrderType.DAILY]: VipLevel.DAILY,
|
|
|
|
|
+ [OrderType.WEEKLY]: VipLevel.WEEKLY,
|
|
|
|
|
+ [OrderType.MONTHLY]: VipLevel.MONTHLY,
|
|
|
|
|
+ [OrderType.QUARTERLY]: VipLevel.QUARTERLY,
|
|
|
|
|
+ [OrderType.YEARLY]: VipLevel.YEARLY,
|
|
|
|
|
+ [OrderType.LIFETIME]: VipLevel.LIFETIME
|
|
|
|
|
+ } as const
|
|
|
|
|
+
|
|
|
|
|
+ private static readonly STRING_TO_ORDER_TYPE_MAP: Record<string, OrderType> = {
|
|
|
|
|
+ single: OrderType.SINGLE_TIP,
|
|
|
|
|
+ hourly: OrderType.HOURLY,
|
|
|
|
|
+ daily: OrderType.DAILY,
|
|
|
|
|
+ weekly: OrderType.WEEKLY,
|
|
|
|
|
+ monthly: OrderType.MONTHLY,
|
|
|
|
|
+ quarterly: OrderType.QUARTERLY,
|
|
|
|
|
+ yearly: OrderType.YEARLY,
|
|
|
|
|
+ lifetime: OrderType.LIFETIME
|
|
|
|
|
+ } as const
|
|
|
|
|
+
|
|
|
constructor(app: FastifyInstance) {
|
|
constructor(app: FastifyInstance) {
|
|
|
this.app = app
|
|
this.app = app
|
|
|
this.url = app.config.PAYMENT_URL
|
|
this.url = app.config.PAYMENT_URL
|
|
@@ -254,32 +276,16 @@ export class PaymentService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private getVipLevelByOrderType(orderType: OrderType): VipLevel {
|
|
private getVipLevelByOrderType(orderType: OrderType): VipLevel {
|
|
|
- const orderTypeMap: Record<OrderType, VipLevel> = {
|
|
|
|
|
- [OrderType.SINGLE_TIP]: VipLevel.FREE,
|
|
|
|
|
- [OrderType.HOURLY_MEMBER]: VipLevel.HOURLY,
|
|
|
|
|
- [OrderType.DAILY_MEMBER]: VipLevel.DAILY,
|
|
|
|
|
- [OrderType.WEEKLY_MEMBER]: VipLevel.WEEKLY,
|
|
|
|
|
- [OrderType.MONTHLY_MEMBER]: VipLevel.MONTHLY,
|
|
|
|
|
- [OrderType.QUARTERLY_MEMBER]: VipLevel.QUARTERLY,
|
|
|
|
|
- [OrderType.YEARLY_MEMBER]: VipLevel.YEARLY,
|
|
|
|
|
- [OrderType.LIFETIME_MEMBER]: VipLevel.LIFETIME
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return orderTypeMap[orderType] || VipLevel.FREE
|
|
|
|
|
|
|
+ return PaymentService.ORDER_TYPE_TO_VIP_LEVEL_MAP[orderType] ?? VipLevel.FREE
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private getOrderTypeByType(type: string): OrderType {
|
|
private getOrderTypeByType(type: string): OrderType {
|
|
|
- const orderTypeMap: Record<string, OrderType> = {
|
|
|
|
|
- single: OrderType.SINGLE_TIP,
|
|
|
|
|
- hourly: OrderType.HOURLY_MEMBER,
|
|
|
|
|
- daily: OrderType.DAILY_MEMBER,
|
|
|
|
|
- weekly: OrderType.WEEKLY_MEMBER,
|
|
|
|
|
- monthly: OrderType.MONTHLY_MEMBER,
|
|
|
|
|
- quarterly: OrderType.QUARTERLY_MEMBER,
|
|
|
|
|
- yearly: OrderType.YEARLY_MEMBER,
|
|
|
|
|
- lifetime: OrderType.LIFETIME_MEMBER
|
|
|
|
|
|
|
+ if (!type || typeof type !== 'string') {
|
|
|
|
|
+ this.app.log.warn(`Invalid type parameter: ${type}, using default SINGLE_TIP`)
|
|
|
|
|
+ return OrderType.SINGLE_TIP
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return orderTypeMap[type] || OrderType.SINGLE_TIP
|
|
|
|
|
|
|
+ const normalizedType = type.toLowerCase().trim()
|
|
|
|
|
+ return PaymentService.STRING_TO_ORDER_TYPE_MAP[normalizedType] ?? OrderType.SINGLE_TIP
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|