fix(#622): india payment phonePe

pull/265/head
Rakov 3 years ago committed by Gitea
parent cc595acfd4
commit 551460fc14
  1. 1
      src/config/clients/india.tsx
  2. 1
      src/config/clients/tunisia.tsx
  3. 1
      src/config/clients/types.tsx
  4. 4
      src/config/payments.tsx
  5. 39
      src/features/BuyMatchPopup/components/IframePayment/hooks.tsx
  6. 18
      src/features/BuyMatchPopup/components/PackageSelectionStep/index.tsx
  7. 16
      src/features/UserAccount/index.tsx
  8. 2
      src/requests/getMatchInfo.tsx
  9. 2
      src/requests/getPaymentOTTUrl.tsx
  10. 31
      src/requests/getPaymentPayUrl.tsx
  11. 2
      src/requests/index.tsx

@ -18,4 +18,5 @@ export const india: ClientConfig = {
}, },
disabledHighlights: true, disabledHighlights: true,
name: ClientNames.India, name: ClientNames.India,
userAccountCardsHidden: true,
} }

@ -60,4 +60,5 @@ export const tunisia: ClientConfig = {
}, },
termsLink: '/terms-and-conditions?client_id=insports-ott-web', termsLink: '/terms-and-conditions?client_id=insports-ott-web',
title: 'Diwan Sport - The home of Tunisian Ligue Professionnelle 1', title: 'Diwan Sport - The home of Tunisian Ligue Professionnelle 1',
userAccountCardsHidden: true,
} }

@ -64,5 +64,6 @@ export type ClientConfig = {
}, },
termsLink: string, termsLink: string,
title: string, title: string,
userAccountCardsHidden?: boolean,
userAccountLinksDisabled?: boolean, userAccountLinksDisabled?: boolean,
} }

