Reputation: 1639
I am using Stripe's Checkout API. I'd like to offer international shipping, with different shipping options and a shipping cost based on the country dinamically choosed on the checkout stripe page. Is there a way, using Checkout, to make shipping cost options conditional on the shipping address country the user inputs in the Checkout form? This is an excerpt from my code:
const session = await stripe.checkout.sessions.create({
success_url: "http://localhost:4242/success.html?id={CHECKOUT_SESSION_ID}",
cancel_url: "http://localhost:4242/cancel.html",
payment_method_types: ["card"],
mode: "payment",
line_items: [
{
price: "price_1Nxx6ZDsK4pxN0rvXLjRy7bJ",
quantity: req.body.quantity,
},
],
customer: "cus_Ol9Y0V0GCXTmSF",
billing_address_collection: "required",
shipping_address_collection: {
allowed_countries: [
"AT",
"BE",
"BG",
"HR",
"CY",
"CZ",
"DK",
"EE",
"FI",
"FR",
"DE",
"GR",
"HU",
"IE",
"IT",
"LV",
"LT",
"LU",
"MT",
"NL",
"PL",
"PT",
"RO",
"SK",
"SI",
"ES",
"SE",
],
},
shipping_options: [
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: 0,
currency: 'eur',
},
display_name: 'Free shipping',
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 5,
},
maximum: {
unit: 'business_day',
value: 7,
},
},
},
},
{
shipping_rate_data: {
type: 'fixed_amount',
fixed_amount: {
amount: 1000,
currency: 'usd',
},
display_name: 'Express',
delivery_estimate: {
minimum: {
unit: 'business_day',
value: 1,
},
maximum: {
unit: 'business_day',
value: 5,
},
},
},
},
],
customer_update: { shipping: "auto" },
automatic_tax: {
enabled: true,
},
allow_promotion_codes: true,
});
Imagine this scenario, pre products are in Italy, if the user insert an italian shipping address it's alright otherwise I want change shipping cost, for instance for France I would have 10 euro low service and 20 euro fast service. How could I implement this in stripe?
Upvotes: 2
Views: 868
Reputation: 1704
It's a good idea... Not possible though.
The only such thing is Stripe Tax, where the tax-rate is computed based on the address entered on Session - only for Tax purposes though, you couldn't even use it as a hack for Shipping rates, since it calculates tax based on your registrations.
The only option you have is to collect address before the Session, not collect it on the Session, and pass a shipping_rate that is appropriate to the address you collected.
Upvotes: 2