2
0

🐛 (payment) Fix payment redirection

This commit is contained in:
Baptiste Arnaud
2024-06-26 10:59:11 +02:00
parent 6db0464fd7
commit 6af47a8cfe
16 changed files with 182 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.3.0",
"version": "0.3.1",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",

View File

@@ -4,7 +4,7 @@ import { isDefined, isNotDefined, isNotEmpty } from '@typebot.io/lib'
import { startChatQuery } from '@/queries/startChatQuery'
import { ConversationContainer } from './ConversationContainer'
import { setIsMobile } from '@/utils/isMobileSignal'
import { BotContext, InitialChatReply, OutgoingLog } from '@/types'
import { BotContext, OutgoingLog } from '@/types'
import { ErrorMessage } from './ErrorMessage'
import {
getExistingResultIdFromStorage,
@@ -15,7 +15,12 @@ import {
} from '@/utils/storage'
import { setCssVariablesValue } from '@/utils/setCssVariablesValue'
import immutableCss from '../assets/immutable.css'
import { Font, InputBlock, StartFrom } from '@typebot.io/schemas'
import {
Font,
InputBlock,
StartChatResponse,
StartFrom,
} from '@typebot.io/schemas'
import { clsx } from 'clsx'
import { HTTPError } from 'ky'
import { injectFont } from '@/utils/injectFont'
@@ -55,7 +60,7 @@ export type BotProps = {
export const Bot = (props: BotProps & { class?: string }) => {
const [initialChatReply, setInitialChatReply] = createSignal<
InitialChatReply | undefined
StartChatResponse | undefined
>()
const [customCss, setCustomCss] = createSignal('')
const [isInitialized, setIsInitialized] = createSignal(false)
@@ -245,7 +250,7 @@ export const Bot = (props: BotProps & { class?: string }) => {
}
type BotContentProps = {
initialChatReply: InitialChatReply
initialChatReply: StartChatResponse
context: BotContext
class?: string
progressBarRef?: HTMLDivElement

View File

@@ -3,6 +3,7 @@ import {
InputBlock,
Theme,
ChatLog,
StartChatResponse,
} from '@typebot.io/schemas'
import {
createEffect,
@@ -14,12 +15,7 @@ import {
} from 'solid-js'
import { continueChatQuery } from '@/queries/continueChatQuery'
import { ChatChunk } from './ChatChunk'
import {
BotContext,
ChatChunk as ChatChunkType,
InitialChatReply,
OutgoingLog,
} from '@/types'
import { BotContext, ChatChunk as ChatChunkType, OutgoingLog } from '@/types'
import { isNotDefined } from '@typebot.io/lib'
import { executeClientSideAction } from '@/utils/executeClientSideActions'
import { LoadingChunk } from './LoadingChunk'
@@ -61,7 +57,7 @@ const parseDynamicTheme = (
})
type Props = {
initialChatReply: InitialChatReply
initialChatReply: StartChatResponse
context: BotContext
onNewInputBlock?: (inputBlock: InputBlock) => void
onAnswer?: (answer: { message: string; blockId: string }) => void

View File

@@ -64,6 +64,7 @@ export const StripePaymentForm = (props: Props) => {
setPaymentInProgressInStorage({
sessionId: props.context.sessionId,
resultId: props.context.resultId,
typebot: props.context.typebot,
})
const { postalCode, ...address } =

View File

@@ -1,9 +1,8 @@
import { BotContext } from '@/types'
import { StartChatResponse } from '@typebot.io/schemas'
export const setPaymentInProgressInStorage = (state: {
sessionId: string
typebot: BotContext['typebot']
}) => {
export const setPaymentInProgressInStorage = (
state: Pick<StartChatResponse, 'typebot' | 'sessionId' | 'resultId'>
) => {
sessionStorage.setItem('typebotPaymentInProgress', JSON.stringify(state))
}

View File

@@ -1,4 +1,4 @@
import { BotContext, InitialChatReply } from '@/types'
import { BotContext } from '@/types'
import { guessApiHost } from '@/utils/guessApiHost'
import { isNotDefined, isNotEmpty } from '@typebot.io/lib'
import {
@@ -6,7 +6,9 @@ import {
removePaymentInProgressFromStorage,
} from '@/features/blocks/inputs/payment/helpers/paymentInProgressStorage'
import {
ContinueChatResponse,
StartChatInput,
StartChatResponse,
StartFrom,
StartPreviewChatInput,
} from '@typebot.io/schemas'
@@ -65,9 +67,14 @@ export async function startChatQuery({
timeout: false,
}
)
.json<InitialChatReply>()
.json<ContinueChatResponse>()
return { data }
return {
data: {
...data,
...paymentInProgressState,
} satisfies StartChatResponse,
}
} catch (error) {
return { error }
}
@@ -94,7 +101,7 @@ export async function startChatQuery({
timeout: false,
}
)
.json<InitialChatReply>()
.json<StartChatResponse>()
return { data }
} catch (error) {
@@ -138,7 +145,7 @@ export async function startChatQuery({
)
throw new CorsError(corsAllowOrigin)
return { data: await response.json<InitialChatReply>() }
return { data: await response.json<StartChatResponse>() }
} catch (error) {
return { error }
}

View File

@@ -7,7 +7,7 @@ export type InputSubmitContent = {
}
export type BotContext = {
typebot: InitialChatReply['typebot']
typebot: StartChatResponse['typebot']
resultId?: string
isPreview: boolean
apiHost?: string
@@ -15,11 +15,6 @@ export type BotContext = {
storage: 'local' | 'session' | undefined
}
export type InitialChatReply = StartChatResponse & {
typebot: NonNullable<StartChatResponse['typebot']>
sessionId: NonNullable<StartChatResponse['sessionId']>
}
export type OutgoingLog = {
status: string
description: string

View File

@@ -1,4 +1,4 @@
import { InitialChatReply } from '@/types'
import { StartChatResponse } from '@typebot.io/schemas/features/chat/schema'
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
const storageResultIdKey = 'resultId'
@@ -38,13 +38,13 @@ export const getInitialChatReplyFromStorage = (
sessionStorage.getItem(`typebot-${typebotId}-initialChatReply`) ??
localStorage.getItem(`typebot-${typebotId}-initialChatReply`)
if (!rawInitialChatReply) return
return JSON.parse(rawInitialChatReply) as InitialChatReply
return JSON.parse(rawInitialChatReply) as StartChatResponse
} catch {
/* empty */
}
}
export const setInitialChatReplyInStorage = (
initialChatReply: InitialChatReply,
initialChatReply: StartChatResponse,
{
typebotId,
storage,