Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reported new donation flow issues #1979

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 16 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 @@ -173,6 +174,7 @@ export function DonationFlowForm() {

// Update the setup intent with the latest calculated amount
try {
console.log(!values.isAnonymous, session?.user, person?.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need this

const updatedIntent = await updateSetupIntentMutation.mutateAsync({
id: setupIntent.id,
idempotencyKey,
Expand All @@ -186,6 +188,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 +200,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 +213,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)
Loading