Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/implemented stripe payment for subscriptions #1020

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
969 changes: 542 additions & 427 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions public/images/Symbol.svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/images/paypal_logo.svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions public/images/stripe_logo.svg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/actions/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const loginUser = async (values: z.infer<typeof LoginSchema>) => {
return {
status: response.status,
organisations: response.data.data.organisations,
access_token: response.data.access_token,
};
} catch (error) {
return axios.isAxiosError(error) && error.response
Expand Down
45 changes: 45 additions & 0 deletions src/actions/payments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use server";
/* eslint-disable prettier/prettier */
import axios from "axios";
import { auth } from "~/lib/auth";
import { getApiUrl } from "./getApiUrl";

export const getOrganizations = async (userId: string) => {
try {
const apiUrl = await getApiUrl();
const session = await auth();

const response = await axios.get(
`${apiUrl}/api/v1/${userId}/organisations`,
{
headers: {
Authorization: `Bearer ${session?.access_token}`,
}
});

return response?.data
} catch {
// return error
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const fetchStripeUrl = async (json: any, callback: (parameter: any) => void) => {
try {
const apiUrl = await getApiUrl();
const session = await auth();

const response = await axios.post(`${apiUrl}/api/v1/payment/stripe`, json,
{
headers: {
Authorization: `Bearer ${session?.access_token}`,
}
}
);


callback(response)
} catch(error) {
return error
}
}
5 changes: 3 additions & 2 deletions src/app/(auth-routes)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ const Login = () => {
startTransition(async () => {
await loginUser(values).then(async (data) => {
const { email, password } = values;

if (data.status === 200) {
setUserOrg(data.organisations);
if (!currentOrgId && data.organisations.length > 0) {

window.localStorage.setItem("token", data.access_token);
if (!currentOrgId && data.organisations?.length > 0) {
setCurrentOrgId(data.organisations[0].organisation_id);
}
await signIn(
Expand Down
6 changes: 4 additions & 2 deletions src/app/(landing-routes)/help-center/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable prettier/prettier */
"use client";

import { getApiUrl } from "~/actions/getApiUrl";
import axios from "axios";
import { Search } from "lucide-react";
import Link from "next/link";
import { ChangeEvent, useEffect, useState } from "react";

import { getApiUrl } from "~/actions/getApiUrl";
import { Input } from "~/components/common/input";
import FaqAccordion from "~/components/layouts/accordion/FaqsAccordion";
import TopicsAccordions from "~/components/layouts/accordion/TopicAccordion";
Expand All @@ -26,6 +27,8 @@ const HelpCenter = () => {
const [searchValue, setSearchValue] = useState<string>("");
const { toast } = useToast();



useEffect(() => {
const fetchTopics = async () => {
try {
Expand All @@ -42,7 +45,6 @@ const HelpCenter = () => {
setLoading(false);
}
};

fetchTopics();
}, [toast]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable prettier/prettier */

"use client"

import { useState, useEffect } from 'react';
import { getApiUrl } from '~/actions/getApiUrl';
import axios from 'axios';
import { useToast } from '~/components/ui/use-toast';
import CheckoutForm from '../_components/checkoutForm/checkoutForm';
import Link from 'next/link';

import { ArrowLeft } from 'lucide-react';

const Page = ({ params }: { params: { slug: string } }) => {
const [plan, setPlan] = useState({
id: "",
name: "",
price: 0
})
const { toast } = useToast()

useEffect(() => {
const getSpecificPlan = async () => {
try {
const apiUrl = await getApiUrl();
const response = await axios.get(`${apiUrl}/api/v1/billing-plans/${params.slug}`);
setPlan(response.data.data);
} catch {
toast({
title: "Error",
description: "Error fetching topics",
variant: "destructive",
});
}
};
getSpecificPlan();
}, [toast, params.slug]);

return (
<div className=''>
<div className='flex flex-col gap-y-[16px] px-[14px]'>
<div className='flex items-center gap-x-[10px]'>
<Link href={'/dashboard/admin/settings/payment-information'}>
<ArrowLeft />
</Link>
<p className='text-[24px] font-semibold'>{`Upgrade to ${plan.name}`}</p>
</div>
<p className='text-[14px] text-neutral-dark-2'>Do more with unlimited users and Integration when you upgrade</p>
</div>
{/* <Elements stripe={stripePromise}> */}
<CheckoutForm plan={plan} />
{/* </Elements> */}
</div>
)
}

export default Page
Loading
Loading