-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payment): integrate new adyen payment flow (incl 3DS)
- Loading branch information
1 parent
9e1b8da
commit bb0f745
Showing
30 changed files
with
591 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/components/FinalizePayment/FinalizePayment.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.container { | ||
min-height: 90px; | ||
margin-top: 24px; | ||
text-align: center; | ||
} | ||
|
||
.title { | ||
width: 100%; | ||
margin-bottom: 24px; | ||
font-weight: var(--body-font-weight-bold); | ||
font-size: 24px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useLocation, useNavigate } from 'react-router'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
import styles from './FinalizePayment.module.scss'; | ||
|
||
import Button from '#components/Button/Button'; | ||
import Spinner from '#components/Spinner/Spinner'; | ||
import useEventCallback from '#src/hooks/useEventCallback'; | ||
import { reloadActiveSubscription } from '#src/stores/AccountController'; | ||
import { useConfigStore } from '#src/stores/ConfigStore'; | ||
import { replaceQueryParam, removeQueryParam, addQueryParam } from '#src/utils/location'; | ||
import { finalizeAdyenPayment } from '#src/stores/CheckoutController'; | ||
|
||
const FinalizePayment = () => { | ||
const { t } = useTranslation('account'); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
const { accessModel } = useConfigStore(({ accessModel }) => ({ accessModel })); | ||
const [searchParams] = useSearchParams(); | ||
const redirectResult = searchParams.get('redirectResult'); | ||
const orderIdQueryParam = searchParams.get('orderId'); | ||
|
||
const [errorMessage, setErrorMessage] = useState<string>(); | ||
|
||
const paymentSuccessUrl = useMemo(() => { | ||
return accessModel === 'SVOD' ? replaceQueryParam(location, 'u', 'welcome') : removeQueryParam(location, 'u'); | ||
}, [accessModel, location]); | ||
|
||
const checkPaymentResult = useEventCallback(async (redirectResult: string) => { | ||
const orderId = orderIdQueryParam ? parseInt(orderIdQueryParam, 10) : undefined; | ||
|
||
try { | ||
await finalizeAdyenPayment({ redirectResult: decodeURI(redirectResult) }, orderId); | ||
await reloadActiveSubscription({ delay: 2000 }); | ||
|
||
navigate(paymentSuccessUrl); | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
setErrorMessage(error.message); | ||
} | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
if (!redirectResult) return; | ||
|
||
checkPaymentResult(redirectResult); | ||
}, [checkPaymentResult, redirectResult]); | ||
|
||
return ( | ||
<div className={styles.container}> | ||
{errorMessage ? ( | ||
<> | ||
<h2 className={styles.title}>{errorMessage}</h2> | ||
<Button | ||
label={t('checkout.go_back_to_checkout')} | ||
variant="contained" | ||
color="primary" | ||
size="large" | ||
onClick={() => navigate(addQueryParam(location, 'u', 'checkout'))} | ||
fullWidth | ||
/> | ||
</> | ||
) : ( | ||
<div className={styles.loading}> | ||
<Spinner /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FinalizePayment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.