fix(#622): india payment phonePe #250
Merged
andrey.dekterev
merged 1 commits from in-622-india-payment-phonePe into develop 3 years ago
@ -6,19 +6,23 @@ import { |
||||
useState, |
||||
} from 'react' |
||||
|
||||
import isNumber from 'lodash/isNumber' |
||||
|
||||
import { PAGES, ProfileTypes } from 'config' |
||||
import { ClientNames } from 'config/clients/types' |
||||
import { payments, PaymentSystem } from 'config/payments' |
||||
|
||||
import isNumber from 'lodash/isNumber' |
||||
|
||||
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 +92,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 +110,7 @@ export const useIframePayment = ({ |
||||
break |
||||
} |
||||
|
||||
const payment: ResponsePaymentArray = await getPaymentUrl({ |
||||
const payment: ResponsePaymentArray = await getPaymentOTTUrl({ |
||||
action, |
||||
item: originalObject, |
||||
product_name: `${pack} ${teams}`, |
||||
@ -117,6 +121,19 @@ export const useIframePayment = ({ |
||||
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]) { |
||||
// eslint-disable-next-line
|
||||
window.onmessage = function (event) { |
||||
@ -126,6 +143,7 @@ export const useIframePayment = ({ |
||||
} |
||||
} |
||||
|
||||
// отслеживание оплаты для Paymee
|
||||
useEffect(() => { |
||||
let interval: ReturnType<typeof setInterval> |
||||
|
andrey.dekterev
commented 3 years ago
Review
у нас есть useInterval |
||||
let timeout: ReturnType<typeof setTimeout> |
||||
@ -164,7 +182,14 @@ export const useIframePayment = ({ |
||||
if (open) { |
||||
(async () => { |
||||
try { |
||||
await paymentRequest() |
||||
switch (paymentSystem) { |
||||
case PaymentSystem.PhonePe: |
||||
await paymentRequestPay() |
||||
break |
||||
default: |
||||
await paymentRequestOTT() |
||||
break |
||||
} |
||||
} catch (err) { |
||||
setError('error_payment_unsuccessful') |
||||
} |
||||
|
||||
@ -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`, |
||||
}) |
||||
} |
||||
Loading…
Reference in new issue
а вот это, такое ощущение, что лучше сделать через стейт или объект хотя бы