# Créer et envoyer une facture
Créer un exemple d’intégration Invoicing.
# Créer et envoyer une facture
Créez une intégration complète et fonctionnelle de facturation avec Stripe Invoicing. Découvrez comment rechercher un client, obtenir un tarif à partir d’un objet représentant une base de données, et créer et envoyer une facture.
1. Build the server
~~~
npm install
~~~
2. Run the server
~~~
npm start
~~~
1. Run the server
~~~
go run server.go
~~~
1. Build the server
~~~
pip3 install -r requirements.txt
~~~
2. Run the server
~~~
export FLASK_APP=server.py
python3 -m flask run --port=4242
~~~
1. Build the server
~~~
bundle install
~~~
2. Run the server
~~~
ruby server.rb -o 0.0.0.0
~~~
1. Build the server
~~~
composer install
~~~
2. Run the server
~~~
php -S 127.0.0.1:4242 --docroot=public
~~~
1. Build the server
~~~
dotnet build
~~~
2. Run the server
~~~
dotnet run
~~~
1. Build the server
~~~
mvn package
~~~
2. Run the server
~~~
java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server
~~~
~~~
stripe listen --forward-to localhost:4242/webhook.php
~~~
~~~
stripe listen --forward-to localhost:4242/webhook
~~~
### Installer la bibliothèque Node de Stripe
Installez le package et importez-le dans votre code. Si vous partez de zéro et qu’il vous faut un fichier package.json, vous pouvez également télécharger les fichiers du projet à l’aide du lien de téléchargement dans l’éditeur de code.
#### npm
Installez la bibliothèque :
```bash
npm install --save stripe
```
#### GitHub
Vous pouvez sinon télécharger le code source de la bibliothèque Node de Stripe directement [depuis GitHub](https://github.com/stripe/stripe-node).
### Installer la bibliothèque Ruby de Stripe
Installez le gem Ruby de Stripe et exigez-le dans votre code. Si vous partez de zéro et avez besoin d’un Gemfile, téléchargez les fichiers du projet à l’aide du lien dans l’éditeur de code.
#### Terminal
Installez le gem :
```bash
gem install stripe
```
#### Bundler
Ajoutez cette ligne à votre Gemfile :
```bash
gem 'stripe'
```
#### GitHub
Vous pouvez sinon télécharger le code source du gem Ruby de Stripe directement [depuis GitHub](https://github.com/stripe/stripe-ruby).
### Installer la bibliothèque Java
Ajoutez la dépendance à votre build et importez la bibliothèque. Ou bien, si vous partez de zéro et avez besoin d’un exemple de fichier pom.xml (pour Maven), téléchargez les fichiers du projet à l’aide du lien de téléchargement dans l’éditeur de code.
#### Maven
Ajoutez la dépendance suivante à votre POM et remplacez {VERSION} par le numéro de version que vous souhaitez utiliser.
```bash
\ncom.stripe\nstripe-java\n{VERSION}\n
```
#### Gradle
Ajoutez la dépendance à votre fichier build.gradle et remplacez {VERSION} par le numéro de version que vous souhaitez utiliser.
```bash
implementation "com.stripe:stripe-java:{VERSION}"
```
#### GitHub
Téléchargez le fichier JAR directement [depuis GitHub](https://github.com/stripe/stripe-java/releases/latest).
### Installer le package Python de Stripe
Installez le package Stripe et importez-le dans votre code. Si vous partez de zéro et qu’il vous faut un fichier requirements.txt, téléchargez les fichiers du projet à l’aide du lien de téléchargement dans l’éditeur de code.
#### pip
Installez le package via pip :
```bash
pip3 install stripe
```
#### GitHub
Téléchargez le code source de la bibliothèque stripe-python directement [depuis GitHub](https://github.com/stripe/stripe-python).
### Installer la bibliothèque PHP
Installez la bibliothèque avec composer et initialisez-la avec votre clé API secrète. Si vous partez de zéro et que vous avez besoin d’un fichier composer.json, vous pouvez également télécharger les fichiers à l’aide du lien de téléchargement dans l’éditeur de code.
#### Composer
Installez la bibliothèque :
```bash
composer require stripe/stripe-php
```
#### GitHub
Vous pouvez sinon télécharger le code source de la bibliothèque php de Stripe directement [depuis GitHub](https://github.com/stripe/stripe-php).
### Configurer votre serveur
Ajoutez la dépendance à votre build et importez la bibliothèque. Si vous partez de zéro et avez besoin d’un fichier go.mod, téléchargez les fichiers du projet à l’aide du lien de téléchargement dans l’éditeur de code.
#### Go
Veillez à initialiser avec des modules Go :
```bash
go get -u github.com/stripe/stripe-go/v84
```
#### GitHub
Vous pouvez sinon télécharger le code source de la bibliothèque Go de Stripe directement [depuis GitHub](https://github.com/stripe/stripe-go).
### Installer la bibliothèque Stripe.net
Installez le package avec .NET ou NuGet. Si vous partez de zéro, vous pouvez également télécharger les fichiers qui contiennent un fichier .csproj configuré.
#### .NET
Installez la bibliothèque :
```bash
dotnet add package Stripe.net
```
#### NuGet
Installez la bibliothèque :
```bash
Install-Package Stripe.net
```
#### GitHub
Vous pouvez sinon télécharger le code source de la bibliothèque .NET de Stripe directement [depuis GitHub](https://github.com/stripe/stripe-dotnet).
### Installer les bibliothèques Stripe
Installez les packages et importez-les dans votre code. Si vous partez de zéro et qu’il vous faut un fichier `package.json`, vous pouvez également télécharger les fichiers du projet à l’aide du lien de téléchargement dans l’éditeur de code.
Installez les bibliothèques :
```bash
npm install --save stripe @stripe/stripe-js next
```
### Gérer les produits, tarifs et clients
Commencez par créer un tarif pour votre produit dans le [Dashboard](https://docs.stripe.com/invoicing/products-prices.md) ou via l’[API](https://docs.stripe.com/api/prices/create.md). Une fois le tarif créé et associé à un produit, consignez son ID dans votre base de données.
Ensuite, recherchez un objet [Customer](https://docs.stripe.com/api/customers.md) dans votre base de données en saisissant l’[adresse e-mail](https://docs.stripe.com/api/customers/object.md?lang=dotnet#customer_object-email) du client. Si celui-ci n’existe pas, créez l’objet `Customer` correspondant, et stockez son ID en vue des achats futurs. Ici, nous utilisons à l’étape suivante l’[ID](https://docs.stripe.com/api/customers/object.md#customer_object-id) de l’[objet Customer](https://docs.stripe.com/api/customers/object.md) pour créer une facture.
> L’objet `Customer` représente le client qui achète votre produit. Vous devez obligatoirement le spécifier pour créer une facture.
### Gérer les produits, les tarifs et les comptes configurés par les clients
Commencez par créer un tarif pour votre produit dans le [Dashboard](https://docs.stripe.com/invoicing/products-prices.md) ou via l’[API](https://docs.stripe.com/api/prices/create.md). Une fois le tarif créé et associé à un produit, consignez son ID dans votre base de données.
Ensuite, recherchez un client dans votre base de données à l’aide de son adresse e-mail. Si ce client n’existe pas, créez un [compte](https://docs.stripe.com/api/v2/core/accounts.md) pour ce [client](https://docs.stripe.com/connect/account-capabilities.md?accounts-namespace=v2#customer) et enregistrez son ID pour les achats futurs. L’étape suivante, par exemple, utilise l’[id](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-id) de [l’objet Compte ](https://docs.stripe.com/api/v2/core/accounts/object.md) pour créer une facture.
> L’objet `Compte` configuré par le client représente le client qui achète votre produit. Il est obligatoire pour créer une facture.
### Créer une facture vide
Définissez l’attribut [collection_method](https://docs.stripe.com/api/invoices/object.md#invoice_object-collection_method) sur `send_invoice`. Pour que Stripe soit en mesure de marquer une facture comme étant en retard, renseignez le paramètre [days_until_due](https://docs.stripe.com/api/invoices/create.md#create_invoice-days_until_due). Stripe envoie au client la facture et des instructions de paiement par e-mail.
> L’autre méthode d’encaissement disponible est `charge_automatically`. Dans ce cas, Stripe paye automatiquement la facture en débitant la source de paiement par défaut du client. Ici, nous avons utilisé le paramètre `send_invoice` afin d’éviter de débiter immédiatement le client.
### Créer un poste de facture
Créez un poste de facture en transmettant l’`id` du client, le `price` (tarif) du produit et l’ID de facture `invoice`.
Une facture peut comporter 250 postes de facture maximum.
> Si les postes de facture sont créés avant la facture elle-même, définissez le paramètre [pending_invoice_items_behavior](https://docs.stripe.com/api/invoices/create.md#create_invoice-pending_invoice_items_behavior) sur `include` à la création de la facture. Ainsi, tous les postes de facture en attente seront automatiquement ajoutés à la facture. Dans ce cas, ajoutez les postes de facture d’un seul client à la fois afin d’éviter toute erreur.
>
> Lorsque vous créez une facture, jusqu’à 250 postes de facture en attente y sont automatiquement ajoutés. Les éventuels postes de facture restants sont ajoutés à la facture suivante. Pour connaître les postes de facture en attente de votre client, consultez la **page des informations sur le client** ou définissez le paramètre [en attente](https://docs.stripe.com/api/invoiceitems/list.md#list_invoiceitems-pending) sur `true` lorsque vous utilisez l’API pour établir la liste de tous les postes de facture.
Envoyez la facture à l’adresse e-mail associée au client. Dès que vous envoyez une facture, Stripe la finalise. De nombreuses juridictions considérant les factures finalisées comme des documents juridiques, certains champs ne pourront plus être modifiés. En cas d’envoi de facture déjà réglée, l’e-mail ne fait pas référence au paiement.
Pour toute facture finalisée, vous pouvez soit télécharger et envoyer un [PDF](https://docs.stripe.com/api/invoices/object.md#invoice_object-invoice_pdf), soit [créer un lien](https://docs.stripe.com/api/invoices/object.md#invoice_object-hosted_invoice_url) vers la [page de la facture hébergée](https://docs.stripe.com/invoicing/hosted-invoice-page.md) correspondante.
## Félicitations !
Vous avez créé et envoyé votre première facture. Approfondissez encore votre intégration en apprenant à automatiser rapidement l’encaissement des taxes grâce à l’API.
### Automatiser l’encaissement des taxes
Calculez et percevez le montant de taxes approprié sur les transactions Stripe. En savoir plus sur [Stripe Tax](https://docs.stripe.com/tax.md) et la manière de [l’activer](https://dashboard.stripe.com/tax) dans le Dashboard avant l’intégration.
### Ajouter le paramètre de calcul automatique des taxes
Définissez le paramètre `automatic_tax` sur `enabled: true`.
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
const stripe = require('stripe')('<>');
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
const CUSTOMERS = [{stripeId: "cus_123456789", email: "jenny.rosen@example.com"}];
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
const PRICES = {basic: "price_123456789", professional: "price_987654321"};
const sendInvoice = async function (email) {
// Look up a customer in your database
let customer = CUSTOMERS.find(c => c.email === email);
let customerId;
if (!customer) {
// Create a new Customer
customer = await stripe.customers.create({
email,
description: 'Customer to invoice',
});
// Store the Customer ID in your database to use for future purchases
CUSTOMERS.push({stripeId: customer.id, email: email});
customerId = customer.id;
} else {
// Read the Customer ID from your database
customerId = customer.stripeId;
}
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
const CUSTOMERS = [{stripeId: "acct_123456789", email: "jenny.rosen@example.com"}];
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
const PRICES = {basic: "price_123456789", professional: "price_987654321"};
const sendInvoice = async function (email) {
// Look up a customer in your database
let customer = CUSTOMERS.find(c => c.email === email);
let customerId;
if (!customer) {
// Create a new customer-configured Account
customer = await stripe.v2.core.accounts.create({
contact_email: email,
display_name: 'Customer to invoice',
configuration: {
customer: {
capabilities: {
automatic_indirect_tax: {requested: true}
},
},
},
});
// Store the Customer ID in your database to use for future purchases
CUSTOMERS.push({stripeId: customer.id, email: email});
customerId = customer.id;
} else {
// Read the Customer ID from your database
customerId = customer.stripeId;
}
// Create an Invoice
const invoice = await stripe.invoices.create({
customer: customerId,
collection_method: 'send_invoice',
days_until_due: 30,
automatic_tax: {enabled: true},
});
// Create an Invoice
const invoice = await stripe.invoices.create({
customer_account: customerId,
collection_method: 'send_invoice',
days_until_due: 30,
automatic_tax: {enabled: true},
});
// Create an Invoice Item with the Price, and Customer you want to charge
const invoiceItem = await stripe.invoiceItems.create({
customer: customerId,
pricing: {
price: PRICES.basic,
},
invoice: invoice.id
});
// Create an Invoice Item with the Price and the customer-configured Account you want to charge
const invoiceItem = await stripe.invoiceItems.create({
customer_account: customerId,
pricing: {
price: PRICES.basic,
},
invoice: invoice.id
});
// Send the Invoice
await stripe.invoices.sendInvoice(invoice.id);
};
{
"name": "stripe-sample",
"version": "1.0.0",
"description": "A sample Stripe implementation",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "stripe-samples",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"stripe": "^20.4.0"
}
}
{
"name": "stripe-sample",
"version": "0.1.0",
"dependencies": {
"@stripe/react-stripe-js": "^3.7.0",
"@stripe/stripe-js": "^7.3.0",
"express": "^4.17.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^3.4.0",
"stripe": "20.4.0"
},
"devDependencies": {
"concurrently": "4.1.2"
},
"homepage": "http://localhost:3000/checkout",
"proxy": "http://localhost:4242",
"scripts": {
"start-client": "react-scripts start",
"start-server": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"start": "concurrently \"yarn start-client\" \"yarn start-server\""
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
const stripe = require('stripe')('<>');
\# This is a public sample test API key.
# Don’t submit any personally identifiable information in requests made with this key.
# Sign in to see your own test API key embedded in code samples.
Stripe.api_key = '<>'
\# This is a public sample test API key.
# Don’t submit any personally identifiable information in requests made with this key.
# Sign in to see your own test API key embedded in code samples.
$CLIENT = Stripe::StripeClient.new('<>')
\# You probably have a database to keep track of preexisting customers.
# But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
$CUSTOMERS = [{ stripeId: 'cus_123456789', email: 'jenny.rosen@example.com' }]
# Prices on Stripe model the pricing scheme of your business.
# Create Prices in the Dashboard or with the API before accepting payments
# and store the IDs in your database.
$PRICES = { basic: 'price_123456', professional: 'price_456789' }
def send_invoice(email)
# Look up a customer in your database
customer = $CUSTOMERS.find { |customer_obj| customer_obj[:email] == email }
customer_id = nil
if !customer
# Create a new Customer
customer = Stripe::Customer.create({
email: email,
description: 'Customer to invoice'
})
# Store the Customer ID in your database to use for future purchases
$CUSTOMERS << { stripeId: customer.id, email: email }
customer_id = customer.id
else
# Read the Customer ID from your database
customer_id = customer[:stripeId]
end
\# You probably have a database to keep track of preexisting customers.
# But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
$CUSTOMERS = [{ stripeId: 'acct_123456789', email: 'jenny.rosen@example.com' }]
# Prices on Stripe model the pricing scheme of your business.
# Create Prices in the Dashboard or with the API before accepting payments
# and store the IDs in your database.
$PRICES = { basic: 'price_123456', professional: 'price_456789' }
def send_invoice(email)
# Look up a customer in your database
customer = $CUSTOMERS.find { |customer_obj| customer_obj[:email] == email }
customer_id = nil
if !customer
# Create a new customer-configured Account
customer = $CLIENT.v2.core.accounts.create({
contact_email: email,
display_name: 'Customer to invoice',
configuration: {
customer: {
capabilities: {automatic_indirect_tax: {requested: true}}
}
}
})
\# Store the Customer ID in your database to use for future purchases
$CUSTOMERS << { stripeId: customer.id, email: email }
customer_id = customer.id
else
# Read the Customer ID from your database
customer_id = customer[:stripeId]
end
\# Create an Invoice
invoice = Stripe::Invoice.create({
customer: customer_id,
collection_method: 'send_invoice',
days_until_due: 30,
automatic_tax: {
enabled: true
},
})
\# Create an Invoice
invoice = $CLIENT.v1.invoices.create({
customer_account: customer_id,
collection_method: 'send_invoice',
days_until_due: 30,
automatic_tax: {
enabled: true
},
})
\# Create an Invoice Item
invoice_item = Stripe::InvoiceItem.create({
customer: customer_id,
pricing: {price: $PRICES[:basic]},
invoice: invoice.id
})
\# Create an Invoice Item
invoice_item = $CLIENT.v1.invoice_items.create({
customer_account: customer_id,
pricing: {price: $PRICES[:basic]},
invoice: invoice.id
})
\# Send the Invoice
Stripe::Invoice.send_invoice(invoice[:id])
\# Send the Invoice
$CLIENT.v1.invoices.send_invoice(invoice[:id])
Stripe.api_key = '<>'
import stripe
\# This is a public sample test API key.
# Don’t submit any personally identifiable information in requests made with this key.
# Sign in to see your own test API key embedded in code samples.
stripe.api_key = '<>'
import stripe
\# This is a public sample test API key.
# Don’t submit any personally identifiable information in requests made with this key.
# Sign in to see your own test API key embedded in code samples.
client = stripe.StripeClient('<>')
\# You probably have a database to keep track of preexisting customers
# But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
CUSTOMERS = [{"stripe_id": "cus_123456789", "email": "jenny.rosen@example.com"}]
# Prices in Stripe model the pricing scheme of your business.
# Create Prices in the Dashboard or with the API before accepting payments
# and store the IDs in your database.
PRICES = {"basic": "price_123456789", "professional": "price_987654321"}
def send_invoice(email):
# Look up a customer in your database
customers = [c for c in CUSTOMERS if c["email"] == email]
if customers:
customer_id=customers[0]["stripe_id"]
else:
# Create a new Customer
customer = stripe.Customer.create(
email=email, # Use your email address for testing purposes
description="Customer to invoice",
)
# Store the customer ID in your database for future purchases
CUSTOMERS.append({"stripe_id": customer.id, "email": email})
# Read the Customer ID from your database
customer_id = customer.id
\# You probably have a database to keep track of preexisting customers
# But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
CUSTOMERS = [{"stripe_id": "acct_123456789", "email": "jenny.rosen@example.com"}]
# Prices in Stripe model the pricing scheme of your business.
# Create Prices in the Dashboard or with the API before accepting payments
# and store the IDs in your database.
PRICES = {"basic": "price_123456789", "professional": "price_987654321"}
def send_invoice(email):
# Look up a customer in your database
customers = [c for c in CUSTOMERS if c["email"] == email]
if customers:
customer_id=customers[0]["stripe_id"]
else:
# Create a new customer-configured Account
customer = client.v2.core.accounts.create({
"contact_email": email, # Use your email address for testing purposes
"display_name": "Customer to invoice",
"configuration": {
"customer": {
"capabilities": {"automatic_indirect_tax": {"requested": True}}
},
},
})
\# Store the customer ID in your database for future purchases
CUSTOMERS.append({"stripe_id": customer.id, "email": email})
# Read the Customer ID from your database
customer_id = customer.id
\# Create an Invoice
invoice = stripe.Invoice.create(
customer=customer_id,
collection_method='send_invoice',
days_until_due=30,
\# Create an Invoice
invoice = client.v1.invoices.create({
"customer_account": customer_id,
"collection_method": 'send_invoice',
"days_until_due": 30,
"automatic_tax": { 'enabled': True },
\# Create an Invoice Item with the Price and Customer you want to charge
stripe.InvoiceItem.create(
customer=customer_id,
pricing={"price": PRICES["basic"]},
invoice=invoice.id
)
\# Create an Invoice Item with the Price and the customer-configured Account you want to charge
client.v1.invoice_items.create({
"customer_account": customer_id,
"pricing": {"price": PRICES["basic"]},
"invoice": invoice.id
})
\# Send the Invoice
stripe.Invoice.send_invoice(invoice.id)
return
\# Send the Invoice
client.v1.invoices.send_invoice(invoice.id)
return
certifi==2026.1.4
chardet==5.2.0
click==8.3.1
Flask==3.1.2
idna==3.11
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.3
requests==2.32.5
stripe==14.4.0
toml==0.10.2
Werkzeug==3.1.5
stripe.api_key = '<>'
\Stripe\Stripe::setApiKey($stripeSecretKey);
$CLIENT = new \Stripe\StripeClient($stripeSecretKey);
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
$CUSTOMERS = [
[
'stripeId' => 'cus_123456789',
'email' => 'jenny.rosen@example.com'
],
];
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
$PRICES = [
'basic' => 'price_123456789',
'professional' => 'price_987654321',
];
function sendInvoice($email) {
// Look up a customer in your database
global $CUSTOMERS;
global $PRICES;
$customerId = null;
$customers = array_filter($CUSTOMERS, function ($customer) use ($email) {
return $customer['email'] === $email;
});
if (!$customers) {
// Create a new Customer
$customer = \Stripe\Customer::create([
'email' => $email,
'description' => 'Customer to invoice',
]);
// Store the Customer ID in your database to use for future purchases
$CUSTOMERS[] = [
'stripeId' => $customer->id,
'email' => $email
];
$customerId = $customer->id;
}
else {
// Read the Customer ID from your database
$customerId = $customers[0]['stripeId'];
}
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll use an Object to store Stripe object IDs in this example.
$CUSTOMERS = [
[
'stripeId' => 'acct_123456789',
'email' => 'jenny.rosen@example.com'
],
];
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
$PRICES = [
'basic' => 'price_123456789',
'professional' => 'price_987654321',
];
function sendInvoice($email) {
// Look up a customer in your database
global $CUSTOMERS;
global $PRICES;
global $CLIENT;
$customerId = null;
$customers = array_filter($CUSTOMERS, function ($customer) use ($email) {
return $customer['email'] === $email;
});
if (!$customers) {
// Create a new customer-configured Account
$customer = $CLIENT->v2->core->accounts->create([
'contact_email' => $email,
'display_name' => 'Customer to invoice',
'configuration' => [
'customer' => [
'capabilities' => [
'automatic_indirect_tax' => [
'requested' => true,
],
],
],
]
]);
// Store the Customer ID in your database to use for future purchases
$CUSTOMERS[] = [
'stripeId' => $customer->id,
'email' => $email
];
$customerId = $customer->id;
}
else {
// Read the Customer ID from your database
$customerId = $customers[0]['stripeId'];
}
// Create an Invoice
$invoice = \Stripe\Invoice::create([
'customer' => $customerId,
'collection_method' => 'send_invoice',
'days_until_due' => 30,
'automatic_tax' => [
'enabled' => true,
],
]);
// Create an Invoice
$invoice = $CLIENT->v1->invoices->create([
'customer_account' => $customerId,
'collection_method' => 'send_invoice',
'days_until_due' => 30,
'automatic_tax' => [
'enabled' => true,
],
]);
// Create an Invoice Item with the Price, and Customer you want to charge
$invoiceItem = \Stripe\InvoiceItem::create([
'customer' => $customerId,
'pricing' => ['price' => $PRICES['basic']],
'invoice' => $invoice->id
]);
// Create an Invoice Item with the Price and the customer-configured Account you want to charge
$invoiceItem = $CLIENT->v1->invoiceItems->create([
'customer_account' => $customerId,
'pricing' => ['price' => $PRICES['basic']],
'invoice' => $invoice->id
]);
// Send the Invoice
$invoice->sendInvoice();
}
// Send the Invoice
$CLIENT->v1->invoices->sendInvoice();
}
$stripeSecretKey = '<>';
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
private static StripeClient Client { get; set; } = new StripeClient("<>");
public static void Main(string[] args)
{
// Add a Customer
Customers.Add(new MyCustomer()
{
StripeId = "acct_123456789",
Email = "jenny.rosen@example.com"
});
public static void sendInvoice(String email)
{
// Look up a customer in your database
var customer = Customers.Find(customer => customer.Email == email);
String customerId;
if(customer == null) {
// Create a new Customer
var customerOptions = new CustomerCreateOptions
{
Email = email,
Description = "Customer to invoice",
};
var stripeCustomer = Client.V1.Customers.Create(customerOptions);
customerId = stripeCustomer.Id;
// Store the Customer ID in your database to use for future purchases
Customers.Add(new MyCustomer()
{
StripeId = stripeCustomer.Id,
Email = stripeCustomer.Email,
});
} else {
// Read the Customer ID from your database
customerId = customer.StripeId;
}
public static void sendInvoice(String email)
{
// Look up a customer in your database
var customer = Customers.Find(customer => customer.Email == email);
String customerId;
if(customer == null) {
// Create a new customer-configured Account
var customerOptions = new Stripe.V2.Core.AccountCreateOptions
{
ContactEmail = email,
DisplayName = "Customer to invoice",
Configuration = new Stripe.V2.Core.AccountCreateConfigurationOptions
{
Customer = new Stripe.V2.Core.AccountCreateConfigurationCustomerOptions
{
Capabilities = new Stripe.V2.Core.AccountCreateConfigurationCustomerCapabilitiesOptions
{
AutomaticIndirectTax = new Stripe.V2.Core.AccountCreateConfigurationCustomerCapabilitiesAutomaticIndirectTaxOptions
{
Requested = true,
},
},
}
},
};
var stripeCustomer = Client.V2.Core.Accounts.Create(customerOptions);
customerId = stripeCustomer.Id;
// Store the Customer ID in your database to use for future purchases
Customers.Add(new MyCustomer()
{
StripeId = stripeCustomer.Id,
Email = stripeCustomer.CustomerEmail,
});
} else {
// Read the Customer ID from your database
customerId = customer.StripeId;
}
// Create an Invoice
var invoiceOptions = new InvoiceCreateOptions
{
Customer = customerId,
CollectionMethod = "send_invoice",
DaysUntilDue = 30,
AutomaticTax = new InvoiceAutomaticTaxOptions
{
Enabled = true,
},
};
var invoice = Client.V1.Invoices.Create(invoiceOptions);
// Create an Invoice
var invoiceOptions = new InvoiceCreateOptions
{
CustomerAccount = customerId,
CollectionMethod = "send_invoice",
DaysUntilDue = 30,
AutomaticTax = new InvoiceAutomaticTaxOptions
{
Enabled = true,
},
};
var invoice = Client.V1.Invoices.Create(invoiceOptions);
// Create an Invoice Item with the Price, and Customer you want to charge
var invoiceItemOptions = new InvoiceItemCreateOptions
{
Customer = customerId,
Pricing = new InvoiceItemPricingOptions
{
Price = Prices["basic"],
},
Invoice = invoice.Id
};
Client.V1.InvoiceItems.Create(invoiceItemOptions);
// Create an Invoice Item with the Price and the customer-configured Account you want to charge
var invoiceItemOptions = new InvoiceItemCreateOptions
{
CustomerAccount = customerId,
Pricing = new InvoiceItemPricingOptions
{
Price = Prices["basic"],
},
Invoice = invoice.Id
};
Client.V1.InvoiceItems.Create(invoiceItemOptions);
// Send the Invoice
Client.V1.Invoices.SendInvoice(invoice.Id);
}
}
}
services.AddSingleton(new StripeClient("<>"));
"github.com/stripe/stripe-go/v84"
"github.com/stripe/stripe-go/v84/customer"
"github.com/stripe/stripe-go/v84/invoice"
"github.com/stripe/stripe-go/v84/invoiceitem"
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
stripe.Key = "<>"
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
client := stripe.NewClient("<>")
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll hardcode a list of fake customers.
customers := []MyCustomer{
{
StripeId: "cus_123456789",
Email: "jenny.rosen@example.com",
},
}
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
prices := []MyPrice{
{
Tier: "basic",
StripeId: "price_123456789",
},
{
Tier: "professional",
StripeId: "price_987654321",
},
}
customerID := ""
// Look up a customer in your database
for _, x := range customers {
if x.Email == email {
customerID = x.StripeId
break
}
}
if customerID == "" {
params := &stripe.CustomerParams{
Email: stripe.String("jenny.rosen@example.com"),
Description: stripe.String("Customer to invoice"),
}
cus, _ := customer.New(params)
newCus := MyCustomer{
Email: email,
StripeId: cus.ID,
}
customers = append(customers, newCus)
customerID = cus.ID
}
// Look up the Price ID from your database
var priceID string
for _, y := range prices {
if y.Tier == "basic" {
priceID = y.StripeId
break
}
}
// You probably have a database to keep track of preexisting customers.
// But to keep things simple, we'll hardcode a list of fake customers.
customers := []MyCustomer{
{
StripeId: "acct_123456789",
Email: "jenny.rosen@example.com",
},
}
// Prices on Stripe model the pricing scheme of your business.
// Create Prices in the Dashboard or with the API before accepting payments
// and store the IDs in your database.
prices := []MyPrice{
{
Tier: "basic",
StripeId: "price_123456789",
},
{
Tier: "professional",
StripeId: "price_987654321",
},
}
customerID := ""
// Look up a customer in your database
for _, x := range customers {
if x.Email == email {
customerID = x.StripeId
break
}
}
if customerID == "" {
params := &stripe.V2CoreAccountCreateParams{
ContactEmail: stripe.String("jenny.rosen@example.com"),
DisplayName: stripe.String("Customer to invoice"),
Configuration: &stripe.V2CoreAccountCreateConfigurationParams{
Customer: &stripe.V2CoreAccountCreateConfigurationCustomerParams{
Capabilities: &stripe.V2CoreAccountCreateConfigurationCustomerCapabilitiesParams{
AutomaticIndirectTax: &stripe.V2CoreAccountCreateConfigurationCustomerCapabilitiesAutomaticIndirectTaxParams{
Requested: stripe.Bool(true),
},
},
},
},
}
cus, _ := client.V2CoreAccounts.Create(context.TODO(), params)
newCus := MyCustomer{
Email: email,
StripeId: cus.ID,
}
customers = append(customers, newCus)
customerID = cus.ID
}
// Look up the Price ID from your database
var priceID string
for _, y := range prices {
if y.Tier == "basic" {
priceID = y.StripeId
break
}
}
// Create an Invoice
inParams := &stripe.InvoiceParams{
Customer: stripe.String(customerID),
CollectionMethod: stripe.String("send_invoice"),
DaysUntilDue: stripe.Int64(30),
AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)},
}
in, _ := invoice.New(inParams)
// Create an Invoice
inParams := &stripe.InvoiceCreateParams{
CustomerAccount: stripe.String(customerID),
CollectionMethod: stripe.String("send_invoice"),
DaysUntilDue: stripe.Int64(30),
AutomaticTax: &stripe.CheckoutSessionAutomaticTaxParams{Enabled: stripe.Bool(true)},
}
in, _ := client.V1Invoices.Create(context.TODO(), inParams)
// Create an Invoice Item with the Price, and Customer you want to charge
iiParams := &stripe.InvoiceItemParams{
Customer: stripe.String(customerID),
Pricing: &stripe.InvoiceItemPricingParams{
Price: sstripe.String(priceID),
},
Invoice: stripe.String(in.ID)
}
invoiceitem.New(iiParams)
// Create an Invoice Item with the Price and the customer-configured Account you want to charge
iiParams := &stripe.InvoiceItemCreateParams{
CustomerAccount: stripe.String(customerID),
Pricing: &stripe.InvoiceItemCreatePricingParams{
Price: sstripe.String(priceID),
},
Invoice: stripe.String(in.ID)
}
client.V1InvoiceItems.Create(context.TODO(), iiParams)
// Send the Invoice
params := &stripe.InvoiceSendInvoiceParams{}
invoice.SendInvoice(in.ID, params)
// Send the Invoice
params := &stripe.InvoiceSendInvoiceParams{}
client.V1Invoices.SendInvoice(context.TODO(), in.ID, params)
require github.com/stripe/stripe-go/v84 v84.4.0
"github.com/stripe/stripe-go/v84"
"github.com/stripe/stripe-go/v84/webhook"
stripe.Key = "<>"
import com.stripe.Stripe;
import com.stripe.model.Customer;
import com.stripe.param.CustomerCreateParams;
import com.stripe.StripeClient;
import com.stripe.model.v2.core.Account;
import com.stripe.param.v2.core.AccountCreateParams;
public static void main(String[] args) {
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
Stripe.apiKey = "<>";
// Simulate data in the DB
customers.add(new MyCustomer("cus_123456789", "jenny.rosen@example.com"));
prices.add(new MyPrice("price_123456", "basic"));
prices.add(new MyPrice("price_789123", "professional"));
}
// This is a public sample test API key.
// Don’t submit any personally identifiable information in requests made with this key.
// Sign in to see your own test API key embedded in code samples.
public static StripeClient client = new StripeClient("<>");
public static void main(String[] args) {
// Simulate data in the DB
customers.add(new MyCustomer("acct_123456789", "jenny.rosen@example.com"));
prices.add(new MyPrice("price_123456", "basic"));
prices.add(new MyPrice("price_789123", "professional"));
}
static void sendInvoice(String email) {
Customer stripeCustomer;
// Look up a customer in your database
String customerId = null;
for (MyCustomer c : customers) {
if (c.getEmail().equals(email)) {
customerId = c.getStripeId();
}
}
// Create a new Customer
if(customerId == null) {
CustomerCreateParams params =
CustomerCreateParams
.builder()
.setEmail(email)
.setDescription("Customer to invoice")
.build();
try {
// Store the Customer ID in your database to use for future purchases
stripeCustomer = Customer.create(params);
customers.add(new MyCustomer(stripeCustomer.getId(), email));
customerId = stripeCustomer.getId();
} catch(StripeException e) {
System.out.println(e.getMessage());
}
}
static void sendInvoice(String email) {
Account stripeCustomer;
// Look up a customer in your database
String customerId = null;
for (MyCustomer c : customers) {
if (c.getEmail().equals(email)) {
customerId = c.getStripeId();
}
}
// Create a new customer-configured Account
if(customerId == null) {
AccountCreateParams params =
AccountCreateParams
.builder()
.setContactEmail(email)
.setDisplayName("Customer to invoice")
.setConfiguration(
AccountCreateParams.Configuration.builder()
.setCustomer(
AccountCreateParams.Configuration.Customer.builder()
.setCapabilities(
AccountCreateParams.Configuration.Customer.Capabilities.builder()
.setAutomaticIndirectTax(
AccountCreateParams.Configuration.Customer.Capabilities.AutomaticIndirectTax.builder()
.setRequested(true)
.build()
)
.build()
)
.build()
)
.build()
)
.build();
try {
// Store the Customer ID in your database to use for future purchases
stripeCustomer = client.v2().core().accounts().create(params);
customers.add(new MyCustomer(stripeCustomer.getId(), email));
customerId = stripeCustomer.getId();
} catch(StripeException e) {
System.out.println(e.getMessage());
}
}
try {
// Create an Invoice
InvoiceCreateParams invoiceParams =
InvoiceCreateParams
.builder()
.setCustomer(customerId)
.setCollectionMethod(InvoiceCreateParams.CollectionMethod.SEND_INVOICE)
.setDaysUntilDue(30L)
.setAutomaticTax(
InvoiceCreateParams.AutomaticTax.builder().setEnabled(true).build()
)
.build();
Invoice invoice = Invoice.create(invoiceParams);
try {
// Create an Invoice
InvoiceCreateParams invoiceParams =
InvoiceCreateParams
.builder()
.setCustomerAccount(customerId)
.setCollectionMethod(InvoiceCreateParams.CollectionMethod.SEND_INVOICE)
.setDaysUntilDue(30L)
.setAutomaticTax(
InvoiceCreateParams.AutomaticTax.builder().setEnabled(true).build()
)
.build();
Invoice invoice = client.v1().invoices().create(invoiceParams);
// Look up the Price ID from your database
String priceId = null;
for (MyPrice p : prices) {
if (p.getTier().equals("basic")) {
priceId = p.getStripeId();
}
}
// Create an Invoice Item with the Price and Customer you want to charge
InvoiceItemCreateParams invoiceItemParams =
InvoiceItemCreateParams.builder()
.setCustomer(customerId)
.setPricing(
InvoiceItemCreateParams.Pricing.builder()
.setPrice(priceId)
.build()
)
.setInvoice(invoice.getId())
.build();
try {
InvoiceItem.create(invoiceItemParams);
} catch(StripeException e) {
System.out.println(e.getMessage());
}
// Look up the Price ID from your database
String priceId = null;
for (MyPrice p : prices) {
if (p.getTier().equals("basic")) {
priceId = p.getStripeId();
}
}
// Create an Invoice Item with the Price and the customer-configured Account you want to charge
InvoiceItemCreateParams invoiceItemParams =
InvoiceItemCreateParams.builder()
.setCustomerAccount(customerId)
.setPricing(
InvoiceItemCreateParams.Pricing.builder()
.setPrice(priceId)
.build()
)
.setInvoice(invoice.getId())
.build();
try {
client.v1().invoiceItems().create(invoiceItemParams);
} catch(StripeException e) {
System.out.println(e.getMessage());
}
// Send an Invoice
InvoiceSendInvoiceParams params = InvoiceSendInvoiceParams.builder().build();
invoice.sendInvoice(params);
// Send an Invoice
InvoiceSendInvoiceParams params = InvoiceSendInvoiceParams.builder().build();
client.v1().invoices().sendInvoice(params);
Stripe.apiKey = "<>";
## Étapes suivantes
#### [Utiliser les webhooks entrants pour être informé des mises à jour en temps réel](https://docs.stripe.com/webhooks.md)
Écoutez les événements sur votre compte Stripe pour que votre intégration puisse déclencher automatiquement des réactions.
#### [Personnaliser les factures](https://docs.stripe.com/invoicing/customize.md)
Vous pouvez utiliser le [modèle de facture](https://dashboard.stripe.com/account/billing/invoice) pour personnaliser le contenu d’une facture. Vous pouvez aussi définir la langue préférée de vos clients et inclure des informations publiques dans vos [informations de compte](https://dashboard.stripe.com/settings/account/?support_details=true).
#### [API Invoicing](https://docs.stripe.com/api/invoices.md)
En savoir plus sur l’API Invoicing.
#### [CLI Stripe](https://docs.stripe.com/stripe-cli.md)
La CLI Stripe comporte plusieurs commandes vous permettant de tester votre application Stripe au-delà de la facturation.