fix(#622): annual access

pull/261/head
Rakov 3 years ago committed by Gitea
parent cf8515fe9e
commit 1e7ffc7366
  1. 20
      src/features/BuyMatchPopup/components/IframePayment/hooks.tsx
  2. 7
      src/requests/getPaymentUrl.tsx

@ -2,6 +2,7 @@ import {
MouseEvent, MouseEvent,
useCallback, useCallback,
useEffect, useEffect,
useMemo,
useState, useState,
} from 'react' } from 'react'
@ -14,9 +15,10 @@ 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 { getMatchInfo } from 'requests/getMatchInfo' import { getMatchInfo } from 'requests/getMatchInfo'
import { getPaymentUrl } from 'requests/getPaymentUrl' import { SubscriptionAction, getPaymentUrl } from 'requests/getPaymentUrl'
import { redirectToUrl } from 'helpers' import { redirectToUrl } from 'helpers'
@ -49,6 +51,7 @@ export const useIframePayment = ({
nameLexic, nameLexic,
originalObject, originalObject,
pass, pass,
type,
} = selectedPackage } = selectedPackage
const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name
@ -60,6 +63,13 @@ export const useIframePayment = ({
sportType, sportType,
}) })
const defaultAction: SubscriptionAction = useMemo(() => {
if (type === SubscriptionType.Month) {
return SubscriptionAction.CreateSubscription
}
return SubscriptionAction.OnePayment
}, [type])
const closePopup = useCallback(async (e?: MouseEvent) => { const closePopup = useCallback(async (e?: MouseEvent) => {
e?.stopPropagation() e?.stopPropagation()
@ -81,18 +91,18 @@ export const useIframePayment = ({
const paymentRequest = async () => { const paymentRequest = async () => {
let url_cancel let url_cancel
let url_return let url_return
let action: Parameters<typeof getPaymentUrl>[0]['action'] let action: SubscriptionAction
switch (paymentSystem) { switch (paymentSystem) {
case PaymentSystem.Paymee: case PaymentSystem.Paymee:
url_cancel = `${window.origin}/failed-paymee` url_cancel = `${window.origin}${PAGES.failedPaymee}`
url_return = null url_return = null
// paymee не умеет работать с подписками // paymee не умеет работать с подписками
action = 'one_payment' action = SubscriptionAction.OnePayment
break break
default: default:
url_return = `${window.location.origin}${PAGES.thanksForSubscribe}` url_return = `${window.location.origin}${PAGES.thanksForSubscribe}`
action = pass === 'pass_match_access' ? 'one_payment' : 'create_subscription' action = defaultAction
break break
} }

@ -4,8 +4,13 @@ import { callApi } from 'helpers'
import type { SubscriptionResponse } from 'requests/getSubscriptions' import type { SubscriptionResponse } from 'requests/getSubscriptions'
export enum SubscriptionAction {
CreateSubscription = 'create_subscription',
OnePayment = 'one_payment'
}
type Props = { type Props = {
action: 'one_payment' | 'create_subscription', action: SubscriptionAction,
item: SubscriptionResponse, item: SubscriptionResponse,
product_name: string, product_name: string,
service: string, service: string,

Loading…
Cancel
Save