|
|
|
|
@ -1,22 +1,35 @@ |
|
|
|
|
/* eslint-disable no-console */ |
|
|
|
|
import { |
|
|
|
|
MouseEvent, |
|
|
|
|
useCallback, |
|
|
|
|
useEffect, |
|
|
|
|
useMemo, |
|
|
|
|
useState, |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import { PAGES, ProfileTypes } from 'config' |
|
|
|
|
import { ClientNames } from 'config/clients/types' |
|
|
|
|
import { payments, PaymentSystem } from 'config/payments' |
|
|
|
|
// import { useQuery } from 'react-query'
|
|
|
|
|
|
|
|
|
|
import isNumber from 'lodash/isNumber' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
PAGES, |
|
|
|
|
ProfileTypes, |
|
|
|
|
// querieKeys,
|
|
|
|
|
} from 'config' |
|
|
|
|
import { ClientNames } from 'config/clients/types' |
|
|
|
|
import { payments, PaymentSystem } from 'config/payments' |
|
|
|
|
|
|
|
|
|
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 { getPaymentUrl } from 'requests/getPaymentUrl' |
|
|
|
|
import { |
|
|
|
|
getPaymentOTTUrl, |
|
|
|
|
getPaymentPayUrl, |
|
|
|
|
getMatchInfo, |
|
|
|
|
SubscriptionAction, |
|
|
|
|
} from 'requests' |
|
|
|
|
|
|
|
|
|
import { redirectToUrl } from 'helpers' |
|
|
|
|
|
|
|
|
|
@ -49,6 +62,7 @@ export const useIframePayment = ({ |
|
|
|
|
nameLexic, |
|
|
|
|
originalObject, |
|
|
|
|
pass, |
|
|
|
|
type, |
|
|
|
|
} = selectedPackage |
|
|
|
|
|
|
|
|
|
const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name |
|
|
|
|
@ -60,6 +74,13 @@ export const useIframePayment = ({ |
|
|
|
|
sportType, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const defaultAction: SubscriptionAction = useMemo(() => { |
|
|
|
|
if (type === SubscriptionType.Month) { |
|
|
|
|
return SubscriptionAction.CreateSubscription |
|
|
|
|
} |
|
|
|
|
return SubscriptionAction.OnePayment |
|
|
|
|
}, [type]) |
|
|
|
|
|
|
|
|
|
const closePopup = useCallback(async (e?: MouseEvent) => { |
|
|
|
|
e?.stopPropagation() |
|
|
|
|
|
|
|
|
|
@ -78,25 +99,25 @@ export const useIframePayment = ({ |
|
|
|
|
} |
|
|
|
|
}, [close, error, id, matchLink, setIsOpenIframe, sportType]) |
|
|
|
|
|
|
|
|
|
const paymentRequest = async () => { |
|
|
|
|
const paymentRequestOTT = async () => { |
|
|
|
|
let url_cancel |
|
|
|
|
let url_return |
|
|
|
|
let action: Parameters<typeof getPaymentUrl>[0]['action'] |
|
|
|
|
let action: SubscriptionAction |
|
|
|
|
|
|
|
|
|
switch (paymentSystem) { |
|
|
|
|
case PaymentSystem.Paymee: |
|
|
|
|
url_cancel = `${window.origin}/failed-paymee` |
|
|
|
|
url_cancel = `${window.origin}${PAGES.failedPaymee}` |
|
|
|
|
url_return = null |
|
|
|
|
// paymee не умеет работать с подписками
|
|
|
|
|
action = 'one_payment' |
|
|
|
|
action = SubscriptionAction.OnePayment |
|
|
|
|
break |
|
|
|
|
default: |
|
|
|
|
url_return = `${window.location.origin}${PAGES.thanksForSubscribe}` |
|
|
|
|
action = pass === 'pass_match_access' ? 'one_payment' : 'create_subscription' |
|
|
|
|
action = defaultAction |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payment: ResponsePaymentArray = await getPaymentUrl({ |
|
|
|
|
const payment: ResponsePaymentArray = await getPaymentOTTUrl({ |
|
|
|
|
action, |
|
|
|
|
item: originalObject, |
|
|
|
|
product_name: `${pack} ${teams}`, |
|
|
|
|
@ -107,7 +128,23 @@ export const useIframePayment = ({ |
|
|
|
|
setSrc(payment?.url || '') |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (paymentSystem === payments[ClientNames.Brasil]) { |
|
|
|
|
// новое апи для оплаты, в будущем все платежки переедут на него
|
|
|
|
|
// временно делаем оплату на новой вкладке, а не через iframe
|
|
|
|
|
const paymentRequestPay = async () => { |
|
|
|
|
const payment = await getPaymentPayUrl({ |
|
|
|
|
item: { |
|
|
|
|
...originalObject, |
|
|
|
|
}, |
|
|
|
|
// url_return: `${window.location.origin}${PAGES.thanksForSubscribe}`,
|
|
|
|
|
url_return: `${window.location.origin}${matchLink}`, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// setSrc(payment?.url || '')
|
|
|
|
|
redirectToUrl(payment.url) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (paymentSystem === payments.brasil |
|
|
|
|
|| paymentSystem === payments.india) { |
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
window.onmessage = function (event) { |
|
|
|
|
if (event.data === 'close') { |
|
|
|
|
@ -116,6 +153,7 @@ export const useIframePayment = ({ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// отслеживание оплаты для Paymee
|
|
|
|
|
useEffect(() => { |
|
|
|
|
let interval: ReturnType<typeof setInterval> |
|
|
|
|
let timeout: ReturnType<typeof setTimeout> |
|
|
|
|
@ -150,11 +188,43 @@ export const useIframePayment = ({ |
|
|
|
|
} |
|
|
|
|
}, [closePopup, paymentSystem]) |
|
|
|
|
|
|
|
|
|
// временное решение для отслеживания доступа к матчу
|
|
|
|
|
// для платежки PhonePe
|
|
|
|
|
// const { data: matchAccess } = useQuery({
|
|
|
|
|
// queryFn: async () => {
|
|
|
|
|
// if (paymentSystem === PaymentSystem.PhonePe) {
|
|
|
|
|
// const matchInfo = await getMatchInfo(sportType, id)
|
|
|
|
|
// return matchInfo?.access
|
|
|
|
|
// }
|
|
|
|
|
// return false
|
|
|
|
|
// },
|
|
|
|
|
// queryKey: querieKeys.getMatchInfo,
|
|
|
|
|
// refetchInterval: 5000,
|
|
|
|
|
// })
|
|
|
|
|
// console.log('access', matchAccess)
|
|
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
|
// if (matchAccess) {
|
|
|
|
|
// setIsPaymentProcessing(false)
|
|
|
|
|
// setIsOpenIframe(false)
|
|
|
|
|
// setError('')
|
|
|
|
|
// close()
|
|
|
|
|
// redirectToUrl(matchLink)
|
|
|
|
|
// }
|
|
|
|
|
// }, [matchAccess, close, matchLink, setIsOpenIframe])
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (open) { |
|
|
|
|
(async () => { |
|
|
|
|
try { |
|
|
|
|
await paymentRequest() |
|
|
|
|
switch (paymentSystem) { |
|
|
|
|
case PaymentSystem.PhonePe: |
|
|
|
|
await paymentRequestPay() |
|
|
|
|
break |
|
|
|
|
default: |
|
|
|
|
await paymentRequestOTT() |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
setError('error_payment_unsuccessful') |
|
|
|
|
} |
|
|
|
|
|