#Stripe React In Next is "Refused to load the script 'https://js.stripe.com/v3'"
44 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
@swift scroll is there any more additional error like is that the full error?
yes
I tested lots of ways, which work locally but not in production
``import Spinner from "@/app/library/components/spinner/Spinner";
import { createStripeCustomer } from "@/app/library/middlewares/middlewareUser";
import { Elements } from "@stripe/react-stripe-js";
import { useEffect, useState } from "react";
import CheckoutForm from "./CheckoutForm";
import getStripe from "./get-stripejs";
import { createSubscription } from "./stripe";
export default function Payment({ dataPlan, dataUser }: { dataPlan: any; dataUser: any }) {
// const [stripePromise, setStripePromise] = useState<Promise<Stripe | null> | Stripe | null>(null);
const [clientSecret, setClientSecret] = useState<string>("");
const [loading, setLoading] = useState<boolean>(true);
console.log("Payment.tsx");
useEffect(() => {
console.log("Payment.tsx useeffect");
const createPayment = async () => {
const userStr = await createStripeCustomer(dataUser.email, `${dataUser.name} ${dataUser.surname}`);
const user = JSON.parse(userStr);
console.log(user);
const res = await createSubscription(user.id, "price_1PLvsTG2vVjK01VJW5lQd2Qw", dataPlan.cycle);
const subscription = JSON.parse(res);
console.log(subscription);
// Récupérer le client_secret du payment_intent
const paymentIntent = subscription.latest_invoice.payment_intent;
if (!paymentIntent || !paymentIntent.client_secret) return;
setClientSecret(paymentIntent.client_secret);
setLoading(false);
};
createPayment();
}, []);
return (
<div className="payment">
{loading && <Spinner text="Loading Stripe Form" />}
{clientSecret && (
<>
<h2>Paiement</h2>
<Elements stripe={getStripe()} options={{ clientSecret, locale: "fr" }}>
<CheckoutForm />
</Elements>
</>
)}
</div>
);
}
``
``import { Stripe, loadStripe } from "@stripe/stripe-js";
import { config } from "./stripe";
let stripePromise: Promise<Stripe | null>;
const getStripe = async () => {
const key = await config();
if (!stripePromise) {
stripePromise = loadStripe(key);
}
return stripePromise;
};
export default getStripe;
``
**I also try with this : **
let stripePromise: Promise<Stripe | null>; const getStripe =() => { if (!stripePromise) { stripePromise = loadStripe("pk_test_51................................."); } return stripePromise; };
Your using stripe checkout right?
No Stripe Element
Oh ok
I don't know if this helps but here is my header
``/** @type {import('next').NextConfig} /
const nextConfig = {
images: {
remotePatterns: [{ hostname: "lh3.googleusercontent.com" }],
},
async headers() {
return [
{
source: "/api/:path",
headers: [
{
key: "Access-Control-Allow-Origin",
value: "", // Set your origin
},
{
key: "Access-Control-Allow-Methods",
value: "GET, POST, PUT, DELETE, OPTIONS",
},
{
key: "Access-Control-Allow-Headers",
value: "Content-Type, Authorization",
},
],
},
{
source: "/:path",
headers: [
{
key: "Content-Security-Policy",
value: "script-src 'self' 'unsafe-inline' https://js.stripe.com; object-src 'none';",
},
],
},
];
},
};
export default nextConfig;
``
head over to stripe: https://discord.gg/stripe
I went to them first, they told me to ask Next for help...
lol
would you mind sharing your code via https://paste.gg/ ?
It's very complicated to see all the details here on discord
A sensible, modern pastebin. Share text and source code snippets with no hassle.
yes of course
Thank you very much for taking the time to help me, I just had a sleepless night and I don't understand how to solve this problem
Are you able to share this?: ```tsx
import { stripe } from "@/app/library/stripe";
I couldn't find it
Oh yes sorry this is that :
``import Stripe from "stripe";
import { stripeSecretKey } from "./uri";
export const stripe = new Stripe(stripeSecretKey, {
apiVersion: "2024-04-10",
typescript: true,
});
``
is that ok ?
yes, thanks! If you need to update your last paste, you can login and update it directly (just if you need it in the future).
Or you can directly share it with 3 `
and then it's a codeblock.
The results are incredible.
2 `:
``import Stripe from "stripe";
import { stripeSecretKey } from "./uri";
export const stripe = new Stripe(stripeSecretKey, {
apiVersion: "2024-04-10",
typescript: true,
});
``
3 `:
import Stripe from "stripe";
import { stripeSecretKey } from "./uri";
export const stripe = new Stripe(stripeSecretKey, {
apiVersion: "2024-04-10",
typescript: true,
});
ok, and the paymentelement does not load. You get this error, right?: #1245753675373346878 message
I forgot it was 3 instead of two, excuse me
Yes absolutly
can we test a little bit?
yes ?
alright. What's the result of this:
const paymentIntent = subscription.latest_invoice.payment_intent;
{
"id": "pi_3PMDbeG2vVjK01VJ07H308mD",
"object": "payment_intent",
"amount": 4900,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic",
"client_secret": "pi_3PMDbeG2vVjK01VJ07H308mD_secret_cNbdkK7AU8Pu7Gf1tzb7YKfHo",
"confirmation_method": "automatic",
"created": 1717093302,
"currency": "eur",
"customer": "cus_QCcryoWacWy4NB",
"description": "Subscription creation",
"invoice": "in_1PMDbeG2vVjK01VJ0Yyl0cgo",
"last_payment_error": null,
"latest_charge": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_configuration_details": null,
"payment_method_options": {
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "any"
}
},
"payment_method_types": [
"card"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": "off_session",
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}
when you generate this paymentintent, what the url of the page? If it's private, send it via dm
Yes it is
thanks! Looks good for me. Let's go further...
hm I am sorry, I have no idea.
@swift scrollyou tried this: https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy
?
Like adding the nonce via middleware and then access it inside your page?
Oh !!! Not at all, I'll try now thank you
Hello my friend, I finally found the solution, instead of next it was in my reverse proxy where I had to add stripe to the exceptions...
Thank you so much for taking the time to help me!