next stripe
1.0.0
Flujos de trabajo de rayas del lado del servidor simplificados en Next.js
️ Tenga en cuenta: ¡esta biblioteca se encuentra actualmente en beta y debe usarse en producción con precaución!
yarn add next-stripe@beta
Cree una ruta [...nextstripe].js Catch-All en pages/api/stripe de su proyecto.
️ Tenga en cuenta: se recomienda que use una clave restringida con acceso de API limitado con esta biblioteca. Estas claves se pueden crear y configurar con el acceso requerido en el tablero de rayas.
import NextStripe from 'next-stripe'
export default NextStripe ( {
stripe_key : process . env . STRIPE_RESTRICTED_KEY
} ) next-stripe/client exporta funciones auxiliares para llamar a las rutas de la API Next.js.
Stripe API Docs
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'
} )Stripe API Docs
import { createPaymentIntent } from 'next-stripe/client'
const paymentIntent = await createPaymentIntent ( {
amount : 1000 ,
currency : 'usd'
} ) Stripe API Docs
import { confirmPaymentIntent } from 'next-stripe/client'
const paymentIntent = await confirmPaymentIntent ( 'pi_id' , {
payment_method : 'pm_id'
} ) Stripe API Docs
import { retrievePaymentIntent } from 'next-stripe/client'
const paymentIntent = await retrievePaymentIntent ( 'pi_id' ) Stripe API Docs
import { updatePaymentIntent } from 'next-stripe/client'
const paymentIntent = await updatePaymentIntent ( 'pi_id' , {
amount : 1000 ,
currency : 'usd'
} )Stripe API Docs
import { createBillingPortalSession } from 'next-stripe/client'
const session = await createBillingPortalSession ( {
customer : 'cus_id' ,
return_url : window . location . href
} )