Ir a contenido
Crea una cuenta
o
Inicia sesión
Logotipo de Stripe Docs
/
Pregúntale a la IA
Crear una cuenta
Iniciar sesión
Empieza ahora
Pagos
Automatización contable
Plataformas y marketplaces
Gestión del dinero
Herramientas para desarrolladores
Empieza ahora
Pagos
Automatización contable
Empieza ahora
Pagos
Automatización contable
Plataformas y marketplaces
Gestión del dinero
Resumen
Billing
    Resumen
    Acerca de las API de facturación
    Suscripciones
    Invoicing
      Resumen
      Inicio rápido de la API
      Integrar con la API
      Facturación sin programación
      Ciclo de vida de la factura
      Vista previa de facturas
      Editar facturas
      Programa la finalización de las facturas
      Transiciones de estado y finalización
      Enviar correos electrónicos a clientes
      Generar notas de crédito
      Facturar a los clientes
      Clientes
      Saldo acreedor del cliente
      Identificaciones fiscales de los clientes
      Facturar pagos
      Página de facturas alojadas
      Crea planes de pago de facturas
      Acepta pagos parciales
      Métodos de pago para las facturas
      Cobros automatizados
      Personalización de facturas
      Personalizar facturas
      Plantillas de representación de facturas
      Agrupa partidas de factura
      Resumir las partidas
      Facturación internacional
      Prácticas recomendadas
      Clientes en varias monedas
      Otras funcionalidades de facturación
      Productos y precios
      Gestiona partidas de facturas en masa
      Impuestos
    Cobro por consumo
    Connect y Billing
    Tax y Billing
    Presupuestos
    Recuperación de ingresos
    Automatizaciones
    Scripts
    Reconocimiento de ingresos
    Gestión de clientes
    Derechos
    Prueba tu integración
Impuesto
Elaboración de informes
Datos
Constitución de una startup
InicioAutomatización contableBillingInvoicing

Nota

Esta página aún no está disponible en este idioma. Estamos trabajando intensamente para que nuestra documentación esté disponible en más idiomas. Ofreceremos la traducción en cuanto esté disponible.

Integrate with the Invoicing API

Learn how to create and send an invoice with code.

Copiar página

The Dashboard is the most common way to create invoices. If you’d like to automate invoice creation, you can integrate with the API. Build a full, working Invoicing integration using our sample integration.

Nota

You don’t need to integrate with the Payments API to integrate with the Invoicing API.

Set up Stripe

Use our official libraries for access to the Stripe API:

Command Line
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

Create a product

To create a product, enter its name:

Command Line
cURL
curl https://api.stripe.com/v1/products \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d name="Gold Special"

Create a price

Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the billing interval (when the price is for a subscription). Like products, if you only have a few prices, it’s preferable to manage them in the Dashboard. Use the unit amount to express prices in the lowest unit of the currency—in this case, cents (10 USD is 1,000 cents, so the unit amount is 1000).

Nota

As an alternative, if you don’t need to create a price for your product, you can use the amount parameter during invoice item creation.

To create a price and assign it to the product, pass the product ID, unit amount, and currency. In the following example, the price for the “Gold Special” product is 10 USD:

Command Line
cURL
curl https://api.stripe.com/v1/prices \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d product=
{{PRODUCT_ID}}
\ -d unit_amount=1000 \ -d currency=usd

Create a customer

The Customer object represents the customer purchasing your product. It’s required for creating an invoice. To create a customer with a name, email, and description, add the following code replacing the values with your own:

Command Line
cURL
curl https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d name="Jenny Rosen" \ --data-urlencode email="jenny.rosen@example.com" \ -d description="My first customer"

After you create the customer, store the customer id in your database so that you can use it later. The next step, for example, uses the customer ID to create an invoice.

Nota

See Create a customer for additional parameters.

Create an invoice

Set the collection_method attribute to send_invoice. For Stripe to mark an invoice as past due, you must add the days_until_due parameter. When you send an invoice, Stripe emails the invoice to the customer with payment instructions.

Command Line
cURL
curl https://api.stripe.com/v1/invoices \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=
{{CUSTOMER_ID}}
\ -d collection_method=send_invoice \ -d days_until_due=30

Then, create an invoice item by passing in the customer id, product price, and invoice ID invoice.

The maximum number of invoice items is 250.

Command Line
cURL
curl https://api.stripe.com/v1/invoiceitems \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=
{{CUSTOMER_ID}}
\ -d "pricing[price]"=
{{PRICE_ID}}
\ -d invoice=
{{INVOICE_ID}}

If you set auto_advance to false, you can continue to modify the invoice until you finalize it. To finalize a draft invoice, use the Dashboard, send it to the customer, or pay it. You can also use the Finalize API:

Nota

If you created the invoice in error, void it. You can also mark an invoice as uncollectible.

Command Line
cURL
curl -X POST https://api.stripe.com/v1/invoices/
{{INVOICE_ID}}
/finalize
\ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Accept invoice payment

Send the invoice to the email address associated with the customer. Stripe finalizes the invoice as soon as you send it. Many jurisdictions consider finalized invoices a legal document making certain fields unalterable. If you send invoices that have already been paid, there’s no reference to the payment in the email.

Nota

When you send invoices that have already been paid, the email doesn’t reference the payment. Stripe sends invoices to the email address associated with the customer.

Command Line
cURL
curl -X POST https://api.stripe.com/v1/invoices/
{{INVOICE_ID}}
/send
\ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"

Handle post-payment events

Stripe sends an invoice.paid event when an invoice payment completes. Listen for this event to ensure reliable fulfillment. If your integration relies on only a client-side callback, the customer could lose connection before the callback executes, which would result in the customer being charged without your server being notified. Setting up your integration to listen for asynchronous events is also what enables you to accept different types of payment methods with a single integration.

Nota

Successful invoice payments trigger both an invoice.paid and invoice.payment_succeeded event. Both event types contain the same invoice data, so it’s only necessary to listen to one of them to be notified of successful invoice payments. The difference is that invoice.payment_succeeded events are sent for successful invoice payments, but aren’t sent when you mark an invoice as paid_out_of_band. invoice.paid events, on the other hand, are triggered for both successful payments and out of band payments. Because invoice.paid covers both scenarios, we typically recommend listening to invoice.paid rather than invoice.payment_succeeded.

Use the Dashboard webhook tool or follow the webhook quickstart to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.

In addition to handling the invoice.paid event, we recommend handling two other events when collecting payments with the Payment Element:

EventDescriptionAction
payment_intent.processingSent when a customer successfully initiated a payment, but the payment has yet to complete. This event is most commonly sent when a bank debit is initiated. It’s followed by either a invoice.paid or invoice.payment_failed event in the future.Send the customer an order confirmation that indicates their payment is pending. For digital goods, you might want to fulfill the order before waiting for payment to complete.
invoice.payment_failedSent when a customer attempted a payment on an invoice, but the payment failed.If a payment transitioned from processing to payment_failed, offer the customer another attempt to pay.

OpcionalCustomize an invoice

Consulta también

  • Post-finalization
  • Use incoming webhooks to get real-time updates
¿Te fue útil esta página?
SíNo
¿Necesitas ayuda? Ponte en contacto con soporte.
Únete a nuestro programa de acceso anticipado.
Echa un vistazo a nuestro registro de cambios.
¿Tienes alguna pregunta? Contacto.
¿LLM? Lee llms.txt.
Con tecnología de Markdoc
Code quickstart
Guías relacionadas
How Invoicing Works
Invoicing API
Hosted Invoice Page
Productos utilizados
Invoicing