2022-06-07 08:49:12 +02:00
|
|
|
import { z } from 'zod'
|
2023-03-09 08:46:36 +01:00
|
|
|
import {
|
|
|
|
optionBaseSchema,
|
|
|
|
blockBaseSchema,
|
|
|
|
credentialsBaseSchema,
|
2023-11-08 15:34:16 +01:00
|
|
|
} from '../../shared'
|
|
|
|
import { PaymentProvider } from './constants'
|
|
|
|
import { InputBlockType } from '../constants'
|
2022-06-07 08:49:12 +02:00
|
|
|
|
|
|
|
export type CreditCardDetails = {
|
|
|
|
number: string
|
|
|
|
exp_month: string
|
|
|
|
exp_year: string
|
|
|
|
cvc: string
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:54:37 -04:00
|
|
|
const addressSchema = z.object({
|
|
|
|
country: z.string().optional(),
|
|
|
|
line1: z.string().optional(),
|
|
|
|
line2: z.string().optional(),
|
|
|
|
state: z.string().optional(),
|
|
|
|
city: z.string().optional(),
|
|
|
|
postalCode: z.string().optional(),
|
|
|
|
})
|
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const paymentInputOptionsSchema = optionBaseSchema.merge(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2023-11-08 15:34:16 +01:00
|
|
|
provider: z.nativeEnum(PaymentProvider).optional(),
|
|
|
|
labels: z
|
|
|
|
.object({
|
|
|
|
button: z.string().optional(),
|
|
|
|
success: z.string().optional(),
|
|
|
|
})
|
|
|
|
.optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
additionalInformation: z
|
|
|
|
.object({
|
2023-03-29 15:08:03 +02:00
|
|
|
description: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
name: z.string().optional(),
|
|
|
|
email: z.string().optional(),
|
|
|
|
phoneNumber: z.string().optional(),
|
2023-05-05 14:54:37 -04:00
|
|
|
address: addressSchema.optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
.optional(),
|
|
|
|
credentialsId: z.string().optional(),
|
2023-11-08 15:34:16 +01:00
|
|
|
currency: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
amount: z.string().optional(),
|
2023-07-27 17:25:02 +02:00
|
|
|
retryMessageContent: z.string().optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2022-12-22 17:02:34 +01:00
|
|
|
export const paymentInputRuntimeOptionsSchema = z.object({
|
|
|
|
paymentIntentSecret: z.string(),
|
|
|
|
amountLabel: z.string(),
|
|
|
|
publicKey: z.string(),
|
|
|
|
})
|
|
|
|
|
2023-03-14 16:42:12 +01:00
|
|
|
export const paymentInputSchema = blockBaseSchema.merge(
|
2022-06-07 08:49:12 +02:00
|
|
|
z.object({
|
2022-06-11 07:27:38 +02:00
|
|
|
type: z.enum([InputBlockType.PAYMENT]),
|
2023-11-08 15:34:16 +01:00
|
|
|
options: paymentInputOptionsSchema.optional(),
|
2022-06-07 08:49:12 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-09 08:46:36 +01:00
|
|
|
export const stripeCredentialsSchema = z
|
|
|
|
.object({
|
|
|
|
type: z.literal('stripe'),
|
|
|
|
data: z.object({
|
|
|
|
live: z.object({
|
|
|
|
secretKey: z.string(),
|
|
|
|
publicKey: z.string(),
|
|
|
|
}),
|
|
|
|
test: z.object({
|
|
|
|
secretKey: z.string().optional(),
|
|
|
|
publicKey: z.string().optional(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.merge(credentialsBaseSchema)
|
|
|
|
|
2022-06-11 07:27:38 +02:00
|
|
|
export type PaymentInputBlock = z.infer<typeof paymentInputSchema>
|
2022-12-22 17:02:34 +01:00
|
|
|
export type PaymentInputRuntimeOptions = z.infer<
|
|
|
|
typeof paymentInputRuntimeOptionsSchema
|
|
|
|
>
|
2023-03-09 08:46:36 +01:00
|
|
|
export type StripeCredentials = z.infer<typeof stripeCredentialsSchema>
|
2023-05-05 14:54:37 -04:00
|
|
|
export type PaymentAddress = NonNullable<
|
2023-11-08 15:34:16 +01:00
|
|
|
NonNullable<PaymentInputBlock['options']>['additionalInformation']
|
2023-05-05 14:54:37 -04:00
|
|
|
>['address']
|