Create different shipping rates for your customers.
Shipping rates let you display various shipping options—like 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.
Note
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.
Enter an amount, a description, and an optional delivery estimate.
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:
On the Shipping rates tab, select the applicable shipping rate.
Click the overflow menu , and select Archive.
To unarchive the shipping rate, click the overflow menu , and select Unarchive shipping rate.
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.
In this example, the first option in the shipping_options array is pre-selected for the customer on the checkout page. However, customers can choose either option.
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/apikeysStripe.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)rescueJSON::ParserError=> e
# Invalid payloadreturn status 400rescueStripe::SignatureVerificationError=> e
# Invalid signaturereturn status 400endif event['type']=='checkout.session.completed'
checkout_session = event['data']['object']
fulfill_order(checkout_session)end
status 200enddeffulfill_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...raiseNotImplementedError.new(<<~MSG)Given the CheckoutSession"#{checkout_session.id}" load your internal order from the database then implement your own fulfillment logic.MSGend
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:
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.