@@ -5,7 +5,12 @@ open GooglePayType
55open Promise
66
77@react.component
8- let make = (~sessionObj : option <SessionsType .token >, ~thirdPartySessionObj : option <JSON .t >) => {
8+ let make = (
9+ ~sessionObj : option <SessionsType .token >,
10+ ~thirdPartySessionObj : option <JSON .t >,
11+ ~walletOptions ,
12+ ~paymentType : CardThemeType .mode ,
13+ ) => {
914 let url = RescriptReactRouter .useUrl ()
1015 let componentName = CardUtils .getQueryParamsDictforKey (url .search , "componentName" )
1116 let loggerState = Recoil .useRecoilValueFromAtom (loggerAtom )
@@ -28,6 +33,17 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
2833
2934 let areOneClickWalletsRendered = Recoil .useSetRecoilState (RecoilAtoms .areOneClickWalletsRendered )
3035
36+ let areRequiredFieldsValid = Recoil .useRecoilValueFromAtom (RecoilAtoms .areRequiredFieldsValid )
37+ let areRequiredFieldsEmpty = Recoil .useRecoilValueFromAtom (RecoilAtoms .areRequiredFieldsEmpty )
38+ let (requiredFieldsBody , setRequiredFieldsBody ) = React .useState (_ => Dict .make ())
39+ let isWallet = walletOptions -> Array .includes ("google_pay" )
40+
41+ UtilityHooks .useHandlePostMessages (
42+ ~complete = areRequiredFieldsValid ,
43+ ~empty = areRequiredFieldsEmpty ,
44+ ~paymentType = "google_pay" ,
45+ )
46+
3147 let googlePayPaymentMethodType = switch PaymentMethodsRecord .getPaymentMethodTypeFromList (
3248 ~paymentMethodListValue ,
3349 ~paymentMethod = "wallet" ,
@@ -58,7 +74,7 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
5874 -> Option .getOr (false )
5975 }, [thirdPartySessionObj ])
6076
61- GooglePayHelpers .useHandleGooglePayResponse (~connectors , ~intent )
77+ GooglePayHelpers .useHandleGooglePayResponse (~connectors , ~intent , ~ isWallet , ~ requiredFieldsBody )
6278
6379 let (_ , buttonType , _ ) = options .wallets .style .type_
6480 let (_ , heightType , _ , _ ) = options .wallets .style .height
@@ -155,9 +171,10 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
155171 React .useEffect (() => {
156172 if (
157173 status == "ready" &&
158- (isGPayReady ||
159- isDelayedSessionToken ||
160- paymentExperience == PaymentMethodsRecord .RedirectToURL )
174+ (isGPayReady ||
175+ isDelayedSessionToken ||
176+ paymentExperience == PaymentMethodsRecord .RedirectToURL ) &&
177+ isWallet
161178 ) {
162179 setIsShowOrPayUsing (_ => true )
163180 addGooglePayButton ()
@@ -190,7 +207,9 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
190207 })
191208
192209 let isRenderGooglePayButton =
193- isGPayReady || paymentExperience == PaymentMethodsRecord .RedirectToURL || isDelayedSessionToken
210+ (isGPayReady ||
211+ paymentExperience == PaymentMethodsRecord .RedirectToURL ||
212+ isDelayedSessionToken ) && isWallet
194213
195214 React .useEffect (() => {
196215 areOneClickWalletsRendered (prev => {
@@ -200,13 +219,22 @@ let make = (~sessionObj: option<SessionsType.token>, ~thirdPartySessionObj: opti
200219 None
201220 }, [isRenderGooglePayButton ])
202221
203- <RenderIf condition = {isRenderGooglePayButton }>
204- <div
205- style = {height : ` ${height-> Int.toString}px` }
206- id = "google-pay-button"
207- className = {` w-full flex flex-row justify-center rounded-md` }
222+ let submitCallback = GooglePayHelpers .useSubmitCallback (~isWallet , ~sessionObj , ~componentName )
223+ useSubmitPaymentData (submitCallback )
224+
225+ if isWallet {
226+ <RenderIf condition = {isRenderGooglePayButton }>
227+ <div
228+ style = {height : ` ${height-> Int.toString}px` }
229+ id = "google-pay-button"
230+ className = {` w-full flex flex-row justify-center rounded-md` }
231+ />
232+ </RenderIf >
233+ } else {
234+ <DynamicFields
235+ paymentType paymentMethod = "wallet" paymentMethodType = "google_pay" setRequiredFieldsBody
208236 />
209- </ RenderIf >
237+ }
210238}
211239
212240let default = make
0 commit comments