fix(#188): tunisia payment part 2

pull/25/head
Rakov Roman 3 years ago committed by Gitea
parent 7a7b597586
commit 7a2277812c
  1. 4
      src/config/clients/tunisia.tsx
  2. 1
      src/config/currencies.tsx
  3. 23
      src/config/payments.tsx
  4. 67
      src/features/BuyMatchPopup/components/IframePayment/hooks.tsx
  5. 6
      src/features/BuyMatchPopup/components/IframePayment/index.tsx
  6. 6
      src/requests/getPaymentUrl.tsx

@ -31,7 +31,7 @@ export const tunisia: ClientConfig = {
#2AB7AA 3.27%, #2AB7AA 3.27%,
#02505C 43.69%, #0B2E4D 100%); #02505C 43.69%, #0B2E4D 100%);
`, `,
logo: 'tunisia-logo.svg', logo: 'tunis-logo.svg',
logoHeight: 1.922, logoHeight: 1.922,
logoLeft: 1.1, logoLeft: 1.1,
logoTop: 1.74, logoTop: 1.74,
@ -54,5 +54,5 @@ export const tunisia: ClientConfig = {
`, `,
}, },
termsLink: '/', termsLink: '/',
title: '', title: 'Diwan Sport - The home of Tunisian Ligue Professionnelle 1',
} }

@ -12,5 +12,6 @@ export const currencySymbols = {
KZT: '₸', KZT: '₸',
MDL: 'L', MDL: 'L',
RUB: '₽', RUB: '₽',
TND: 'DT',
USD: '$', USD: '$',
} as const } as const

@ -1,15 +1,22 @@
import { ClientNames } from './clients/types' import { ClientNames } from './clients/types'
export enum PaymentSystem {
PagBrazil = 'pag_brasil',
Paymee = 'paymee',
Paytm = 'paytm',
Stripe = 'stripe'
}
type PaymentsType = { type PaymentsType = {
[key in ClientNames]: string [key in ClientNames]: PaymentSystem
} }
export const payments: PaymentsType = { export const payments: PaymentsType = {
[ClientNames.Tunisia]: 'paymee', [ClientNames.Tunisia]: PaymentSystem.Paymee,
brasil: 'pag_brasil', brasil: PaymentSystem.PagBrazil,
[ClientNames.India]: 'paytm', [ClientNames.India]: PaymentSystem.Paytm,
[ClientNames.Insports]: 'stripe', [ClientNames.Insports]: PaymentSystem.Stripe,
[ClientNames.Instat]: 'stripe', [ClientNames.Instat]: PaymentSystem.Stripe,
[ClientNames.Facr]: 'stripe', [ClientNames.Facr]: PaymentSystem.Stripe,
[ClientNames.Lff]: 'stripe', [ClientNames.Lff]: PaymentSystem.Stripe,
} }

