@@ -149,6 +149,7 @@ export default function PlansAndPayment ({ userData }) {
149149 const [ checkoutStep , setCheckoutStep ] = useState ( "plan" )
150150 const [ isChatbotTrialSuccess , setIsChatbotTrialSuccess ] = useState ( false )
151151 const [ isStartingChatbotTrial , setIsStartingChatbotTrial ] = useState ( false )
152+ const [ isSetupIntentCheckout , setIsSetupIntentCheckout ] = useState ( false )
152153 const successCheckoutKindRef = useRef ( null )
153154
154155 const internalSubscriptions = userData ?. internalSubscription ?. edges ?. map ( ( edge ) => edge ?. node ) || [ ]
@@ -346,6 +347,7 @@ export default function PlansAndPayment ({ userData }) {
346347 setCoupon ( "" )
347348 setCouponInfos ( { } )
348349 setPlan ( "" )
350+ setIsSetupIntentCheckout ( false )
349351 }
350352
351353 function openCheckoutPlanStep ( ) {
@@ -356,6 +358,7 @@ export default function PlansAndPayment ({ userData }) {
356358 function openCheckoutPaymentStep ( ) {
357359 setCheckoutStep ( "payment" )
358360 setIsLoadingClientSecret ( true )
361+ setIsSetupIntentCheckout ( false )
359362 PaymentModal . onOpen ( )
360363 }
361364
@@ -672,14 +675,23 @@ export default function PlansAndPayment ({ userData }) {
672675 )
673676 }
674677
675- const TotalToPayDisplay = ( ) => {
676- let value
677-
678- if ( couponInfos ?. discountAmount ) {
679- value = ( checkoutInfos ?. amount - couponInfos ?. discountAmount ) . toLocaleString ( 'pt-BR' , { style : 'currency' , currency : 'BRL' , minimumFractionDigits : 2 } )
680- } else {
681- value = checkoutInfos ?. amount ?. toLocaleString ( 'pt-BR' , { style : 'currency' , currency : 'BRL' , minimumFractionDigits : 2 } )
678+ function getCheckoutTotalAmount ( ) {
679+ if ( couponInfos ?. discountAmount ) {
680+ return checkoutInfos ?. amount - couponInfos . discountAmount
682681 }
682+ return checkoutInfos ?. amount
683+ }
684+
685+ function formatCheckoutAmount ( amount ) {
686+ return amount ?. toLocaleString ( "pt-BR" , {
687+ style : "currency" ,
688+ currency : "BRL" ,
689+ minimumFractionDigits : 2 ,
690+ } )
691+ }
692+
693+ const TotalToPayDisplay = ( ) => {
694+ const value = formatCheckoutAmount ( getCheckoutTotalAmount ( ) )
683695
684696 return (
685697 < >
@@ -693,6 +705,11 @@ export default function PlansAndPayment ({ userData }) {
693705 )
694706 }
695707
708+ const showPaymentSummary =
709+ checkoutStep === "payment" &&
710+ ! isLoadingClientSecret &&
711+ ( ! isSetupIntentCheckout || ! isChatbotCheckout )
712+
696713 async function handlerEmailGcp ( ) {
697714 setErrEmailGCP ( false )
698715 setIsLoadingEmailChange ( true )
@@ -1019,7 +1036,11 @@ export default function PlansAndPayment ({ userData }) {
10191036 </ Button >
10201037 < Button
10211038 width = { { base : "100%" , lg : "fit-content" } }
1022- onClick = { ( ) => setCheckoutStep ( "payment" ) }
1039+ onClick = { ( ) => {
1040+ setIsSetupIntentCheckout ( false )
1041+ setIsLoadingClientSecret ( true )
1042+ setCheckoutStep ( "payment" )
1043+ } }
10231044 >
10241045 { t ( "username.next" ) }
10251046 </ Button >
@@ -1032,6 +1053,32 @@ export default function PlansAndPayment ({ userData }) {
10321053 spacing = "24px"
10331054 pointerEvents = { isLoadingClientSecret ? "none" : "default" }
10341055 >
1056+ { showPaymentSummary && (
1057+ < Stack
1058+ spacing = "8px"
1059+ padding = "16px"
1060+ backgroundColor = "#F7F7F7"
1061+ borderRadius = "12px"
1062+ >
1063+ < Box
1064+ display = "flex"
1065+ justifyContent = "space-between"
1066+ alignItems = "center"
1067+ gap = "16px"
1068+ >
1069+ < LabelText textTransform = "capitalize" >
1070+ { checkoutInfos ?. productName }
1071+ </ LabelText >
1072+ < BodyText typography = "small" color = "#71757A" >
1073+ { formattedPlanInterval ( checkoutInfos ?. interval ) }
1074+ </ BodyText >
1075+ </ Box >
1076+ < TitleText typography = "small" >
1077+ { formatCheckoutAmount ( getCheckoutTotalAmount ( ) ) } /
1078+ { formattedPlanInterval ( checkoutInfos ?. interval , true ) }
1079+ </ TitleText >
1080+ </ Stack >
1081+ ) }
10351082 < LabelText > { t ( "username.paymentDetails" ) } </ LabelText >
10361083 < PaymentSystem
10371084 userData = { userData }
@@ -1040,6 +1087,13 @@ export default function PlansAndPayment ({ userData }) {
10401087 onSucess = { ( isTrial ) => openModalSucess ( isTrial ) }
10411088 onErro = { ( ) => openModalErro ( ) }
10421089 isLoading = { ( e ) => setIsLoadingClientSecret ( e ) }
1090+ onClientSecretReady = { ( { isSetupIntent, isLoading : loadingSecret } ) => {
1091+ if ( loadingSecret ) {
1092+ setIsSetupIntentCheckout ( false )
1093+ return
1094+ }
1095+ setIsSetupIntentCheckout ( Boolean ( isSetupIntent ) )
1096+ } }
10431097 />
10441098 </ Stack >
10451099 ) }
0 commit comments