ParcelCraft Dynamic Shipping Fix - Checkout Session
This document provides the corrected implementation for enabling ParcelCraft dynamic shipping rates in the Stripe Checkout session creation process.
Problem Overview
The create-checkout-session.ts file had two critical issues preventing ParcelCraft dynamic shipping from working correctly:
- A duplicate sessionParams declaration was accidentally placed inside the line items loop (around line 730)
- The shipping_options configuration was missing, which is required to enable ParcelCraft dynamic rate calculation
Solution
Step 1: Remove Duplicate sessionParams Declaration
Locate and remove the duplicate sessionParams declaration that was mistakenly placed inside the line items loop around line 730. This duplicate declaration was overwriting the correct configuration.
Step 2: Keep the Correct sessionParams Declaration
Ensure the correct sessionParams declaration remains in place. This should come after the following variables are defined:
- metadataForSession
- paymentIntentMetadata
- shippingAddressCollection
Step 3: Add shipping_options Configuration
Add the shipping_options configuration to the sessionParams object. This should be placed after shipping_address_collection and before success_url.
Code Implementation
Add the following configuration to your sessionParams object:
How It Works
The shipping_options configuration enables ParcelCraft dynamic shipping by:
- Setting up a placeholder shipping rate with amount: 0
- Using the display name 'Calculated at checkout' to inform customers
- Including metadata with parcelcraft: 'true' to trigger the ParcelCraft webhook integration
- Conditionally applying this configuration only when shippingRequired is true
Placement in sessionParams
The shipping_options configuration should be placed in the sessionParams object structure as follows:
Testing
After implementing these changes, test the checkout flow to verify:
- The checkout session creates successfully without errors
- Shipping rates are calculated dynamically based on the customer's address
- The ParcelCraft webhook is triggered correctly
- Shipping costs are accurately calculated and displayed to customers
Important Notes
- The currency is set to 'usd' - adjust this if your store uses a different currency
- The initial amount is 0 because ParcelCraft will calculate the actual shipping cost dynamically
- Ensure your ParcelCraft webhook is properly configured to handle the checkout.session.async_payment_succeeded event
- The spread operator syntax (...) ensures this configuration is only added when shipping is required
Related Posts
The Biggest Sale In F.A.S. History: Extended Cyber Monday Week
Professional porting and custom coating services at 10% off - the perfect time to upgrade your performance. - F.A.S. Motorsports
NEW PRODUCT DROP: 2020+ 6.7L Powerstroke Piping Kit – Hand-Fabricated Performance
Introducing our latest in-house fabrication: a premium piping kit engineered for 2020-2026 6.7L Ford Powerstroke trucks.