@@ -101,6 +101,18 @@ export const validationSchema: yup.SchemaOf<DonationFormData> = yup
101101export function DonationFlowForm ( ) {
102102 const formikRef = useRef < FormikProps < DonationFormData > | null > ( null )
103103 const { t } = useTranslation ( 'donation-flow' )
104+ const { campaign, setupIntent, paymentError, setPaymentError, idempotencyKey } = useDonationFlow ( )
105+ const stripe = useStripe ( )
106+ const elements = useElements ( )
107+ const router = useRouter ( )
108+ const updateSetupIntentMutation = useUpdateSetupIntent ( )
109+ const cancelSetupIntentMutation = useCancelSetupIntent ( )
110+ const paymentMethodSectionRef = React . useRef < HTMLDivElement > ( null )
111+ const authenticationSectionRef = React . useRef < HTMLDivElement > ( null )
112+ const stripeChargeRef = React . useRef < string > ( idempotencyKey )
113+ const [ showCancelDialog , setShowCancelDialog ] = React . useState ( false )
114+ const [ submitPaymentLoading , setSubmitPaymentLoading ] = React . useState ( false )
115+ const { data : { user : person } = { user : null } } = useCurrentPerson ( )
104116 const { data : session } = useSession ( {
105117 required : false ,
106118 onUnauthenticated : ( ) => {
@@ -117,17 +129,6 @@ export function DonationFlowForm() {
117129 formikRef . current ?. setFieldValue ( 'email' , '' )
118130 formikRef . current ?. setFieldValue ( 'isAnonymous' , true , false )
119131 } , [ session ] )
120- const { campaign, setupIntent, paymentError, setPaymentError, idempotencyKey } = useDonationFlow ( )
121- const stripe = useStripe ( )
122- const elements = useElements ( )
123- const router = useRouter ( )
124- const updateSetupIntentMutation = useUpdateSetupIntent ( )
125- const cancelSetupIntentMutation = useCancelSetupIntent ( )
126- const paymentMethodSectionRef = React . useRef < HTMLDivElement > ( null )
127- const authenticationSectionRef = React . useRef < HTMLDivElement > ( null )
128- const [ showCancelDialog , setShowCancelDialog ] = React . useState ( false )
129- const [ submitPaymentLoading , setSubmitPaymentLoading ] = React . useState ( false )
130- const { data : { user : person } = { user : null } } = useCurrentPerson ( )
131132
132133 return (
133134 < Formik
@@ -186,6 +187,7 @@ export function DonationFlowForm() {
186187 return_url : `${ window . location . origin } /${ routes . campaigns . donationStatus (
187188 campaign . slug ,
188189 ) } `,
190+ personId : ! values . isAnonymous && session ?. user && person ?. id ? person . id : null ,
189191 } ,
190192 } ,
191193 } )
@@ -197,7 +199,7 @@ export function DonationFlowForm() {
197199 campaign ,
198200 values ,
199201 session ,
200- idempotencyKey ,
202+ stripeChargeRef . current ,
201203 )
202204 router . push (
203205 `${ window . location . origin } ${ routes . campaigns . donationStatus ( campaign . slug ) } ?p_status=${
@@ -210,7 +212,7 @@ export function DonationFlowForm() {
210212 type : 'invalid_request_error' ,
211213 message : ( error as StripeError ) . message ?? t ( 'step.summary.alerts.error' ) ,
212214 } )
213-
215+ stripeChargeRef . current = crypto . randomUUID ( )
214216 return
215217 }
216218
0 commit comments