From 1e7ffc7366c39c080922e64bc5d53582687ecd5c Mon Sep 17 00:00:00 2001 From: Rakov Date: Wed, 21 Jun 2023 16:05:07 +0300 Subject: [PATCH] fix(#622): annual access --- .../components/IframePayment/hooks.tsx | 20 ++++++++++++++----- src/requests/getPaymentUrl.tsx | 7 ++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx b/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx index 2cd13cc4..54b3f4d3 100644 --- a/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx +++ b/src/features/BuyMatchPopup/components/IframePayment/hooks.tsx @@ -2,6 +2,7 @@ import { MouseEvent, useCallback, useEffect, + useMemo, useState, } from 'react' @@ -14,9 +15,10 @@ 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 { getPaymentUrl } from 'requests/getPaymentUrl' +import { SubscriptionAction, getPaymentUrl } from 'requests/getPaymentUrl' import { redirectToUrl } from 'helpers' @@ -49,6 +51,7 @@ export const useIframePayment = ({ nameLexic, originalObject, pass, + type, } = selectedPackage const teams = isNumber(nameLexic) ? translate(String(nameLexic)) : name @@ -60,6 +63,13 @@ export const useIframePayment = ({ sportType, }) + const defaultAction: SubscriptionAction = useMemo(() => { + if (type === SubscriptionType.Month) { + return SubscriptionAction.CreateSubscription + } + return SubscriptionAction.OnePayment + }, [type]) + const closePopup = useCallback(async (e?: MouseEvent) => { e?.stopPropagation() @@ -81,18 +91,18 @@ export const useIframePayment = ({ const paymentRequest = async () => { let url_cancel let url_return - let action: Parameters[0]['action'] + let action: SubscriptionAction switch (paymentSystem) { case PaymentSystem.Paymee: - url_cancel = `${window.origin}/failed-paymee` + url_cancel = `${window.origin}${PAGES.failedPaymee}` url_return = null // paymee не умеет работать с подписками - action = 'one_payment' + action = SubscriptionAction.OnePayment break default: url_return = `${window.location.origin}${PAGES.thanksForSubscribe}` - action = pass === 'pass_match_access' ? 'one_payment' : 'create_subscription' + action = defaultAction break } diff --git a/src/requests/getPaymentUrl.tsx b/src/requests/getPaymentUrl.tsx index 325a513d..781a3a81 100644 --- a/src/requests/getPaymentUrl.tsx +++ b/src/requests/getPaymentUrl.tsx @@ -4,8 +4,13 @@ import { callApi } from 'helpers' import type { SubscriptionResponse } from 'requests/getSubscriptions' +export enum SubscriptionAction { + CreateSubscription = 'create_subscription', + OnePayment = 'one_payment' +} + type Props = { - action: 'one_payment' | 'create_subscription', + action: SubscriptionAction, item: SubscriptionResponse, product_name: string, service: string,