From 551460fc143135a9883781fdc39566e7a9f1c873 Mon Sep 17 00:00:00 2001 From: Rakov Date: Mon, 26 Jun 2023 12:36:47 +0300 Subject: [PATCH] fix(#622): india payment phonePe --- src/config/clients/india.tsx | 1 + src/config/clients/tunisia.tsx | 1 + src/config/clients/types.tsx | 1 + src/config/payments.tsx | 4 +- .../components/IframePayment/hooks.tsx | 39 +++++++++++++++---- .../components/PackageSelectionStep/index.tsx | 18 ++++++--- src/features/UserAccount/index.tsx | 16 ++++---- src/requests/getMatchInfo.tsx | 2 +- ...getPaymentUrl.tsx => getPaymentOTTUrl.tsx} | 2 +- src/requests/getPaymentPayUrl.tsx | 31 +++++++++++++++ src/requests/index.tsx | 2 + 11 files changed, 93 insertions(+), 24 deletions(-) rename src/requests/{getPaymentUrl.tsx => getPaymentOTTUrl.tsx} (94%) create mode 100644 src/requests/getPaymentPayUrl.tsx diff --git a/src/config/clients/india.tsx b/src/config/clients/india.tsx index 3cf869c5..49e19cde 100644 --- a/src/config/clients/india.tsx +++ b/src/config/clients/india.tsx @@ -18,4 +18,5 @@ export const india: ClientConfig = { }, disabledHighlights: true, name: ClientNames.India, + userAccountCardsHidden: true, } diff --git a/src/config/clients/tunisia.tsx b/src/config/clients/tunisia.tsx index e27d68a8..29ea8d0d 100644 --- a/src/config/clients/tunisia.tsx +++ b/src/config/clients/tunisia.tsx @@ -60,4 +60,5 @@ export const tunisia: ClientConfig = { }, termsLink: '/terms-and-conditions?client_id=insports-ott-web', title: 'Diwan Sport - The home of Tunisian Ligue Professionnelle 1', + userAccountCardsHidden: true, } diff --git a/src/config/clients/types.tsx b/src/config/clients/types.tsx index d7b21fac..017c994c 100644 --- a/src/config/clients/types.tsx +++ b/src/config/clients/types.tsx @@ -64,5 +64,6 @@ export type ClientConfig = { }, termsLink: string, title: string, + userAccountCardsHidden?: boolean, userAccountLinksDisabled?: boolean, } diff --git a/src/config/payments.tsx b/src/config/payments.tsx index 56b5a5a0..cb803b31 100644 --- a/src/config/payments.tsx +++ b/src/config/payments.tsx @@ -3,7 +3,7 @@ import { ClientNames } from './clients/types' export enum PaymentSystem { PagBrazil = 'pag_brasil', Paymee = 'paymee', - Paytm = 'paytm', + PhonePe = 'phonePe', Stripe = 'stripe' } @@ -20,7 +20,7 @@ type PaymentsType = { export const payments: PaymentsType = { [ClientNames.Tunisia]: PaymentSystem.Paymee, [ClientNames.Brasil]: PaymentSystem.PagBrazil, - [ClientNames.India]: PaymentSystem.Paytm, + [ClientNames.India]: PaymentSystem.PhonePe, [ClientNames.Insports]: PaymentSystem.Stripe, [ClientNames.Instat]: PaymentSystem.Stripe, [ClientNames.Facr]: PaymentSystem.Stripe, diff --git a/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx b/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx index 54b3f4d3..d12f5cae 100644 --- a/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx +++ b/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx @@ -6,19 +6,23 @@ import { useState, } from 'react' +import isNumber from 'lodash/isNumber' + import { PAGES, ProfileTypes } from 'config' import { ClientNames } from 'config/clients/types' import { payments, PaymentSystem } from 'config/payments' -import isNumber from 'lodash/isNumber' - import { useLexicsStore } from 'features/LexicsStore' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup/store' import { getProfileUrl } from 'features/ProfileLink/helpers' import { SubscriptionType } from 'features/BuyMatchPopup/types' -import { getMatchInfo } from 'requests/getMatchInfo' -import { SubscriptionAction, getPaymentUrl } from 'requests/getPaymentUrl' +import { + getPaymentOTTUrl, + getPaymentPayUrl, + getMatchInfo, + SubscriptionAction, +} from 'requests' import { redirectToUrl } from 'helpers' @@ -88,7 +92,7 @@ export const useIframePayment = ({ } }, [close, error, id, matchLink, setIsOpenIframe, sportType]) - const paymentRequest = async () => { + const paymentRequestOTT = async () => { let url_cancel let url_return let action: SubscriptionAction @@ -106,7 +110,7 @@ export const useIframePayment = ({ break } - const payment: ResponsePaymentArray = await getPaymentUrl({ + const payment: ResponsePaymentArray = await getPaymentOTTUrl({ action, item: originalObject, product_name: `${pack} ${teams}`, @@ -117,6 +121,19 @@ export const useIframePayment = ({ setSrc(payment?.url || '') } + // новое апи для оплаты, в будущем все платежки переедут на него + // делаем оплату на новой вкладке, а не через iframe + const paymentRequestPay = async () => { + const payment = await getPaymentPayUrl({ + item: { + ...originalObject, + }, + url_return: `${window.location.origin}${matchLink}`, + }) + + redirectToUrl(payment.url) + } + if (paymentSystem === payments[ClientNames.Brasil]) { // eslint-disable-next-line window.onmessage = function (event) { @@ -126,6 +143,7 @@ export const useIframePayment = ({ } } + // отслеживание оплаты для Paymee useEffect(() => { let interval: ReturnType let timeout: ReturnType @@ -164,7 +182,14 @@ export const useIframePayment = ({ if (open) { (async () => { try { - await paymentRequest() + switch (paymentSystem) { + case PaymentSystem.PhonePe: + await paymentRequestPay() + break + default: + await paymentRequestOTT() + break + } } catch (err) { setError('error_payment_unsuccessful') } diff --git a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx index 2fcec4fc..226e38df 100644 --- a/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx +++ b/src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx @@ -22,6 +22,7 @@ import { ArrowLoader } from 'features/ArrowLoader' import { Arrow } from 'features/HeaderFilters/components/DateFilter/styled' import { useAuthStore } from 'features/AuthStore' +import { ClientNames } from 'config/clients/types' import { IframePayment } from '../IframePayment' import { useBuyMatchPopupStore } from '../../store' @@ -73,20 +74,25 @@ export const PackageSelectionStep = () => { }, [cards, fetchCards]) const paymentSystem = useMemo(() => { - switch (countryCode?.country_code) { - case CountryCode.BR: + switch (true) { + case countryCode?.country_code === CountryCode.BR: return payments.brasil - case CountryCode.TN: + case countryCode?.country_code === CountryCode.TN: return payments.tunisia + case countryCode?.country_code === CountryCode.IN: + case client.name === ClientNames.India: + return payments.india default: return payments[client.name] } }, [countryCode]) const isIframePayment = useMemo(() => { - switch (countryCode?.country_code) { - case CountryCode.BR: - case CountryCode.TN: + switch (true) { + case countryCode?.country_code === CountryCode.BR: + case countryCode?.country_code === CountryCode.TN: + case countryCode?.country_code === CountryCode.IN: + case client.name === ClientNames.India: return true default: return false diff --git a/src/features/UserAccount/index.tsx b/src/features/UserAccount/index.tsx index 62563155..bd4f44ed 100644 --- a/src/features/UserAccount/index.tsx +++ b/src/features/UserAccount/index.tsx @@ -54,13 +54,15 @@ const UserAccount = () => { {!isLffClient && ( - - - + {!client.userAccountCardsHidden && ( + + + + )} => { + const config = { + body: { + item, + url_return, + }, + } + + return callApi({ + config, + url: `${PAYMENT_API_URL}/api/v2/phonepe/create-payment-link`, + }) +} diff --git a/src/requests/index.tsx b/src/requests/index.tsx index 0613c71a..b11eb223 100644 --- a/src/requests/index.tsx +++ b/src/requests/index.tsx @@ -34,3 +34,5 @@ export * from './getMatchParticipants' export * from './getStatsEvents' export * from './getTokenVirtualUser' export * from './checkDevice' +export * from './getPaymentOTTUrl' +export * from './getPaymentPayUrl'