Accéder directement au contenu
Créez un compte
ou
connecter-vous
Logo de la documentation Stripe
/
Demander à l'assistant IA
Créez un compte
Connectez-vous
Démarrer
Paiements
Revenus
Plateformes et places de marché
Gestion de fonds
Ressources pour les développeurs
Aperçu
À propos des paiements Stripe
Mettre votre intégration à niveau
Analyses des paiements
Paiements en ligne
PrésentationTrouver votre cas d'usageUtiliser Managed Payments
Utiliser Payment Links
Utiliser une page de paiement préconfiguré
Créer une intégration personnalisée avec Elements
    Présentation
    Comparer Checkout Sessions et PaymentIntents
    Guides QuickStart
    Concevoir une intégration avancée
    Personnaliser l'apparence
    Gérer les moyens de paiement
    Collecter des informations supplémentaires
      Collecter les adresses physiques et les numéros de téléphone
      Personnaliser la collecte des données de facturation
      Facturer la livraison
    Créer une intégration pour les abonnements
    Mises à jour dynamiques
    Ajouter des réductions
    Percevoir les taxes sur vos paiements
    Utiliser des crédits
    Offrir aux clients la possibilité de payer dans leur devise locale
    Enregistrer et récupérer les moyens de paiement des clients
    Envoyer des reçus ou factures après paiement
    Approuver manuellement les paiements sur votre serveur
    Autoriser et capturer un paiement séparément
    Liste des modifications de la version bêta d'Elements avec l'API Checkout Sessions
Développer une intégration dans l'application
Moyens de paiement
Ajouter des moyens de paiement
Gérer les moyens de paiement
Paiement accéléré avec Link
Interfaces de paiement
Payment Links
Checkout
Elements pour le web
Paiements dans l'application
Scénarios de paiement
Gérer plusieurs devises
Tunnels de paiement personnalisés
Acquisition flexible
Orchestration
Paiements par TPE
Terminal
Au-delà des paiements
Constituez votre entreprise
Cryptomonnaies
Commerce agentique
Financial Connections
Climate
Comprendre la fraude
Radar pour la protection contre la fraude
Gestion des litiges
Vérifier l'identité
AccueilPaiementsBuild a custom integration with ElementsCollect additional information

Remarque

Cette page n'est pas encore disponible dans cette langue. Nous faisons tout notre possible pour proposer notre documentation dans davantage de langues et nous vous fournirons la version traduite dès qu'elle sera disponible.

Charge for shipping

Create different shipping rates for your customers.

Shipping rates let you display various shipping options, such as standard, express, and overnight, with more accurate delivery estimates. Charge your customer for shipping using different Stripe products. Before you create a shipping rate, learn how to collect billing and shipping addresses.

Remarque

Shipping rates only support fixed amount values for the entire order. You can’t adjust the shipping rate based on the number of items in the order.

Create a shipping rate
Server-side

Remarque

Shipping rates only support fixed amount values for the entire order. You can’t adjust the shipping rate based on the number of items in the order.

To add a shipping rate using the Dashboard:

  1. Click Create shipping rate.
  2. Enter an amount, a description, and an optional delivery estimate.
  3. Click Save, and copy the shipping rate ID (shr_123456).

Enter your shipping rate details

Update a shipping rate

You can’t update a shipping rate in the Dashboard. To update a shipping rate in the Dashboard, you must archive the shipping rate and then create a new one.

Archive a shipping rate

To archive a shipping rate:

  1. On the Shipping rates tab, select the applicable shipping rate.
  2. Click the overflow menu , and select Archive.

To unarchive the shipping rate, click the overflow menu , and select Unarchive shipping rate.

Create a Checkout Session
Server-side

To create a Checkout Session that includes your shipping rate, pass in the generated shipping rate ID to the shipping_options parameter. If you want to create the shipping rate at the same time as a Checkout Session, use the shipping_rate_data parameter with shipping_options. Only Checkout Sessions in payment mode support shipping options.

The following code sample adds two shipping options to the Checkout Session:

  • Free shipping, with an estimated delivery of 5-7 business days.
  • Next day air, at a cost of 15.00 USD, with an estimated delivery of exactly 1 business day.
Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d billing_address_collection=required \ -d "shipping_address_collection[allowed_countries][0]"=US \ -d "shipping_address_collection[allowed_countries][1]"=CA \ -d "shipping_options[0][shipping_rate_data][type]"=fixed_amount \ -d "shipping_options[0][shipping_rate_data][fixed_amount][amount]"=0 \ -d "shipping_options[0][shipping_rate_data][fixed_amount][currency]"=usd \ -d "shipping_options[0][shipping_rate_data][display_name]"="Free shipping" \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][minimum][unit]"=business_day \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][minimum][value]"=5 \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][maximum][unit]"=business_day \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][maximum][value]"=7 \ -d "shipping_options[1][shipping_rate_data][type]"=fixed_amount \ -d "shipping_options[1][shipping_rate_data][fixed_amount][amount]"=1500 \ -d "shipping_options[1][shipping_rate_data][fixed_amount][currency]"=usd \ -d "shipping_options[1][shipping_rate_data][display_name]"="Next day air" \ -d "shipping_options[1][shipping_rate_data][delivery_estimate][minimum][unit]"=business_day \ -d "shipping_options[1][shipping_rate_data][delivery_estimate][minimum][value]"=1 \ -d "shipping_options[1][shipping_rate_data][delivery_estimate][maximum][unit]"=business_day \ -d "shipping_options[1][shipping_rate_data][delivery_estimate][maximum][value]"=1 \ -d "line_items[0][price_data][currency]"=usd \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][quantity]"=1 \ -d mode=payment \ -d ui_mode=custom \ --data-urlencode return_url="https://example.com/return"

