#beninagata

1 messages · Page 1 of 1 (latest)

teal fiberBOT
#

Hello beninagata, we'll be with you shortly! Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
beninagata, 13 hours ago, 6 messages

wanton meteor
#

The value of success_url and cancel_url is not a valid URL. It should be something like https://...

tawny plinth
#

import { auth, currentUser } from "@clerk/nextjs";
import { NextResponse } from "next/server";

import prismadb from "@/lib/prismadb";
import { stripe } from "@/lib/stripe";
import { absoluteUrl } from "@/lib/utils";

const settingsUrl = absoluteUrl("/settings");

export async function GET(){
try {
const { userId } = auth();
const user = await currentUser();

if(!userId || !user){
    return new NextResponse("Unauthorized", {status: 401});
}

const userSubscription = await prismadb.userSubscription.findUnique({
    where: {
        userId
    }
});

if( userSubscription && userSubscription.stripeCustomerId){
    const stripeSession = await stripe.billingPortal.sessions.create({
        customer: userSubscription.stripeCustomerId,
        return_url: settingsUrl,
    }); 

    return new NextResponse(JSON.stringify({url: stripeSession.url}));
}

const stripeSession = await stripe.checkout.sessions.create({
    success_url: settingsUrl,
    cancel_url: settingsUrl,
    payment_method_types: ["card"],
    mode: "subscription",
    billing_address_collection: "auto",
    customer_email:user.emailAddresses[0].emailAddress,
    line_items:[
        {
            price_data:{
                currency: "MYR",
                product_data:{
                    name: "Genius Pro",
                    description: "Unlimited AI Generation"
                },
                unit_amount: 2000,
                recurring:{
                    interval: "month"
                }
            },
            quantity: 1,
        }
    ],
    metadata:{
        userId,
    },
});

return new NextResponse(JSON.stringify({url: stripeSession.url}));

} catch (error){
    console.log("[STRIPE_ERROR]", error);
    return new NextResponse("Internal error", {status: 500});
}

}

#

the /settings change to https.//settings?

wanton meteor
#

No! success_url and cancel_url should be a valid URL on your server. It should be something like https://{your-domain}/{path}

tawny plinth
#

i see

#

sure will be change

#

thanks

wanton meteor
#

No problem! Happy to help 😄

tawny plinth
#

still not working

wanton meteor
#

What is not working? Did you set to proper HTTPS URL?

tawny plinth
#

yup

wanton meteor
#

Please share the request ID (req_xxx) of the error