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
} )