-
Notifications
You must be signed in to change notification settings - Fork 60
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
OWA-107: Fix broken SCA flow payment finalization #677
Open
mirovladimitrovski
wants to merge
7
commits into
develop
Choose a base branch
from
OWA-107/sca-ppv-flow
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+173
−75
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dea0f21
feat: implement broken sca flow payment finalization
mirovladimitrovski 4d74fd9
fix: simplify sca logic
mirovladimitrovski e310049
fix: refactor finalizing stripe ppv payment
mirovladimitrovski 8babd30
fix: restore old name of variable
mirovladimitrovski c81ef16
fix: remove await from statement
mirovladimitrovski f9e60af
Merge branch 'develop' into OWA-107/sca-ppv-flow
mirovladimitrovski 84f900a
Merge branch 'develop' into OWA-107/sca-ppv-flow
mirovladimitrovski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
84 changes: 84 additions & 0 deletions
84
packages/ui-react/src/components/FinalizePayment/FinalizeAdyenPayment.tsx
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,84 @@ | ||
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 { getModule } from '@jwp/ott-common/src/modules/container'; | ||
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore'; | ||
import AccountController from '@jwp/ott-common/src/controllers/AccountController'; | ||
import CheckoutController from '@jwp/ott-common/src/controllers/CheckoutController'; | ||
import { ACCESS_MODEL } from '@jwp/ott-common/src/constants'; | ||
import useEventCallback from '@jwp/ott-hooks-react/src/useEventCallback'; | ||
|
||
import Button from '../Button/Button'; | ||
import { modalURLFromLocation } from '../../utils/location'; | ||
import { useAriaAnnouncer } from '../../containers/AnnouncementProvider/AnnoucementProvider'; | ||
|
||
import styles from './FinalizePayment.module.scss'; | ||
|
||
type FinalizeAdyenPaymentProps = { | ||
onError: () => void; | ||
}; | ||
|
||
const FinalizeAdyenPayment = ({ onError }: FinalizeAdyenPaymentProps) => { | ||
const accountController = getModule(AccountController); | ||
const checkoutController = getModule(CheckoutController); | ||
|
||
const { t } = useTranslation('account'); | ||
const announce = useAriaAnnouncer(); | ||
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 modalURLFromLocation(location, accessModel === ACCESS_MODEL.SVOD ? 'welcome' : null); | ||
}, [accessModel, location]); | ||
|
||
const checkPaymentResult = useEventCallback(async (redirectResult: string) => { | ||
const orderId = orderIdQueryParam ? parseInt(orderIdQueryParam, 10) : undefined; | ||
|
||
try { | ||
await checkoutController.finalizeAdyenPayment({ redirectResult: decodeURI(redirectResult) }, orderId); | ||
await accountController.reloadSubscriptions({ retry: 10 }); | ||
|
||
announce(t('checkout.payment_success'), 'success'); | ||
navigate(paymentSuccessUrl); | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
setErrorMessage(error.message); | ||
onError(); | ||
} | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
if (!redirectResult) return; | ||
|
||
checkPaymentResult(redirectResult); | ||
}, [checkPaymentResult, redirectResult]); | ||
|
||
return ( | ||
<> | ||
{errorMessage && ( | ||
<> | ||
<h2 className={styles.title}>{errorMessage}</h2> | ||
<Button | ||
label={t('checkout.go_back_to_checkout')} | ||
variant="contained" | ||
color="primary" | ||
size="large" | ||
onClick={() => navigate(modalURLFromLocation(location, 'checkout'))} | ||
fullWidth | ||
/> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default FinalizeAdyenPayment; |
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 |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
font-weight: var(--body-font-weight-bold); | ||
font-size: 24px; | ||
} | ||
|
84 changes: 18 additions & 66 deletions
84
packages/ui-react/src/components/FinalizePayment/FinalizePayment.tsx
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
37 changes: 37 additions & 0 deletions
37
packages/ui-react/src/components/FinalizePayment/FinalizeStripePpvPayment.tsx
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,37 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { getModule } from '@jwp/ott-common/src/modules/container'; | ||
import CheckoutController from '@jwp/ott-common/src/controllers/CheckoutController'; | ||
|
||
const FinalizeStripePpvPayment = () => { | ||
const checkoutController = getModule(CheckoutController); | ||
|
||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const finalize = useCallback(async (paymentIntent: string) => { | ||
try { | ||
await checkoutController.finalizeStripePpvPayment(paymentIntent); | ||
|
||
setSearchParams({ u: 'waiting-for-payment' }); | ||
} finally { | ||
// we don't need to handle any outcome here, it is handled by notifications | ||
// NotificationsTypes.CARD_SUCCESS and NotificationsTypes.CARD_FAILED | ||
} | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
useEffect(() => { | ||
const paymentIntent = searchParams.get('payment_intent'); | ||
|
||
if (paymentIntent) { | ||
finalize(paymentIntent); | ||
} | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default FinalizeStripePpvPayment; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try to reuse everything in FanalizeAdyenPayment except using a different method instead of a
checkoutController.finalizeAdyenPayment
one?