当前位置: 首页 > news >正文

龙岩有什么招聘本地网站网站设计学习

龙岩有什么招聘本地网站,网站设计学习,网站域名的作用,网站制作中的展开怎么做这里要准备好几个东西#xff1a; 一个支付成功过后的回调 还有一个下单的接口 一旦进入这个下单界面#xff0c;就要去调下单的接口的#xff0c;用 post, 这个 接口你自己写#xff0c;可以写在后端中#xff0c;也可以放到 nextjs 的 api 中。 首先说的是这个下单… 这里要准备好几个东西 一个支付成功过后的回调 还有一个下单的接口 一旦进入这个下单界面就要去调下单的接口的用 post, 这个 接口你自己写可以写在后端中也可以放到 nextjs 的 api 中。 首先说的是这个下单接口 可以这样写 import { NextRequest, NextResponse } from next/server; const stripe require(stripe)(process.env.STRIPE_SECRET_KEY);export async function POST(request: NextRequest) {try {const { amount } await request.json();const paymentIntent await stripe.paymentIntents.create({amount: amount,currency: usd,automatic_payment_methods: { enabled: true },});return NextResponse.json({ clientSecret: paymentIntent.client_secret });} catch (error) {console.error(Internal Error:, error);// Handle other errors (e.g., network issues, parsing errors)return NextResponse.json({ error: Internal Server Error: ${error} },{ status: 500 });} } 这个东西一般是放后端因为有个 secrets key原则 nextjs 的 api 也算是后端。 要传入的参数呢只有一个是金额一个是 secret key 返回的信息是给前端用的一个 client secret key. 可以理解为一个通用凭证。 前端怎么利用这个 key 。 const { error } await stripe.confirmPayment({elements,clientSecret,confirmParams: {return_url: http://www.localhost:3000/payment-success?amount${amount},},});这个 elements 是 stripe 自带的要利用到里面的一些组件比如你开了 wechat 就要自动显示。 而不是自己写页面。 clientSecret 这个 client key 就是从后端返回的。 大约就是这样简单最后这个 return url 中的。 我不太清楚这样的话还需要 webhook 吗还需要去验证。 整个表单的代码我放一下 use client;import React, { useEffect, useState } from react; import {useStripe,useElements,PaymentElement, } from stripe/react-stripe-js; import convertToSubcurrency from /lib/convertToSubcurrency;const CheckoutPage ({ amount }: { amount: number }) {const stripe useStripe();const elements useElements();const [errorMessage, setErrorMessage] useStatestring();const [clientSecret, setClientSecret] useState();const [loading, setLoading] useState(false);useEffect(() {fetch(/api/create-payment-intent, {method: POST,headers: {Content-Type: application/json,},body: JSON.stringify({ amount: convertToSubcurrency(amount) }),}).then((res) res.json()).then((data) setClientSecret(data.clientSecret));}, [amount]);const handleSubmit async (event: React.FormEventHTMLFormElement) {event.preventDefault();setLoading(true);if (!stripe || !elements) {return;}const { error: submitError } await elements.submit();if (submitError) {setErrorMessage(submitError.message);setLoading(false);return;}const { error } await stripe.confirmPayment({elements,clientSecret,confirmParams: {return_url: http://www.localhost:3000/payment-success?amount${amount},},});if (error) {// This point is only reached if theres an immediate error when// confirming the payment. Show the error to your customer (for example, payment details incomplete)setErrorMessage(error.message);} else {// The payment UI automatically closes with a success animation.// Your customer is redirected to your return_url.}setLoading(false);};if (!clientSecret || !stripe || !elements) {return (div classNameflex items-center justify-centerdivclassNameinline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-e-transparent align-[-0.125em] text-surface motion-reduce:animate-[spin_1.5s_linear_infinite] dark:text-whiterolestatusspan className!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]Loading.../span/div/div);}return (form onSubmit{handleSubmit} classNamebg-white p-2 rounded-md{clientSecret PaymentElement /}{errorMessage div{errorMessage}/div}buttondisabled{!stripe || loading}classNametext-white w-full p-5 bg-black mt-2 rounded-md font-bold disabled:opacity-50 disabled:animate-pulse{!loading ? Pay $${amount} : Processing...}/button/form); };export default CheckoutPage;
http://www.hkea.cn/news/14526724/

相关文章:

  • 网站建设课程简介图片大站网站建设
  • 济南企业网站制作网站点击量在哪里看
  • 长春火车站位置外汇申报在哪个网站上做
  • 企业网站建设 企业官网定制国内10大搜索引擎
  • 代点任意广告链接网站一个公司可以做几个网站吗
  • 下好的字体怎么导入wordpress快速优化seo软件推广方法
  • 武城网站建设电话codeus企业wordpress
  • 公司设计一个网站艺腾青岛网站建设
  • 高端网站制作乐是WordPress任务发布插件
  • 金融理财网站源码整合营销推广策略
  • 山西汽车网站建设html网页wordpress
  • php如何给网站做支付接口阿里巴巴可以做公司网站吗
  • 晋州住房保障建设局网站网站网络建设
  • 海外网站导航网站建设一点通
  • 搭建企业网站流程柒零叁网站建设
  • 网站建设图文片做网站字体规范
  • 天猫官方网站首页网站开发保密协议范本
  • 怎么样做网站赚钱小型网站设计及建设论文
  • 网站商城建设合同免费下载食堂网站建设
  • 仙居网站开发wordpress破解插件放心用吗
  • 运河经济开发区建设局网站免费建立网站的网站吗
  • 关于加强企业门户网站建设通知推动高质量发展就是要
  • 写出网站建设的基本流程wordpress 调用时间
  • 温州大军建设有限公司网站租房网站建设
  • 网站建设支出账务处理电商网站设计系统
  • 机关门花网站建设深圳4a广告公司
  • 白云区建材网站建设谷歌app下载 安卓
  • 做电子商务网站多少钱汉中站
  • 福州网站建设流程有哪些网络推广渠道
  • 成品网站w灬源码1688国外建设网站情况