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 [customerId, setCustomerId] = useState(null);
const [sub, setSub] = useState(false);
const flat = false; // Switch between subscription system or flat prices
const portal = () => {
axios
@@ -45,8 +46,6 @@ const Pricing = () => {
}
}, [user]);
const flat = false; // Switch between subscription system or flat prices
const pricing = {
monthly: {
personal: "$5/mo",
@@ -75,6 +74,7 @@ const Pricing = () => {
customerId: customerId,
userId: user.id,
tokenId: session.access_token,
pay_mode: flat ? "payment" : "subscription",
})
.then((result) => router.push(result.data.url));
};
@@ -171,7 +171,8 @@ const Pricing = () => {
</h3>
<ul className='text-sm px-5 mb-8 text-left'>
<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 className='leading-tight'>
<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 {
const session = req.body.customerId
? await stripe.checkout.sessions.create({
mode: "subscription",
mode: req.body.pay_mode,
payment_method_types: ["card"],
client_reference_id: req.body.userId,
metadata: { token: req.body.tokenId, priceId: req.body.priceId },