Dynamically customize shipping options
Learn how to create different shipping rates for your customers.
Learn how to dynamically update shipping options based on the address that your customer enters in Checkout.
Use cases 
- Validate an address: Confirm whether you can ship a product to a customer’s address using your own custom validation rules. You can also create a custom UI for customers to confirm their preferred address.
- Show relevant shipping options: Display only available shipping methods, based on the customer’s address. For example, show overnight shipping only for deliveries in your country.
- Dynamically calculate shipping rates: Calculate and display shipping fees based on a customer’s delivery address.
- Update shipping rates based on order total: Offer shipping rates based on the shipping address or order total, such as free shipping for orders over 100 USD. For checkouts allowing quantity changes or cross-sells, see Dynamically updating line items.
Limitations 
- Only supported in payment mode. Shipping rates aren’t available in subscription mode.
Payment Intents API
If you use the Payment Intents API, you must manually update shipping options and modify the payment amount based on a selected shipping option, or by creating a new PaymentIntent with adjusted amounts.
Configure update permissions for the Checkout SessionServer-side
Set the shipping_address_collection.allowed_countries to the list of countries you want to offer shipping to.
When you create the Checkout Session, pass the permissions.update_shipping_details=server_only option to disable the client-side updateShippingAddress method and to enable updating the shipping address and shipping options from your server.
Customize shipping optionsServer-side
Create an endpoint on your server to calculate the shipping options based on the customer’s shipping address.
- Retrieve the Checkout Session using the
checkoutSessionId
from the request body. - Validate the customer’s shipping details from the request body.
- Calculate the shipping options based on the customer’s shipping address and the line items in the Checkout Session.
- Update the Checkout Session with the customer’s shipping_details and the shipping_options.
Test the integration
Follow these steps to test your integration, and ensure your custom shipping options work correctly.
Set up a sandbox environment that mirrors your production setup. Use your Stripe sandbox API keys for this environment.
Simulate various shipping addresses to verify that your
calculateShippingOptions
function handles different scenarios correctly.Verify server-side logic by using logging or debugging tools to confirm that your server:
- Retrieves the Checkout Session.
- Validates shipping details.
- Calculates shipping options.
- Updates the Checkout Session with new shipping details and options. Make sure the update response contains the new shipping details and options.
Verify client-side logic by completing the checkout process multiple times in your browser. Pay attention to how the UI updates after entering shipping details. Make sure that:
- The
runServerUpdate
function is called when expected. - Shipping options update correctly based on the provided address.
- Error messages display properly when shipping is unavailable.
- The
Enter invalid shipping addresses or simulate server errors to test error handling, both server-side and client-side.