diff --git a/packages/common/src/controllers/CheckoutController.ts b/packages/common/src/controllers/CheckoutController.ts index ffe195d50..709db7bb0 100644 --- a/packages/common/src/controllers/CheckoutController.ts +++ b/packages/common/src/controllers/CheckoutController.ts @@ -205,13 +205,11 @@ export default class CheckoutController { paypalPayment = async ({ successUrl, - waitingUrl, cancelUrl, errorUrl, couponCode = '', }: { successUrl: string; - waitingUrl: string; cancelUrl: string; errorUrl: string; couponCode: string; @@ -223,7 +221,6 @@ export default class CheckoutController { const response = await this.checkoutService.paymentWithPayPal({ order: order, successUrl, - waitingUrl, cancelUrl, errorUrl, couponCode, @@ -291,21 +288,13 @@ export default class CheckoutController { return responseData; }; - updatePayPalPaymentMethod = async ( - successUrl: string, - waitingUrl: string, - cancelUrl: string, - errorUrl: string, - paymentMethodId: number, - currentPaymentId?: number, - ) => { + updatePayPalPaymentMethod = async (successUrl: string, cancelUrl: string, errorUrl: string, paymentMethodId: number, currentPaymentId?: number) => { assertModuleMethod(this.checkoutService.updatePaymentMethodWithPayPal, 'updatePaymentMethodWithPayPal is not available in checkout service'); assertModuleMethod(this.checkoutService.deletePaymentMethod, 'deletePaymentMethod is not available in checkout service'); const response = await this.checkoutService.updatePaymentMethodWithPayPal({ paymentMethodId, successUrl, - waitingUrl, cancelUrl, errorUrl, }); diff --git a/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts b/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts index 678c50cd5..5f6de093b 100644 --- a/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts +++ b/packages/common/src/services/integrations/jwp/JWPCheckoutService.ts @@ -136,7 +136,7 @@ export default class JWPCheckoutService extends CheckoutService { paymentWithPayPal: PaymentWithPayPal = async (payload) => { try { const response = await InPlayer.Payment.getPayPalParams({ - origin: payload.waitingUrl, + origin: payload.successUrl, accessFeeId: payload.order.id, paymentMethod: 2, voucherCode: payload.couponCode, diff --git a/packages/common/types/checkout.ts b/packages/common/types/checkout.ts index 89210f117..6c19f9717 100644 --- a/packages/common/types/checkout.ts +++ b/packages/common/types/checkout.ts @@ -263,7 +263,6 @@ export type PaymentWithPayPalPayload = { successUrl: string; cancelUrl: string; errorUrl: string; - waitingUrl: string; couponCode?: string; }; diff --git a/packages/hooks-react/src/useCheckout.ts b/packages/hooks-react/src/useCheckout.ts index 29614f08b..34e7521d3 100644 --- a/packages/hooks-react/src/useCheckout.ts +++ b/packages/hooks-react/src/useCheckout.ts @@ -52,11 +52,7 @@ const useCheckout = ({ onUpdateOrderSuccess, onSubmitPaymentWithoutDetailsSucces }, }); - const submitPaymentPaypal = useMutation< - { redirectUrl: string }, - Error, - { successUrl: string; waitingUrl: string; cancelUrl: string; errorUrl: string; couponCode: string } - >({ + const submitPaymentPaypal = useMutation<{ redirectUrl: string }, Error, { successUrl: string; cancelUrl: string; errorUrl: string; couponCode: string }>({ mutationKey: ['submitPaymentPaypal'], mutationFn: checkoutController.paypalPayment, onSuccess: onSubmitPaypalPaymentSuccess, diff --git a/packages/ui-react/src/containers/AccountModal/forms/Checkout.tsx b/packages/ui-react/src/containers/AccountModal/forms/Checkout.tsx index d1befb85b..bf0f58e9b 100644 --- a/packages/ui-react/src/containers/AccountModal/forms/Checkout.tsx +++ b/packages/ui-react/src/containers/AccountModal/forms/Checkout.tsx @@ -104,7 +104,12 @@ const Checkout = () => { const absoluteCancelUrl = modalURLFromWindowLocation('payment-cancelled'); const absoluteWaitingUrl = modalURLFromWindowLocation('waiting-for-payment', { offerId: selectedOffer?.offerId }); const absoluteErrorUrl = modalURLFromWindowLocation('payment-error'); - const absoluteSuccessUrl = offerType === 'svod' ? absoluteWaitingUrl : modalURLFromWindowLocation(null); + const absoluteCloseModalUrl = modalURLFromWindowLocation(null); + + // the waiting for payment modal doesn't work for TVOD offers, so we close the modal instead + // @todo add support for different offers in the waiting for payment modal + const absoluteReturnUrl = offerType === 'svod' ? absoluteWaitingUrl : absoluteCloseModalUrl; + const returnUrl = offerType === 'svod' ? waitingUrl : closeModalUrl; const referrer = window.location.href; const paymentMethod = paymentMethods?.find((method) => method.id === parseInt(paymentMethodId)); @@ -138,26 +143,20 @@ const Checkout = () => { {isStripePayment && ( - await submitPaymentStripe.mutateAsync({ cardPaymentPayload, referrer, returnUrl: absoluteWaitingUrl }) + await submitPaymentStripe.mutateAsync({ cardPaymentPayload, referrer, returnUrl: absoluteReturnUrl }) } /> )} {isAdyenPayment && ( <> - + )} {isPayPalPayment && ( submitPaymentPaypal.mutate({ - successUrl: absoluteSuccessUrl, - waitingUrl: absoluteWaitingUrl, + successUrl: absoluteReturnUrl, cancelUrl: absoluteCancelUrl, errorUrl: absoluteErrorUrl, couponCode, diff --git a/packages/ui-react/src/containers/UpdatePaymentMethod/UpdatePaymentMethod.tsx b/packages/ui-react/src/containers/UpdatePaymentMethod/UpdatePaymentMethod.tsx index 15e5c9408..5721a132a 100644 --- a/packages/ui-react/src/containers/UpdatePaymentMethod/UpdatePaymentMethod.tsx +++ b/packages/ui-react/src/containers/UpdatePaymentMethod/UpdatePaymentMethod.tsx @@ -49,18 +49,10 @@ const UpdatePaymentMethod = ({ onCloseButtonClick }: Props) => { setPaymentError(undefined); const successUrl = modalURLFromWindowLocation('payment-method-success'); - const waitingUrl = modalURLFromWindowLocation('waiting-for-payment'); const cancelUrl = modalURLFromWindowLocation('payment-cancelled'); const errorUrl = modalURLFromWindowLocation('payment-error'); - const response = await checkoutController.updatePayPalPaymentMethod( - successUrl, - waitingUrl, - cancelUrl, - errorUrl, - paymentMethodId as number, - currentPaymentId, - ); + const response = await checkoutController.updatePayPalPaymentMethod(successUrl, cancelUrl, errorUrl, paymentMethodId as number, currentPaymentId); if (response) { window.location.href = response.redirectUrl;