Skip to content

Commit

Permalink
fix(payment): fix incorrect svod redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed May 31, 2022
1 parent 31325e4 commit cf3bd7d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/containers/AccountModal/forms/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useHistory } from 'react-router';
import { useTranslation } from 'react-i18next';
import shallow from 'zustand/shallow';

import { isSVODOffer } from '../../../utils/subscription';

import CheckoutForm from '#src/components/CheckoutForm/CheckoutForm';
import { addQueryParam, removeQueryParam } from '#src/utils/history';
import useForm from '#src/hooks/useForm';
Expand All @@ -27,12 +29,11 @@ const Checkout = () => {
const [paymentMethodId, setPaymentMethodId] = useState<number | undefined>(undefined);

const { order, offer, paymentMethods } = useCheckoutStore(({ order, offer, paymentMethods }) => ({ order, offer, paymentMethods }), shallow);
const offerType = offer?.period === null ? 'tvod' : 'svod';
const offerType = offer && !isSVODOffer(offer) ? 'tvod' : 'svod';

const paymentSuccessUrl = useMemo(
() => (offerType === 'svod' ? addQueryParams(window.location.href, { u: 'welcome' }) : removeQueryParam(history, 'u')),
[history, offerType],
);
const paymentSuccessUrl = useMemo(() => {
return offerType === 'svod' ? addQueryParam(history, 'u', 'welcome') : removeQueryParam(history, 'u');
}, [history, offerType]);

const couponCodeForm = useForm({ couponCode: '' }, async (values, { setSubmitting, setErrors }) => {
setUpdatingOrder(true);
Expand Down Expand Up @@ -123,7 +124,8 @@ const Checkout = () => {
setUpdatingOrder(true);
const cancelUrl = addQueryParams(window.location.href, { u: 'paypal-cancelled' });
const errorUrl = addQueryParams(window.location.href, { u: 'paypal-error' });
const response = await paypalPayment(paymentSuccessUrl, cancelUrl, errorUrl);
const successUrl = `${window.location.origin}${paymentSuccessUrl}`;
const response = await paypalPayment(successUrl, cancelUrl, errorUrl);

if (response.redirectUrl) {
window.location.href = response.redirectUrl;
Expand Down

0 comments on commit cf3bd7d

Please sign in to comment.