Add payment switch on pricing page/create checkout session

This commit is contained in:
Michael
2021-07-10 19:04:34 +02:00
parent 2f34ab4fd3
commit 7ea604c2ac
2 changed files with 5 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ const Pricing = () => {
const { user, session } = Auth.useUser(); const { user, session } = Auth.useUser();
const [customerId, setCustomerId] = useState(null); const [customerId, setCustomerId] = useState(null);
const [sub, setSub] = useState(false); const [sub, setSub] = useState(false);
const flat = false; // Switch between subscription system or flat prices
const portal = () => { const portal = () => {
axios axios
@@ -45,8 +46,6 @@ const Pricing = () => {
} }
}, [user]); }, [user]);
const flat = false; // Switch between subscription system or flat prices
const pricing = { const pricing = {
monthly: { monthly: {
personal: "$5/mo", personal: "$5/mo",
@@ -75,6 +74,7 @@ const Pricing = () => {
customerId: customerId, customerId: customerId,
userId: user.id, userId: user.id,
tokenId: session.access_token, tokenId: session.access_token,
pay_mode: flat ? "payment" : "subscription",
}) })
.then((result) => router.push(result.data.url)); .then((result) => router.push(result.data.url));
}; };
@@ -171,7 +171,8 @@ const Pricing = () => {
</h3> </h3>
<ul className='text-sm px-5 mb-8 text-left'> <ul className='text-sm px-5 mb-8 text-left'>
<li className='leading-tight'> <li className='leading-tight'>
<i className='mdi mdi-check-bold text-lg'></i> All basic features <i className='mdi mdi-check-bold text-lg'></i> All basic
features
</li> </li>
<li className='leading-tight'> <li className='leading-tight'>
<i className='mdi mdi-check-bold text-lg'></i> Dolor sit amet <i className='mdi mdi-check-bold text-lg'></i> Dolor sit amet

View File

@@ -30,7 +30,7 @@ export default async function handler(req, res) {
try { try {
const session = req.body.customerId const session = req.body.customerId
? await stripe.checkout.sessions.create({ ? await stripe.checkout.sessions.create({
mode: "subscription", mode: req.body.pay_mode,
payment_method_types: ["card"], payment_method_types: ["card"],
client_reference_id: req.body.userId, client_reference_id: req.body.userId,
metadata: { token: req.body.tokenId, priceId: req.body.priceId }, metadata: { token: req.body.tokenId, priceId: req.body.priceId },