无法在Stripe Checkout价格基础上添加GST税费的技术求助
在Stripe Checkout中添加澳大利亚GST(10%消费税)的实现方案
针对你的需求,提供两种可行方案,均能在Stripe Checkout中正确计算并显示GST:
方法一:使用Stripe自动税(推荐)
Stripe自动税可根据客户地址自动计算税费,适配澳大利亚GST规则,无需手动计算,且会在Checkout页面单独展示税费项。
修改代码要点:
- 替换通用税码为澳大利亚服务类对应税码
txcd_30000000 - 启用自动税配置,传入不含GST的
totalBill金额,Stripe自动计算10%税费 - 确保客户地址信息完整(你已完成此步骤)
const product = await stripe.products.create({ name: `Service for ${name}`, // 无需手动添加"+GST",自动税会单独显示税费 tax_code: "txcd_30000000", // 澳大利亚服务类专用税码 }); const price = await stripe.prices.create({ currency: "aud", unit_amount: totalBill * 100, // 传入不含GST的金额,单位转换为澳分 product: product.id, }); if (price) { const customer = await stripe.customers.create({ email: email, name: name, address: { line1: addressLine1, city: addressCity, state: addressState, postal_code: addressPostalCode, country: addressCountry, }, }); if (customer) { session = await stripe.checkout.sessions.create({ payment_method_types: ["card"], line_items: [ { price: price.id, quantity: 1, }, ], customer: customer.id, customer_update: { address: "auto", }, automatic_tax: { // 启用自动税计算 enabled: true, }, mode: "payment", success_url: `URL`, cancel_url: "URL", }); const customerid = customer.id; customerStripeURL = `https://dashboard.stripe.com/customers/${customerid}`; } }
补充说明:
- 需先在Stripe后台开启「自动税」功能,并完成澳大利亚税务信息配置
- 自动税会根据客户地址判断是否收取GST,非澳大利亚客户不会触发税费计算
方法二:手动计算GST并拆分显示
若不想依赖自动税,可手动计算GST金额,通过两个Line Item分别展示服务金额和税费。
修改代码要点:
- 计算10%的GST金额,转换为澳分单位
- 创建两个独立的产品和价格对象,分别对应服务金额与GST
- 在Checkout Session中添加两个Line Item
// 创建服务产品与价格(不含GST) const serviceProduct = await stripe.products.create({ name: `Service for ${name}`, }); const servicePrice = await stripe.prices.create({ currency: "aud", unit_amount: totalBill * 100, product: serviceProduct.id, }); // 创建GST产品与价格 const gstProduct = await stripe.products.create({ name: "GST (10%)", }); const gstPrice = await stripe.prices.create({ currency: "aud", unit_amount: Math.round(totalBill * 0.1 * 100), // 计算10%GST并转澳分,避免小数精度问题 product: gstProduct.id, }); if (servicePrice && gstPrice) { const customer = await stripe.customers.create({ email: email, name: name, address: { line1: addressLine1, city: addressCity, state: addressState, postal_code: addressPostalCode, country: addressCountry, }, }); if (customer) { session = await stripe.checkout.sessions.create({ payment_method_types: ["card"], line_items: [ { price: servicePrice.id, quantity: 1, }, { price: gstPrice.id, quantity: 1, }, ], customer: customer.id, customer_update: { address: "auto", }, mode: "payment", success_url: `URL`, cancel_url: "URL", }); const customerid = customer.id; customerStripeURL = `https://dashboard.stripe.com/customers/${customerid}`; } }
补充说明:
- 此方式会在Checkout页面清晰展示服务金额和GST两个条目
- 需自行处理税务合规问题,比如判断客户是否属于GST征收范围
内容的提问来源于stack exchange,提问作者Tom Galland
相关产品推荐
相关产品推荐

