Stripe关联账户税务配置优化及自提订单计税方案咨询
基于Stripe的仓库订单应用税务处理问题解答
现有操作流程
1. 账户创建与入驻
创建并引导Stripe自定义账户入驻:
$account = $stripe->accounts->create([ 'type' => 'custom', 'country' => 'US', 'email' => $email, 'capabilities' => [ 'card_payments' => ['requested' => true], 'transfers' => ['requested' => true], 'us_bank_account_ach_payments' => ['requested' => true], ], ]); $session = $stripe->accountLinks->create([ 'account' => $account['id'], 'refresh_url' => $url, 'return_url' => $url, 'type' => 'account_onboarding', 'collection_options' => [ 'fields' => 'eventually_due', 'future_requirements' => 'include', ], ]); header('Location: ' . $session['url']); exit();
2. 税务设置配置
为账户配置税务设置:
$stripe->tax->settings->update([ 'defaults' => [ 'tax_behavior' => 'exclusive', ], 'head_office' => [ 'address' => [ 'line1' => $account->company->address->line1, 'city' => $account->company->address->city, 'state' => $account->company->address->state, 'postal_code' => $account->company->address->postal_code, 'country' => $account->company->address->country, ] ], ], ['stripe_account' => $account->id] );
3. 税务注册
为账户完成税务注册:
$stripe->tax->registrations->create([ 'country' => 'US', 'country_options' => [ 'us' => [ 'state' => $account->company->address->state, 'type' => 'state_sales_tax', ], ], 'active_from' => 'now', ], ['stripe_account' => $account->id]);
4. 结账流程(当前存在问题)
通过临时修改客户地址计算销售税:
function checkout($application_fee, $amount, $customer_id, $account_id){ global $stripe; $tax_settings = $stripe->tax->settings->retrieve([], ['stripe_account' => $account_id]); $stripe->customers->update( $customer_id, ['address' => [ 'postal_code' => $tax_settings->head_office->address->postal_code, 'country' => $tax_settings->head_office->address->country, ] ] ); $invoice = $stripe->invoices->create([ 'customer' => $customer_id, 'auto_advance' => false, // Do not auto-finalize the invoice 'collection_method' => 'charge_automatically', 'application_fee_amount' => $application_fee, 'automatic_tax' => [ 'enabled' => true, 'liability' => [ 'type' => 'account', 'account' => $account_id ], ], 'description' => "Order", 'footer' => "Thank you for using TextToTableAI!", 'issuer' => [ 'type' => 'account', 'account' => $account_id ], 'on_behalf_of' => $account_id, 'transfer_data' => [ 'destination' => $account_id, ], ]); $stripe->invoiceItems->create([ 'customer' => $customer_id, 'currency' => 'usd', 'description' => 'Test purchase', 'invoice' => $invoice->id, 'quantity' => 1, 'unit_amount' => $amount, 'tax_behavior' => 'exclusive', 'tax_code' => 'txcd_41052001' ]); $finalized_invoice = $invoice->finalizeInvoice(); $paid_invoice = $finalized_invoice->pay(); $stripe->customers->update( $customer_id, ['address' => [ 'postal_code' => null, 'country' => null, ] ] ); return $paid_invoice; }
问题解答
1. 是否可将关联账户入驻与税务配置流程合并,无需分步骤操作?
不能直接合并,核心原因是税务配置依赖入驻流程收集的账户信息:
- 税务设置和注册需要用到商家的公司地址等数据,这些信息只有在商家完成入驻表单填写后才会被Stripe同步到账户对象中。
- 入驻流程是异步的,商家跳转至Stripe页面完成信息提交后,账户的相关字段才会有有效值,在此之前无法完成准确的税务配置。
优化方案:监听Stripe的account.updated webhook事件,当账户的requirements.currently_due字段为空(即入驻完成)时,自动触发税务配置和注册流程,实现自动化的衔接,无需手动分步骤执行。
2. 对于无配送的自提订单,如何利用已保存的客户信息自动计算税务,避免临时修改地址?
自提订单的税务计算基于商家经营地址或客户指定的自提点,无需修改客户默认地址,可通过以下方式实现:
在创建发票时,添加shipping对象并指定自提地址,Stripe会基于该地址计算税务,而非客户的默认地址:
$invoice = $stripe->invoices->create([ 'customer' => $customer_id, 'auto_advance' => false, 'collection_method' => 'charge_automatically', 'application_fee_amount' => $application_fee, 'automatic_tax' => [ 'enabled' => true, 'liability' => [ 'type' => 'account', 'account' => $account_id ], ], 'shipping' => [ 'address' => [ // 这里设置自提地址,比如商家的head office地址 'postal_code' => $tax_settings->head_office->address->postal_code, 'country' => $tax_settings->head_office->address->country, 'state' => $tax_settings->head_office->address->state, 'city' => $tax_settings->head_office->address->city, 'line1' => $tax_settings->head_office->address->line1, ], 'name' => $customer->name, 'phone' => $customer->phone ], // 其他原有参数... ]);
这种方式既保留了客户的原始地址信息,又能让Stripe基于自提地址准确计算税务,完全替代临时修改客户地址的不合理操作。
内容的提问来源于stack exchange,提问作者tony
相关产品推荐
相关产品推荐

