|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
/* eslint-disable no-console */ |
|
|
|
|
import { |
|
|
|
|
MouseEvent, |
|
|
|
|
useCallback, |
|
|
|
|
@ -6,19 +7,29 @@ import { |
|
|
|
|
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 { SubscriptionAction, getPaymentUrl } from 'requests/getPaymentUrl' |
|
|
|
|
import { |
|
|
|
|
getPaymentOTTUrl, |
|
|
|
|
getPaymentPayUrl, |
|
|
|
|
getMatchInfo, |
|
|
|
|
SubscriptionAction, |
|
|
|
|
} from 'requests' |
|
|
|
|
|
|
|
|
|
import { redirectToUrl } from 'helpers' |
|
|
|
|
|
|
|
|
|
@ -88,7 +99,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 +117,7 @@ export const useIframePayment = ({ |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const payment: ResponsePaymentArray = await getPaymentUrl({ |
|
|
|
|
const payment: ResponsePaymentArray = await getPaymentOTTUrl({ |
|
|
|
|
action, |
|
|
|
|
item: originalObject, |
|
|
|
|
product_name: `${pack} ${teams}`, |
|
|
|
|
@ -117,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') { |
|
|
|
|
@ -126,6 +153,7 @@ export const useIframePayment = ({ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// отслеживание оплаты для Paymee
|
|
|
|
|
useEffect(() => { |
|
|
|
|
let interval: ReturnType<typeof setInterval> |
|
|
|
|
let timeout: ReturnType<typeof setTimeout> |
|
|
|
|
@ -160,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') |
|
|
|
|
} |
|
|
|
|
|