@ -3,7 +3,7 @@ import { ClientNames } from './clients/types'
export enum PaymentSystem { export enum PaymentSystem {
PagBrazil = 'pag_brasil', PagBrazil = 'pag_brasil',
Paymee = 'paymee', Paymee = 'paymee',
Paytm = 'paytm', PhonePe = 'phonePe',
Stripe = 'stripe' Stripe = 'stripe'
} }
@ -20,7 +20,7 @@ type PaymentsType = {
export const payments: PaymentsType = { export const payments: PaymentsType = {
[ClientNames.Tunisia]: PaymentSystem.Paymee, [ClientNames.Tunisia]: PaymentSystem.Paymee,
[ClientNames.Brasil]: PaymentSystem.PagBrazil, [ClientNames.Brasil]: PaymentSystem.PagBrazil,
[ClientNames.India]: PaymentSystem.Paytm, [ClientNames.India]: PaymentSystem.PhonePe,
[ClientNames.Insports]: PaymentSystem.Stripe, [ClientNames.Insports]: PaymentSystem.Stripe,
[ClientNames.Instat]: PaymentSystem.Stripe, [ClientNames.Instat]: PaymentSystem.Stripe,
[ClientNames.Facr]: PaymentSystem.Stripe, [ClientNames.Facr]: PaymentSystem.Stripe,

@ -6,19 +6,23 @@ import {
useState, useState,
} from 'react' } from 'react'
import isNumber from 'lodash/isNumber'
import { PAGES, ProfileTypes } from 'config' import { PAGES, ProfileTypes } from 'config'
import { ClientNames } from 'config/clients/types' import { ClientNames } from 'config/clients/types'
import { payments, PaymentSystem } from 'config/payments' import { payments, PaymentSystem } from 'config/payments'
import isNumber from 'lodash/isNumber'
import { useLexicsStore } from 'features/LexicsStore' import { useLexicsStore } from 'features/LexicsStore'
import { useBuyMatchPopupStore } from 'features/BuyMatchPopup/store' import { useBuyMatchPopupStore } from 'features/BuyMatchPopup/store'
import { getProfileUrl } from 'features/ProfileLink/helpers' import { getProfileUrl } from 'features/ProfileLink/helpers'
import { SubscriptionType } from 'features/BuyMatchPopup/types' import { SubscriptionType } from 'features/BuyMatchPopup/types'
import { getMatchInfo } from 'requests/getMatchInfo' import {
import { SubscriptionAction, getPaymentUrl } from 'requests/getPaymentUrl' getPaymentOTTUrl,
getPaymentPayUrl,
getMatchInfo,
SubscriptionAction,
} from 'requests'
import { redirectToUrl } from 'helpers' import { redirectToUrl } from 'helpers'
@ -88,7 +92,7 @@ export const useIframePayment = ({
} }
}, [close, error, id, matchLink, setIsOpenIframe, sportType]) }, [close, error, id, matchLink, setIsOpenIframe, sportType])
const paymentRequest = async () => { const paymentRequestOTT = async () => {
let url_cancel let url_cancel
let url_return let url_return
let action: SubscriptionAction let action: SubscriptionAction
@ -106,7 +110,7 @@ export const useIframePayment = ({
break break
} }
const payment: ResponsePaymentArray = await getPaymentUrl({ const payment: ResponsePaymentArray = await getPaymentOTTUrl({
action, action,
item: originalObject, item: originalObject,
product_name: `${pack} ${teams}`, product_name: `${pack} ${teams}`,
@ -117,6 +121,19 @@ export const useIframePayment = ({
setSrc(payment?.url || '') 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]) { if (paymentSystem === payments[ClientNames.Brasil]) {
// eslint-disable-next-line // eslint-disable-next-line
window.onmessage = function (event) { window.onmessage = function (event) {
@ -126,6 +143,7 @@ export const useIframePayment = ({
} }
} }
// отслеживание оплаты для Paymee
useEffect(() => { useEffect(() => {
let interval: ReturnType<typeof setInterval> let interval: ReturnType<typeof setInterval>
let timeout: ReturnType<typeof setTimeout> let timeout: ReturnType<typeof setTimeout>
@ -164,7 +182,14 @@ export const useIframePayment = ({
if (open) { if (open) {
(async () => { (async () => {
try { try {
await paymentRequest() switch (paymentSystem) {
case PaymentSystem.PhonePe:
await paymentRequestPay()
break
default:
await paymentRequestOTT()
break
}
} catch (err) { } catch (err) {
setError('error_payment_unsuccessful') setError('error_payment_unsuccessful')
} }

@ -22,6 +22,7 @@ import { ArrowLoader } from 'features/ArrowLoader'
import { Arrow } from 'features/HeaderFilters/components/DateFilter/styled' import { Arrow } from 'features/HeaderFilters/components/DateFilter/styled'
import { useAuthStore } from 'features/AuthStore' import { useAuthStore } from 'features/AuthStore'
import { ClientNames } from 'config/clients/types'
import { IframePayment } from '../IframePayment' import { IframePayment } from '../IframePayment'
import { useBuyMatchPopupStore } from '../../store' import { useBuyMatchPopupStore } from '../../store'
@ -73,20 +74,25 @@ export const PackageSelectionStep = () => {
}, [cards, fetchCards]) }, [cards, fetchCards])
const paymentSystem = useMemo(() => { const paymentSystem = useMemo(() => {
switch (countryCode?.country_code) { switch (true) {
case CountryCode.BR: case countryCode?.country_code === CountryCode.BR:
return payments.brasil return payments.brasil
case CountryCode.TN: case countryCode?.country_code === CountryCode.TN:
return payments.tunisia return payments.tunisia
case countryCode?.country_code === CountryCode.IN:
case client.name === ClientNames.India:
return payments.india
default: default:
return payments[client.name] return payments[client.name]
} }
}, [countryCode]) }, [countryCode])
const isIframePayment = useMemo(() => { const isIframePayment = useMemo(() => {
switch (countryCode?.country_code) { switch (true) {
case CountryCode.BR: case countryCode?.country_code === CountryCode.BR:
case CountryCode.TN: case countryCode?.country_code === CountryCode.TN:
case countryCode?.country_code === CountryCode.IN:
case client.name === ClientNames.India:
return true return true
default: default:
return false return false

@ -54,13 +54,15 @@ const UserAccount = () => {
</StyledLink> </StyledLink>
{!isLffClient && ( {!isLffClient && (
<Fragment> <Fragment>
<StyledLink {!client.userAccountCardsHidden && (
disabled={user?.profile?.country_code === 'BR'} <StyledLink
to={`${PAGES.useraccount}/bank-cards`} disabled={user?.profile?.country_code === 'BR'}
id='personal_cards' to={`${PAGES.useraccount}/bank-cards`}
> id='personal_cards'
<T9n t='bank_card' /> >
</StyledLink> <T9n t='bank_card' />
</StyledLink>
)}
<StyledLink <StyledLink
to={`${PAGES.useraccount}/subscriptions`} to={`${PAGES.useraccount}/subscriptions`}
id='personal_subscriptions' id='personal_subscriptions'

@ -50,7 +50,7 @@ export enum MatchStatuses {
} }
export type MatchInfo = { export type MatchInfo = {
access?: boolean, access?: boolean | null,
c_match_calc_status: MatchStatuses | null, c_match_calc_status: MatchStatuses | null,
calc: boolean, calc: boolean,
country: TournamentType, country: TournamentType,

@ -18,7 +18,7 @@ type Props = {
url_return?: string | null, url_return?: string | null,
} }
export const getPaymentUrl = async ({ export const getPaymentOTTUrl = async ({
action, action,
item, item,
product_name, product_name,

@ -0,0 +1,31 @@
import { PAYMENT_API_URL } from 'config'
import { callApi } from 'helpers'
import type { SubscriptionResponse } from 'requests/getSubscriptions'
type Props = {
item: SubscriptionResponse,
url_return?: string | null,
}
type PaymentResponse = {
url: string,
}
export const getPaymentPayUrl = async ({
item,
url_return,
}: Props): Promise<PaymentResponse> => {
const config = {
body: {
item,
url_return,
},
}
return callApi({
config,
url: `${PAYMENT_API_URL}/api/v2/phonepe/create-payment-link`,
})
}

@ -34,3 +34,5 @@ export * from './getMatchParticipants'
export * from './getStatsEvents' export * from './getStatsEvents'
export * from './getTokenVirtualUser' export * from './getTokenVirtualUser'
export * from './checkDevice' export * from './checkDevice'
export * from './getPaymentOTTUrl'
export * from './getPaymentPayUrl'

Loading…
Cancel
Save