- {/*

navigate(routes.client.home())}
- /> */}
{isLoading ? (
) : null}
+ {!isLoading && (
+ <>
+
+ Pay
+
+
{email}
+ >
+ )}
{stripePromise && clientSecret && (
<>
-
- {activeSubPlan && }
+ {activeSubPlan && (
+
+ )}
>
diff --git a/src/components/StripePage/styles.module.css b/src/components/StripePage/styles.module.css
index 0862b8d..d305530 100644
--- a/src/components/StripePage/styles.module.css
+++ b/src/components/StripePage/styles.module.css
@@ -3,11 +3,10 @@
position: static;
/* height: calc(100vh - 50px);
max-height: -webkit-fill-available; */
- flex: auto;
- justify-content: center;
- display: grid;
- grid-template-rows: 1fr 96px;
+ display: flex;
justify-items: center;
+ justify-content: center;
+ gap: 16px;
}
.payment-loader {
@@ -25,3 +24,15 @@
cursor: pointer;
z-index: 9;
}
+
+.title {
+ font-size: 27px;
+ font-weight: 700;
+ margin: 0;
+}
+
+.email {
+ font-size: 17px;
+ font-weight: 500;
+ margin: 0;
+}
\ No newline at end of file
diff --git a/src/components/SubPlanInformation/index.tsx b/src/components/SubPlanInformation/index.tsx
index 6a4db85..da73452 100644
--- a/src/components/SubPlanInformation/index.tsx
+++ b/src/components/SubPlanInformation/index.tsx
@@ -2,9 +2,16 @@ import { useTranslation } from "react-i18next";
import styles from "./styles.module.css";
import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
import TotalToday from "./TotalToday";
+import ApplePayButton from "../StripePage/ApplePayButton";
+import MainButton from "../MainButton";
+import { useApi } from "@/api";
+import { useAuth } from "@/auth";
+import { useEffect, useState } from "react";
+import Loader from "../Loader";
interface ISubPlanInformationProps {
subPlan: ISubscriptionPlan;
+ subPlans: ISubscriptionPlan[] | null;
}
const getPrice = (plan: ISubscriptionPlan): string => {
@@ -15,14 +22,76 @@ const getPrice = (plan: ISubscriptionPlan): string => {
function SubPlanInformation({
subPlan,
+ subPlans,
}: ISubPlanInformationProps): JSX.Element {
const { t } = useTranslation();
+ const api = useApi();
+ const { token } = useAuth();
+ const [payPalSubPlan, setPayPalSubPlan] = useState
();
+ const [errors, setErrors] = useState("");
+ const [isLoading, setIsLoading] = useState(false);
+
+ useEffect(() => {
+ if (!subPlans) return;
+ const paypalPlan = subPlans
+ .filter((plan: ISubscriptionPlan) => plan.provider === "paypal")
+ .filter((plan: ISubscriptionPlan) => {
+ if (subPlan?.trial && plan?.trial) return true;
+ if (!subPlan?.trial && !plan?.trial) return true;
+ return false;
+ })
+ .find((plan: ISubscriptionPlan) => {
+ if (subPlan?.trial && plan?.trial) {
+ return plan?.trial?.price_cents === subPlan?.trial?.price_cents;
+ }
+ if (!subPlan?.trial && !plan?.trial) {
+ return plan?.name === subPlan?.name;
+ }
+ return false;
+ });
+ setPayPalSubPlan(paypalPlan);
+ }, [subPlan?.name, subPlan?.trial, subPlans]);
+
+ const handlePayPalButton = async () => {
+ setIsLoading(true);
+ const {
+ subscription_receipt: { data },
+ } = await api.createSubscriptionReceipt({
+ token,
+ way: "paypal",
+ subscription_receipt: {
+ sub_plan_id: payPalSubPlan?.id || "paypal.6",
+ },
+ });
+ if (!data?.links) {
+ return setErrors("Something went wrong. Please try again later.");
+ }
+ const link = data.links.find((link) => link.rel === "approve");
+ if (!link) {
+ return setErrors("Something went wrong. Please try again later.");
+ }
+ setIsLoading(false);
+ window.open(link.href, "_blank");
+ };
+
return (
+ {payPalSubPlan && (
+
+ {!isLoading &&
}
+ {isLoading && }
+
+ )}
+
{t("auweb.pay.information").replaceAll("%@", getPrice(subPlan))}
+ {!!errors.length &&
{errors}
}
);
}
diff --git a/src/components/SubPlanInformation/styles.module.css b/src/components/SubPlanInformation/styles.module.css
index 4404a0e..7c6cd7d 100644
--- a/src/components/SubPlanInformation/styles.module.css
+++ b/src/components/SubPlanInformation/styles.module.css
@@ -14,3 +14,18 @@
line-height: 16px;
padding-bottom: 16px;
}
+
+.pay-pal-button {
+ width: 100%;
+ height: 60px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background-color: #ffc43a;
+ border-radius: 7px;
+}
+
+.errors {
+ color: red;
+ text-align: center;
+}
diff --git a/src/components/SubscriptionPage/index.tsx b/src/components/SubscriptionPage/index.tsx
index c99fcea..6b0e602 100644
--- a/src/components/SubscriptionPage/index.tsx
+++ b/src/components/SubscriptionPage/index.tsx
@@ -62,8 +62,8 @@ function SubscriptionPage(): JSX.Element {
const targetSubPlan = subPlans.find(
(sub_plan) =>
String(
- sub_plan.trial?.price_cents
- ? Math.floor(sub_plan.trial?.price_cents / 100)
+ sub_plan?.trial?.price_cents
+ ? Math.floor(sub_plan?.trial?.price_cents / 100)
: sub_plan.id.replace(".", "")
) === subPlan
);
@@ -181,16 +181,16 @@ function SubscriptionPage(): JSX.Element {
const { sub_plans } = await api.getSubscriptionPlans({ locale });
const plans = sub_plans
.filter(
- (plan: ISubscriptionPlan) => plan.provider === "stripe" && plan.trial
+ (plan: ISubscriptionPlan) => plan.provider === "stripe"
)
.sort((a, b) => {
if (!a.trial || !b.trial) {
return 0;
}
- if (a.trial.price_cents < b.trial.price_cents) {
+ if (a?.trial?.price_cents < b?.trial?.price_cents) {
return -1;
}
- if (a.trial.price_cents > b.trial.price_cents) {
+ if (a?.trial?.price_cents > b?.trial?.price_cents) {
return 1;
}
return 0;