|
|
|
|
@ -1,33 +1,51 @@ |
|
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
|
|
|
|
|
|
import { Loader } from 'features/Loader' |
|
|
|
|
import { useLexicsStore } from 'features/LexicsStore' |
|
|
|
|
|
|
|
|
|
import { MatchPackage } from 'features/BuyMatchPopup/types' |
|
|
|
|
|
|
|
|
|
import { getBrazilPaymentUrl } from 'requests/getBrazilPaymentUrl' |
|
|
|
|
import type { SubscriptionResponse } from 'requests/getSubscriptions' |
|
|
|
|
|
|
|
|
|
import isNumber from 'lodash/isNumber' |
|
|
|
|
|
|
|
|
|
import { ScModal, LoaderWrapper } from './styled' |
|
|
|
|
|
|
|
|
|
type Props = { |
|
|
|
|
item: SubscriptionResponse, |
|
|
|
|
open: boolean, |
|
|
|
|
product_name: string, |
|
|
|
|
selectedPackage: MatchPackage, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ResponsePayment = { |
|
|
|
|
url: string, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ResponsePaymentArray =Array<ResponsePayment | null> |
|
|
|
|
|
|
|
|
|
export const BrazilPayment = ({ |
|
|
|
|
item, |
|
|
|
|
open, |
|
|
|
|
product_name, |
|
|
|
|
selectedPackage, |
|
|
|
|
}: Props) => { |
|
|
|
|
const { |
|
|
|
|
name, |
|
|
|
|
nameLexic, |
|
|
|
|
originalObject, |
|
|
|
|
pass, |
|
|
|
|
} = selectedPackage |
|
|
|
|
const [src, setSrc] = useState('') |
|
|
|
|
const { translate } = useLexicsStore() |
|
|
|
|
const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name |
|
|
|
|
const pack = translate(String(pass)) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (open) { |
|
|
|
|
(async () => { |
|
|
|
|
const json: any = await getBrazilPaymentUrl({ item, product_name }) |
|
|
|
|
setSrc(json[0]?.url) |
|
|
|
|
const json: ResponsePaymentArray = await getBrazilPaymentUrl({ item: originalObject, product_name: `${pack} ${teams}` }) |
|
|
|
|
setSrc(json[0]?.url || '') |
|
|
|
|
})() |
|
|
|
|
} |
|
|
|
|
}, [item, open, product_name]) |
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [selectedPackage, open]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<ScModal isOpen={open} withCloseButton={false}> |
|
|
|
|
|