next stripe
1.0.0
Next.js中的简化服务器端条纹工作流程
配x 请注意:此库当前正在Beta中,应谨慎使用!
yarn add next-stripe@beta
创建一个[...nextstripe].js在项目pages/api/stripe目录中的所有路由。
配x 请注意:建议您使用此库有限的API访问使用有限的键。可以在Stripe仪表板中使用所需的访问创建和配置这些键。
import NextStripe from 'next-stripe'
export default NextStripe ( {
stripe_key : process . env . STRIPE_RESTRICTED_KEY
} ) next-stripe/client导出助手功能以调用next.js API路由。
条纹API文档
import { createCheckoutSession } from 'next-stripe/client'
const session = await createCheckoutSession ( {
success_url : window . location . href ,
cancel_url : window . location . href ,
line_items : [ { price : 'price_id' , quantity : 1 } ] ,
payment_method_types : [ 'card' ] ,
mode : 'payment'
} )条纹API文档
import { createPaymentIntent } from 'next-stripe/client'
const paymentIntent = await createPaymentIntent ( {
amount : 1000 ,
currency : 'usd'
} ) 条纹API文档
import { confirmPaymentIntent } from 'next-stripe/client'
const paymentIntent = await confirmPaymentIntent ( 'pi_id' , {
payment_method : 'pm_id'
} ) 条纹API文档
import { retrievePaymentIntent } from 'next-stripe/client'
const paymentIntent = await retrievePaymentIntent ( 'pi_id' ) 条纹API文档
import { updatePaymentIntent } from 'next-stripe/client'
const paymentIntent = await updatePaymentIntent ( 'pi_id' , {
amount : 1000 ,
currency : 'usd'
} )条纹API文档
import { createBillingPortalSession } from 'next-stripe/client'
const session = await createBillingPortalSession ( {
customer : 'cus_id' ,
return_url : window . location . href
} )