Merge branch 'clone' into 'main'
fix: paymentRequest See merge request witapp/aura-webapp!17
This commit is contained in:
commit
35c2120ca2
@ -6,19 +6,16 @@ import {
|
|||||||
} from "@stripe/react-stripe-js";
|
} from "@stripe/react-stripe-js";
|
||||||
import { PaymentRequest } from "@stripe/stripe-js";
|
import { PaymentRequest } from "@stripe/stripe-js";
|
||||||
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
|
||||||
import { useAuth } from "@/auth";
|
|
||||||
import { useApi } from "@/api";
|
|
||||||
import styles from "./styles.module.css";
|
import styles from "./styles.module.css";
|
||||||
|
|
||||||
interface ApplePayButtonProps {
|
interface ApplePayButtonProps {
|
||||||
activeSubPlan: ISubscriptionPlan | null;
|
activeSubPlan: ISubscriptionPlan | null;
|
||||||
|
client_secret: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ApplePayButton({ activeSubPlan }: ApplePayButtonProps) {
|
function ApplePayButton({ activeSubPlan, client_secret }: ApplePayButtonProps) {
|
||||||
const stripe = useStripe();
|
const stripe = useStripe();
|
||||||
const elements = useElements();
|
const elements = useElements();
|
||||||
const api = useApi();
|
|
||||||
const { token } = useAuth();
|
|
||||||
const [paymentRequest, setPaymentRequest] = useState<PaymentRequest | null>(
|
const [paymentRequest, setPaymentRequest] = useState<PaymentRequest | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@ -53,19 +50,6 @@ function ApplePayButton({ activeSubPlan }: ApplePayButtonProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
pr.on("paymentmethod", async (e) => {
|
pr.on("paymentmethod", async (e) => {
|
||||||
const { subscription_receipt } = await api.createSubscriptionReceipt({
|
|
||||||
token,
|
|
||||||
way: "stripe",
|
|
||||||
subscription_receipt: {
|
|
||||||
sub_plan_id: activeSubPlan?.id || "stripe.7",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const { client_secret } = subscription_receipt.data;
|
|
||||||
|
|
||||||
if (!subscription_receipt) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { error: stripeError } = await stripe.confirmCardPayment(
|
const { error: stripeError } = await stripe.confirmCardPayment(
|
||||||
client_secret,
|
client_secret,
|
||||||
{
|
{
|
||||||
@ -85,7 +69,7 @@ function ApplePayButton({ activeSubPlan }: ApplePayButtonProps) {
|
|||||||
// payment_intent.succeeded event that handles any business critical
|
// payment_intent.succeeded event that handles any business critical
|
||||||
// post-payment actions.
|
// post-payment actions.
|
||||||
});
|
});
|
||||||
}, [stripe, elements, activeSubPlan, api, token]);
|
}, [activeSubPlan, client_secret, elements, stripe]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export function StripePage(): JSX.Element {
|
|||||||
const locale = i18n.language;
|
const locale = i18n.language;
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const activeSubPlan = useSelector(selectors.selectActiveSubPlan);
|
const activeSubPlan = useSelector(selectors.selectActiveSubPlan);
|
||||||
const email = useSelector(selectors.selectEmail);
|
const email = useSelector(selectors.selectUser).email;
|
||||||
const [stripePromise, setStripePromise] =
|
const [stripePromise, setStripePromise] =
|
||||||
useState<Promise<Stripe | null> | null>(null);
|
useState<Promise<Stripe | null> | null>(null);
|
||||||
const [subPlans, setSubPlans] = useState<ISubscriptionPlan[] | null>(null);
|
const [subPlans, setSubPlans] = useState<ISubscriptionPlan[] | null>(null);
|
||||||
@ -111,12 +111,14 @@ export function StripePage(): JSX.Element {
|
|||||||
)}
|
)}
|
||||||
{stripePromise && clientSecret && (
|
{stripePromise && clientSecret && (
|
||||||
<Elements stripe={stripePromise} options={{ clientSecret }}>
|
<Elements stripe={stripePromise} options={{ clientSecret }}>
|
||||||
<ApplePayButton activeSubPlan={activeSubPlan} />
|
<ApplePayButton
|
||||||
<CheckoutForm>
|
activeSubPlan={activeSubPlan}
|
||||||
{activeSubPlan && (
|
client_secret={clientSecret}
|
||||||
<SubPlanInformation subPlan={activeSubPlan} subPlans={subPlans} />
|
/>
|
||||||
)}
|
{activeSubPlan && (
|
||||||
</CheckoutForm>
|
<SubPlanInformation subPlan={activeSubPlan} subPlans={subPlans} />
|
||||||
|
)}
|
||||||
|
<CheckoutForm></CheckoutForm>
|
||||||
</Elements>
|
</Elements>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -8,10 +8,12 @@ import { useApi } from "@/api";
|
|||||||
import { useAuth } from "@/auth";
|
import { useAuth } from "@/auth";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Loader from "../Loader";
|
import Loader from "../Loader";
|
||||||
|
import ApplePayButton from "../StripePage/ApplePayButton";
|
||||||
|
|
||||||
interface ISubPlanInformationProps {
|
interface ISubPlanInformationProps {
|
||||||
subPlan: ISubscriptionPlan;
|
subPlan: ISubscriptionPlan;
|
||||||
subPlans: ISubscriptionPlan[] | null;
|
subPlans: ISubscriptionPlan[] | null;
|
||||||
|
client_secret?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPrice = (plan: ISubscriptionPlan): string => {
|
const getPrice = (plan: ISubscriptionPlan): string => {
|
||||||
@ -23,6 +25,7 @@ const getPrice = (plan: ISubscriptionPlan): string => {
|
|||||||
function SubPlanInformation({
|
function SubPlanInformation({
|
||||||
subPlan,
|
subPlan,
|
||||||
subPlans,
|
subPlans,
|
||||||
|
client_secret,
|
||||||
}: ISubPlanInformationProps): JSX.Element {
|
}: ISubPlanInformationProps): JSX.Element {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
@ -77,6 +80,9 @@ function SubPlanInformation({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<TotalToday total={getPrice(subPlan)} />
|
<TotalToday total={getPrice(subPlan)} />
|
||||||
|
{client_secret && (
|
||||||
|
<ApplePayButton activeSubPlan={subPlan} client_secret={client_secret} />
|
||||||
|
)}
|
||||||
{payPalSubPlan && (
|
{payPalSubPlan && (
|
||||||
<MainButton
|
<MainButton
|
||||||
type="button"
|
type="button"
|
||||||
@ -89,7 +95,7 @@ function SubPlanInformation({
|
|||||||
)}
|
)}
|
||||||
{/* <ApplePayButton activeSubPlan={subPlan} /> */}
|
{/* <ApplePayButton activeSubPlan={subPlan} /> */}
|
||||||
<p className={styles.description}>
|
<p className={styles.description}>
|
||||||
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}
|
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}.
|
||||||
</p>
|
</p>
|
||||||
{!!errors.length && <p className={styles.errors}>{errors}</p>}
|
{!!errors.length && <p className={styles.errors}>{errors}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -194,8 +194,9 @@ export const withoutHeaderRoutes = [
|
|||||||
routes.client.energyVampirismResult(),
|
routes.client.energyVampirismResult(),
|
||||||
routes.client.nameHoroscopeResult(),
|
routes.client.nameHoroscopeResult(),
|
||||||
];
|
];
|
||||||
export const hasNoHeader = (path: string) =>
|
export const hasNoHeader = (path: string) => {
|
||||||
!withoutHeaderRoutes.includes(path);
|
return !withoutHeaderRoutes.includes(`/${path.split("/")[1]}`);
|
||||||
|
};
|
||||||
|
|
||||||
export const getRouteBy = (status: UserStatus): string => {
|
export const getRouteBy = (status: UserStatus): string => {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user