Skip to content

Commit

Permalink
fix: Reported new donation flow issues (#1979)
Browse files Browse the repository at this point in the history
* fix: Reported new donation flow issues

* fix: Non-anonymous donation being flagged as anonymous

* fix: E2E test breakage

* chore: Remove redundant console log
  • Loading branch information
sashko9807 authored Dec 4, 2024
1 parent 953b219 commit f4384d8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion e2e/pages/web-pages/donation/donation.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class DonationPage extends CampaignsPage {
bgLocalizationValidation['informed-agree-with'] + ' ' + bgLocalizationValidation.gdpr
private readonly enPrivacyCheckboxText =
enLocalizationValidation['informed-agree-with'] + ' ' + enLocalizationValidation.gdpr
private readonly bgStripeErrorNoBalanceText = 'Картата Ви не разполага с достатъчно средства.'
private readonly bgStripeErrorNoBalanceText = 'В картата ви няма достатъчно средства. Опитайте с друга.'

async checkPageUrlByRegExp(urlRegExpAsString?: string, timeoutParam = 10000): Promise<void> {
await this.page.waitForTimeout(1000)
Expand Down
28 changes: 15 additions & 13 deletions src/components/client/donation-flow/DonationFlowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ export const validationSchema: yup.SchemaOf<DonationFormData> = yup
export function DonationFlowForm() {
const formikRef = useRef<FormikProps<DonationFormData> | null>(null)
const { t } = useTranslation('donation-flow')
const { campaign, setupIntent, paymentError, setPaymentError, idempotencyKey } = useDonationFlow()
const stripe = useStripe()
const elements = useElements()
const router = useRouter()
const updateSetupIntentMutation = useUpdateSetupIntent()
const cancelSetupIntentMutation = useCancelSetupIntent()
const paymentMethodSectionRef = React.useRef<HTMLDivElement>(null)
const authenticationSectionRef = React.useRef<HTMLDivElement>(null)
const stripeChargeRef = React.useRef<string>(idempotencyKey)
const [showCancelDialog, setShowCancelDialog] = React.useState(false)
const [submitPaymentLoading, setSubmitPaymentLoading] = React.useState(false)
const { data: { user: person } = { user: null } } = useCurrentPerson()
const { data: session } = useSession({
required: false,
onUnauthenticated: () => {
Expand All @@ -117,17 +129,6 @@ export function DonationFlowForm() {
formikRef.current?.setFieldValue('email', '')
formikRef.current?.setFieldValue('isAnonymous', true, false)
}, [session])
const { campaign, setupIntent, paymentError, setPaymentError, idempotencyKey } = useDonationFlow()
const stripe = useStripe()
const elements = useElements()
const router = useRouter()
const updateSetupIntentMutation = useUpdateSetupIntent()
const cancelSetupIntentMutation = useCancelSetupIntent()
const paymentMethodSectionRef = React.useRef<HTMLDivElement>(null)
const authenticationSectionRef = React.useRef<HTMLDivElement>(null)
const [showCancelDialog, setShowCancelDialog] = React.useState(false)
const [submitPaymentLoading, setSubmitPaymentLoading] = React.useState(false)
const { data: { user: person } = { user: null } } = useCurrentPerson()

return (
<Formik
Expand Down Expand Up @@ -186,6 +187,7 @@ export function DonationFlowForm() {
return_url: `${window.location.origin}/${routes.campaigns.donationStatus(
campaign.slug,
)}`,
personId: !values.isAnonymous && session?.user && person?.id ? person.id : null,
},
},
})
Expand All @@ -197,7 +199,7 @@ export function DonationFlowForm() {
campaign,
values,
session,
idempotencyKey,
stripeChargeRef.current,
)
router.push(
`${window.location.origin}${routes.campaigns.donationStatus(campaign.slug)}?p_status=${
Expand All @@ -210,7 +212,7 @@ export function DonationFlowForm() {
type: 'invalid_request_error',
message: (error as StripeError).message ?? t('step.summary.alerts.error'),
})

stripeChargeRef.current = crypto.randomUUID()
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function AlertsColumn({
<>
{updatedRefArray.map((ref, index) => {
const alert = alerts[ref.current?.id as keyof typeof alerts]
if (!alert) return null
return <AnchoredAlert key={index} sectionRef={ref} {...alert} />
})}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type DonationContext = {
paymentError: StripeError | null
setPaymentError: React.Dispatch<React.SetStateAction<StripeError | null>>
campaign: CampaignResponse
stripe: StripeType | null
stripe: Promise<StripeType | null>
idempotencyKey: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/stripeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ const {
publicRuntimeConfig: { STRIPE_PUBLISHABLE_KEY },
} = getConfig()

export const stripe = await loadStripe(STRIPE_PUBLISHABLE_KEY)
export const stripe = loadStripe(STRIPE_PUBLISHABLE_KEY)

0 comments on commit f4384d8

Please sign in to comment.