@ -1,14 +1,15 @@
import { import {
MouseEvent, MouseEvent,
useCallback,
useEffect, useEffect,
useState, useState,
} from 'react' } from 'react'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { ProfileTypes } from 'config' import { PAGES, ProfileTypes } from 'config'
import { ClientNames } from 'config/clients/types' import { ClientNames } from 'config/clients/types'
import { payments } from 'config/payments' import { payments, PaymentSystem } from 'config/payments'
import isNumber from 'lodash/isNumber' import isNumber from 'lodash/isNumber'
@ -59,7 +60,7 @@ export const useIframePayment = ({
sportType, sportType,
}) })
const closePopup = async (e?: MouseEvent) => { const closePopup = useCallback(async (e?: MouseEvent) => {
e?.stopPropagation() e?.stopPropagation()
setIsOpenIframe(false) setIsOpenIframe(false)
setError('') setError('')
@ -69,35 +70,28 @@ export const useIframePayment = ({
close() close()
history.push(matchLink) history.push(matchLink)
} }
} }, [close, history, id, matchLink, setIsOpenIframe, sportType])
// const paymentPaymee = async () => {
// const response: ResponseTypeTunis = await getTunisPaymentToken({
// amount: originalObject.price,
// note: `${pack} ${teams}`,
// vendor: 5020,
// })
// setSrc(`https://sandbox.paymee.tn/gateway/${response?.data.token}` || '')
//
// window.addEventListener(
// 'message',
// (event) => {
// if (event.data.event_id === 'paymee.complete') {
// // Execute Step 3
// setSrc(`https://sandbox.paymee.tn/api/v1/payments/${response?.data.token}/check`)
// }
// }, false,
// )
// }
const paymentRequest = async () => { const paymentRequest = async () => {
const json: ResponsePaymentArray = await getPaymentUrl({ let url_return
switch (paymentSystem) {
case PaymentSystem.Paymee:
url_return = undefined
break
default:
url_return = `${window.location.origin}${PAGES.thanksForSubscribe}`
break
}
const payment: ResponsePaymentArray = await getPaymentUrl({
action: pass === 'pass_match_access' ? 'one_payment' : 'create_subscription', action: pass === 'pass_match_access' ? 'one_payment' : 'create_subscription',
item: originalObject, item: originalObject,
product_name: `${pack} ${teams}`, product_name: `${pack} ${teams}`,
service: paymentSystem, service: paymentSystem,
url_return,
}) })
setSrc(json?.url || '') setSrc(payment?.url || '')
} }
if (paymentSystem === payments[ClientNames.Brasil]) { if (paymentSystem === payments[ClientNames.Brasil]) {
@ -107,18 +101,29 @@ export const useIframePayment = ({
closePopup() closePopup()
} }
} }
}
useEffect(() => {
const paymentCallback = (event: any) => {
if (event.data.event_id === 'paymee.complete') {
closePopup()
}
}
if (paymentSystem === payments[ClientNames.Tunisia]) { if (paymentSystem === payments[ClientNames.Tunisia]) {
window.addEventListener( window.addEventListener(
'message', 'message',
(event) => { paymentCallback,
if (event.data.event_id === 'paymee.complete') { false,
closePopup()
}
}, false,
) )
} }
} return () => {
window.removeEventListener(
'message',
paymentCallback,
false,
)
}
}, [closePopup, paymentSystem])
useEffect(() => { useEffect(() => {
if (open) { if (open) {

@ -2,6 +2,8 @@ import { Loader } from 'features/Loader'
import { MatchPackage, Match } from 'features/BuyMatchPopup/types' import { MatchPackage, Match } from 'features/BuyMatchPopup/types'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { PaymentSystem } from 'config/payments'
import { useIframePayment } from './hooks' import { useIframePayment } from './hooks'
import { import {
@ -12,7 +14,7 @@ import {
export type Props = { export type Props = {
match: Match, match: Match,
open: boolean, open: boolean,
paymentSystem: string, paymentSystem: PaymentSystem,
selectedPackage: MatchPackage, selectedPackage: MatchPackage,
setIsOpenIframe: (open: boolean) => void, setIsOpenIframe: (open: boolean) => void,
} }
@ -40,7 +42,7 @@ export const IframePayment = ({
<ScModal isOpen={open} withCloseButton close={closePopup}> <ScModal isOpen={open} withCloseButton close={closePopup}>
{src && open ? ( {src && open ? (
<iframe <iframe
title='BrazilPayment' title='Payment'
frameBorder='0' frameBorder='0'
src={src} src={src}
height={600} height={600}

@ -1,4 +1,4 @@
import { API_ROOT, PAGES } from 'config' import { API_ROOT } from 'config'
import { callApi } from 'helpers' import { callApi } from 'helpers'
@ -9,6 +9,7 @@ type Props = {
item: SubscriptionResponse, item: SubscriptionResponse,
product_name: string, product_name: string,
service: string, service: string,
url_return?: string,
} }
export const getPaymentUrl = async ({ export const getPaymentUrl = async ({
@ -16,13 +17,14 @@ export const getPaymentUrl = async ({
item, item,
product_name, product_name,
service, service,
url_return,
}: Props) => { }: Props) => {
const config = { const config = {
body: { body: {
action, action,
data: { data: {
item: { ...item, product_name }, item: { ...item, product_name },
url_return: `${window.location.origin}${PAGES.thanksForSubscribe}`, url_return,
}, },
service, service,
}, },

Loading…
Cancel
Save