Collect the customer's shipping option
Client-side

On your client, use the shippingOptions object to render the available shipping options, such as in a radio button list. When your customer selects a shipping option, call updateShippingOption with the ID of the shipping option.

index.html
<div id="shipping-options"></div>
checkout.js
checkout.session().shippingOptions.forEach((option) => { const form = document.createElement('form'); shippingOptions.forEach(option => { const label = document.createElement('label'); const radio = document.createElement('input'); radio.type = 'radio'; radio.id = option.id; radio.name = 'shippingOption'; radio.value = option.id; radio.addEventListener('click', () => { checkout.updateShippingOption(option.id) }) const labelText = document.createTextNode(option.displayName); label.appendChild(radio); label.appendChild(labelText); form.appendChild(label); }); document.getElementById('shipping-options').appendChild(form); }); const shippingAddressElement = checkout.createShippingAddressElement(); shippingAddressElement.mount('#shipping-address');

FacultatifHandle completed transactions

After the payment succeeds, you can retrieve the shipping amount in the amount_total attribute of the shipping_cost. You can also retrieve the selected shipping rate using the shipping_rate attribute in shipping_cost. To access the shipping_cost property, you must create an event handler to handle completed Checkout Sessions. You can test a handler by installing the Stripe CLI and using stripe listen --forward-to localhost:4242/webhook to forward events to your local server. In the following code sample, the handler allows for the user to access the shipping_property:

Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key =
"sk_test_BQokikJOvBiI2HlWgH4olfQ2"
require 'sinatra' # You can find your endpoint's secret in your webhook settings endpoint_secret = 'whsec_...' post '/webhook' do event = nil # Verify webhook signature and extract the event # See https://stripe.com/docs/webhooks#verify-events for more information. begin sig_header = request.env['HTTP_STRIPE_SIGNATURE'] payload = request.body.read event = Stripe::Webhook.construct_event(payload, sig_header, endpoint_secret) rescue JSON::ParserError => e # Invalid payload return status 400 rescue Stripe::SignatureVerificationError => e # Invalid signature return status 400 end if event['type'] == 'checkout.session.completed' checkout_session = event['data']['object'] fulfill_order(checkout_session) end status 200 end def fulfill_order(checkout_session) selected_shipping_rate = Stripe::ShippingRate.retrieve(checkout_session.shipping_cost.shipping_rate) shipping_total = checkout_session.shipping_cost.amount_total # TODO: Remove error and implement... raise NotImplementedError.new(<<~MSG) Given the Checkout Session "#{checkout_session.id}" load your internal order from the database then implement your own fulfillment logic. MSG end

FacultatifDefine a delivery estimate

You can configure shipping rates using a number of delivery estimate combinations. The following table contains some examples of plain English delivery estimates, and their corresponding delivery_estimate.minimum and delivery_estimate.maximum values:

Delivery EstimateMinimumMaximum
1 day
{ unit: 'day', value: 1, }
{ unit: 'day', value: 1, }
1 business day
{ unit: 'business_day', value: 1, }
{ unit: 'business_day', value: 1, }
At least 2 business days
{ unit: 'business_day', value: 2, }
null
3 to 7 days
{ unit: 'day', value: 3, }
{ unit: 'day', value: 7, }
4 to 8 hours
{ unit: 'hour', value: 4, }
{ unit: 'hour', value: 8, }
4 hours to 2 business days
{ unit: 'hour', value: 4, }
{ unit: 'business_day', value: 2, }

FacultatifCharge tax for shipping

You can use Stripe Tax to automatically calculate tax on shipping fees by setting a tax_code and tax_behavior on your shipping rate. Stripe Tax automatically determines whether shipping is taxable (as taxability varies by state and country) and applies the correct tax rate if so.

When creating a shipping rate with shipping_rate_data or through Create a Shipping Rate, you can add a tax_behavior and tax_code parameter to the shipping rate.

We recommend setting the tax_code to Shipping (txcd_92010001) to make sure that you always charge the correct tax. You can also set the shipping rate tax_code to Nontaxable (txcd_00000000) if you don’t want to charge tax.

For this example, we set the tax_behavior to exclusive, which is common in the US. Learn more about tax behavior.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d billing_address_collection=required \ -d "shipping_address_collection[allowed_countries][0]"=US \ -d "shipping_address_collection[allowed_countries][1]"=CA \ -d "shipping_options[0][shipping_rate_data][type]"=fixed_amount \ -d "shipping_options[0][shipping_rate_data][fixed_amount][amount]"=0 \ -d "shipping_options[0][shipping_rate_data][fixed_amount][currency]"=usd \ -d "shipping_options[0][shipping_rate_data][display_name]"="Free shipping" \ -d "shipping_options[0][shipping_rate_data][tax_behavior]"=exclusive \ -d "shipping_options[0][shipping_rate_data][tax_code]"=txcd_92010001 \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][minimum][unit]"=business_day \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][minimum][value]"=5 \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][maximum][unit]"=business_day \ -d "shipping_options[0][shipping_rate_data][delivery_estimate][maximum][value]"=7 \ -d "line_items[0][price_data][currency]"=usd \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][price_data][tax_behavior]"=exclusive \ -d "line_items[0][quantity]"=1 \ -d "automatic_tax[enabled]"=true \ -d mode=payment \ -d ui_mode=custom \ --data-urlencode return_url="https://example.com/return"
Cette page vous a-t-elle été utile ?
OuiNon
  • Besoin d'aide ? Contactez le service Support.
  • Rejoignez notre programme d'accès anticipé.
  • Consultez notre log des modifications.
  • Des questions ? Contactez l'équipe commerciale.
  • LLM ? Lire llms.txt.
  • Propulsé par Markdoc