简体   繁体   English

Stripe 问题,请调用 Stripe() 错误 Uncaught (in promise)

[英]Stripe Problem, please call Stripe ( ) error Uncaught (in promise)

I'm facing this problem when trying to implement Stripe in my ecommerce尝试在我的电子商务中实施 Stripe 时遇到了这个问题

When I put the credit card numbers from Stripe testing website, the website refresh, nothing happens, not even re direct to /success, only this error appears in console:当我从 Stripe 测试网站输入信用卡号时,网站刷新,没有任何反应,甚至没有重定向到 /success,只有这个错误出现在控制台中:

 Uncaught (in promise) IntegrationError: Please call Stripe() with your publishable key. 
 You used an empty string.

this is my app.js这是我的 app.js

 function App() {

const {isAuthenticated, user} = useSelector((state)=>state.user)

const [stripeApiKey, setStripeApiKey] = useState("");

 async function getStripeApiKey() {
 const {data} = await axios.get("/api/v1/stripeapikey");

  setStripeApiKey(data.stripeApiKey)
 }

 useEffect(() => { 

  WebFont.load({
   google:{
     families: [ "Droid Sans", "Chilanka"],
   },
  });

  store.dispatch(loadUser())

  getStripeApiKey()
 }, []);

return (
<Router>
  <Header/>
  {isAuthenticated && <UserOptions user={user} />}
  <Routes>
    <Route path="/" element={<Home/>}/>
    <Route path="/product/:id" element={<ProductDetails/>}/>
    <Route path="/products" element={<Products/>}/>
    <Route path="/products/:keyword" element={<Products/>}/>
    <Route path="/search" element={<Search/>}/>
    <Route element={<ProtectedRoute/>}/>
      <Route path="/account" element={<Profile/>}/>
    <Route element={<ProtectedRoute/>}/>
     <Route path="/me/update" element={<UpdateProfile/>}/>
    <Route element={<ProtectedRoute/>}/>
     <Route path="/password/update" element={<UpdatePassword/>}/>
    <Route path="/password/forgot" element={<ForgotPassword/>}/> 
    <Route path="/password/reset/:token" element={<ResetPassword/>}/> 
    <Route path="/login" element={<LoginSignUp/>}/>
    <Route path="/cart" element={<Cart/>}/>
    <Route element={<ProtectedRoute/>}/>
     <Route path="/shipping" element={<Shipping/>}/>
    <Route element={<ProtectedRoute/>}/>
     <Route path="/order/confirm" element={<ConfirmOrder/>}/>

     <Route element={<ProtectedRoute/>}/>
      <Route  path="/process/payment" element={ <Elements stripe={loadStripe(stripeApiKey)}><Payment/></Elements>}/>
  </Routes>
<Footer/>
</Router>
 );
}

and this is my paymentController, I think the problem may be in the app.js, as how I'm calling StripeP这是我的支付控制器,我认为问题可能出在 app.js 中,就像我调用 StripeP 的方式一样

const catchAsyncErrors = require("../middlewares/catchAsyncErrors");

  const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);

exports.processPayment = catchAsyncErrors(async (req, res, next) => {
const myPayment = await stripe.paymentIntents.create({
amount: req.body.amount,
currency: "inr",
metadata: {
  company: "Ecommerce",
},
});

res
.status(200)
 .json({ success: true, client_secret: myPayment.client_secret });
 });

exports.sendStripeApiKey = catchAsyncErrors(async (req, res, next) => {
res.status(200).json({ stripeApiKey: process.env.STRIPE_API_KEY });
});  
{stripeApiKey && <Route exact path="/process/payment" element={<Elements stripe={loadStripe(stripeApiKey)}><Payment/></Elements>}/>}

In app.js where you have declared your Payment Route Path just add and condition && stripeApiKey .在 app.js 中,您已经声明了支付路径路径,只需添加和条件&& stripeApiKey

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获(承诺)错误:提供给 `Elements` 的道具 `stripe` 无效。 我们建议使用来自 `@stripe/stripe-js` 的 `loadStripe` 实用程序 - Uncaught (in promise) Error: Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js` 未捕获的 ReferenceError:未定义条纹 - 条纹错误 - Uncaught ReferenceError: Stripe is not defined - STRIPE ERROR Stripe 无法使用错误“未捕获(承诺中)错误:我们无法从指定元素中检索数据。” - Stripe not working with error 'Uncaught (in promise) Error: We could not retrieve data from the specified Element.' 未捕获(承诺中)IntegrationError:stripe.confirmCardPayment 意图秘密的值无效 - Uncaught (in promise) IntegrationError: Invalid value for stripe.confirmCardPayment intent secret NEXJS stripe v3:1 Uncaught (in promise) IntegrationError: Missing value for Stripe(): apiKey should be a string - NEXJS stripe v3:1 Uncaught (in promise) IntegrationError: Missing value for Stripe(): apiKey should be a string 条纹未定义; 请修复或添加/ * global Stripe * / - stripe is not defined; please fix or add /*global Stripe*/ Angular 条纹集成错误:请提供元素或 PaymentMethod - Angular Stripe Integration error: Please provide an element or PaymentMethod Uncaught ReferenceError:未定义条纹MVC - Uncaught ReferenceError: Stripe is not defined MVC 未捕获(承诺)错误:对 fetch() 的挂钩调用无效 - Uncaught (in promise) Error: Invalid hook call on fetch() 条纹付款和反应错误 - Stripe Payments & React Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM