Skip to content

Commit

Permalink
fix: returning to previous screen after redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ authored and ChristiaanScheermeijer committed Jun 1, 2023
1 parent 6a681ce commit 9f0405e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/containers/AdyenInitialPayment/AdyenInitialPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ export default function AdyenInitialPayment({ setUpdatingOrder, type, setPayment
return;
}

const returnUrl = addQueryParams(window.origin, { u: 'finalize-payment', orderId: orderId });
const returnUrl = addQueryParams(window.location.href, { u: 'finalize-payment', orderId: orderId });
const result = await initialAdyenPayment(state.data.paymentMethod, returnUrl);

if ('action' in result) {
handleAction(result.action);
return;
}

await reloadActiveSubscription({ delay: 2000 });
Expand Down
8 changes: 4 additions & 4 deletions src/containers/AdyenPaymentDetails/AdyenPaymentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ import type { AdyenPaymentSession } from '#types/checkout';
import { addAdyenPaymentDetails, createAdyenPaymentSession, finalizeAdyenPayment, finalizeAdyenPaymentDetails } from '#src/stores/CheckoutController';
import useQueryParam from '#src/hooks/useQueryParam';
import useEventCallback from '#src/hooks/useEventCallback';
import { replaceQueryParam } from '#src/utils/location';
import { addQueryParam, replaceQueryParam } from '#src/utils/location';
import { addQueryParams } from '#src/utils/formatting';
import { reloadActiveSubscription } from '#src/stores/AccountController';

type Props = {
setProcessing: (loading: boolean) => void;
setPaymentError: (errorMessage?: string) => void;
paymentSuccessUrl: string;
paymentMethodId: number;
type: AdyenPaymentMethodType;
error?: string;
};

export default function AdyenPaymentDetails({ setProcessing, type, setPaymentError, paymentSuccessUrl, error, paymentMethodId }: Props) {
export default function AdyenPaymentDetails({ setProcessing, type, setPaymentError, error, paymentMethodId }: Props) {
const { sandbox } = useClientIntegration();
const navigate = useNavigate();
const location = useLocation();
const [session, setSession] = useState<AdyenPaymentSession>();

const redirectResult = useQueryParam('redirectResult');
const finalize = !!redirectResult;
const paymentSuccessUrl = addQueryParam(location, 'u', 'payment-method-success');

const finalizePaymentDetails = useEventCallback(async (redirectResult: string) => {
try {
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function AdyenPaymentDetails({ setProcessing, type, setPaymentErr
setProcessing(true);
setPaymentError(undefined);

const returnUrl = addQueryParams(window.origin, { u: 'payment-method', paymentMethodId: `${paymentMethodId}` });
const returnUrl = addQueryParams(window.location.href, { u: 'payment-method', paymentMethodId: `${paymentMethodId}` });
const result = await addAdyenPaymentDetails(state.data.paymentMethod, paymentMethodId, returnUrl);

if ('action' in result) {
Expand Down

0 comments on commit 9f0405e

Please sign in to comment.