# 継続支払いの税金を徴収する 継続支払いの税金を徴収および申告する方法をご紹介します。 Stripe Tax では、Stripe Billing の使用時に継続支払いの税額を計算できます。サブスクリプションを作成する前に顧客の所在地の詳細情報を使用して税額のプレビューを行い、顧客の支払い準備ができたら、Stripe Tax を有効にしてサブスクリプションを作成します。Stripe Tax はStripe Billing と連携し、設定された[料金モデル](https://docs.stripe.com/products-prices/pricing-models.md)、[比例配分 (日割り計算)](https://docs.stripe.com/billing/subscriptions/prorations.md)、[割引](https://docs.stripe.com/billing/subscriptions/coupons.md)、[トライアル](https://docs.stripe.com/billing/subscriptions/trials.md)などを使用して税金計算を自動的に処理します。 #### Customer v1 Customer v1 を使用した Stripe Tax と Billing の連携の概要を示す図。 (See full diagram at https://docs.stripe.com/tax/subscriptions) このガイドでは、初めて Stripe Tax と Billing を設定することを前提としています。[既存のサブスクリプションを更新する](https://docs.stripe.com/tax/subscriptions/update.md)方法をご覧ください。 Stripe Checkout を使用して新しいサブスクリプションを作成する場合は、[Checkout セッションで税金を自動徴収する](https://docs.stripe.com/tax/checkout.md)方法をご確認ください。また、以下の短い動画もご覧いただけます。 [Watch on YouTube](https://www.youtube.com/watch?v=3QBRs4IfDNo) ## 税額と合計額を推計する [サーバー側] #### 住所収集前 顧客が初めて決済フローを使用する際は、住所情報をまだ取得していない可能性があります。この場合、[請求書のプレビューを作成](https://docs.stripe.com/api/invoices/create_preview.md)し、[customer_details.tax.ip_address](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-tax-ip_address) を設定して、Stripe が IP アドレスを使用して所在地を確認できるようにします。 > ほとんどの場合、Stripe は IP アドレスを物理的なエリアに対して解決できますが、その精度はさまざまで、顧客の実際の所在地を反映できていない場合もあります。初期の見積もり以外で顧客の IP アドレスに頼ってアドレスを判別することはお勧めしません。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d "automatic_tax[enabled]=true" \ -d "customer_details[tax][ip_address]={{IP_ADDRESS}}" \ -d "subscription_details[items][0][price]={{PRICE_ID}}" ``` #### 住所収集後 顧客が住所の詳細情報を入力するときに、[customer_details.address](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-address) も設定します。配送先住所を収集する場合は、[customer_details.shipping](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-shipping) を使用します。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d "automatic_tax[enabled]=true" \ -d "customer_details[address][line1]={{LINE1}}" \ -d "customer_details[address][line2]={{LINE2}}" \ -d "customer_details[address][city]={{CITY}}" \ -d "customer_details[address][state]={{STATE}}" \ -d "customer_details[address][postal_code]={{POSTAL_CODE}}" \ -d "customer_details[address][country]={{COUNTRY}}" \ -d "customer_details[tax][ip_address]={{IP_ADDRESS}}" \ -d "subscription_details[items][0][price]={{PRICE_ID}}" ``` 請求書の [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) を確認します。ステータスが `requires_location_inputs` の場合は、住所の詳細情報が無効であるか、不備があります。この場合、顧客に住所情報の再入力や、正確な住所情報の提供を求めてください。 請求書の[total (合計)](https://docs.stripe.com/api/invoices/object.md#invoice_object-total) は顧客が支払う金額で、[tax (税金)](https://docs.stripe.com/api/invoices/object.md#invoice_object-tax) は請求書のすべての税金金額の合計です。税金の内訳については、[total_tax_amounts](https://docs.stripe.com/api/invoices/object.md#invoice_object-total_tax_amounts) をご覧ください。金額はすべてセント単位です。 > #### 税額ゼロ > > `tax` がゼロの場合は、顧客の所在地に税務登録があることを確認してください。[売上税、VAT、GST の登録](https://docs.stripe.com/tax/registering.md)方法と[税額ゼロとリバースチャージ](https://docs.stripe.com/tax/zero-tax.md)の詳細をご確認ください。 ## 顧客情報を収集する [クライアント側] 税額と合計額の見積もりができたら、配送先住所 (該当する場合)、請求先住所、支払い情報など、顧客情報の収集を開始します。Stripe Tax を使用する場合は、インテントなしで支払い情報を収集します。最初のステップは、[インテントのない Elements オブジェクトを作成](https://docs.stripe.com/js/elements_object/create_without_intent)することです。 ```javascript const stripe = Stripe("<>"); const elements = stripe.elements({ mode: 'subscription', currency: '{{CURRENCY}}', amount: {{TOTAL}}, // これは請求書の合計額です。 }); ``` 次に、[Address Element](https://docs.stripe.com/js/elements_object/create_address_element) と [Payment Element](https://docs.stripe.com/js/elements_object/create_payment_element) を作成し、その両方を[マウント](https://docs.stripe.com/js/element/mount)します。 ```javascript const addressElement = elements.create('address', { mode: 'billing' // or 'shipping', if you are shipping goods }); addressElement.mount('#address-element'); const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` その後、Address Element で[変更イベント](https://docs.stripe.com/js/element/events/on_change?type=paymentElement#element_on_change-event)をリッスンできます。住所が変更された場合は、税額と合計額を[再見積もり](https://docs.stripe.com/tax/subscriptions.md?estimate=after#estimate-taxes-total)します。 ```javascript addressElement.on('change', async function(event) { // Throttle your requests to avoid overloading your server or hitting // Stripe's rate limits. const { tax, total } = await updateEstimate(event.value.address); elements.update({ amount: total }); // Update your page to display the new tax and total to the user... }); ``` > 顧客が住所を入力すると、Address Element はキーストロークごとに `change` イベントを起動します。サーバーへの過負荷と Stripe の[レート制限](https://docs.stripe.com/rate-limits.md)への到達を回避するには、最後の `change` イベントの後、しばらく待ってから、税金と合計を推計しなおします。 ## 送信を処理する [クライアント側] 顧客がフォームを送信したら、[elements.submit()](https://docs.stripe.com/js/elements/submit) を呼び出してフォームのフィールドを検証し、ウォレットに必要なデータを収集します。この関数の Promise が解決されるのを待たないと、他の操作は実行できません。 ```javascript document.querySelector("#form").addEventListener("submit", async function(event) { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); const { error: submitError } = await elements.submit(); if (submitError) { // Handle error... return; } const { value: customerDetails } = await addressElement.getValue(); // See the "Save customer details" section below to implement this // server-side. await saveCustomerDetails(customerDetails); // 顧客の詳細を保存するリクエストをサーバーに送信します。 // See the "Create subscription" section below to implement this server-side. const { clientSecret } = await createSubscription(); // 新しいサブスクリプションの latest_invoice.confirmation_secret.client_secret。 // サブスクリプションを作成するリクエストをサーバーに送信します。 const { error: confirmError } = await stripe.confirmPayment({ elements, clientSecret, confirmParams: { return_url: {{RETURN_URL}}, // 顧客が支払いを完了した後にリダイレクトされる URL。 }, }); if (confirmError) { // Handle error... return; } // Upon a successful confirmation, your user will be redirected to the // return_url you provide before the Promise ever resolves. }); ``` ## 顧客の情報を保存する [サーバー側] #### Customer v1 顧客から収集した詳細情報で `Customer` オブジェクトを[更新](https://docs.stripe.com/api/customers/update.md)して、Stripe Tax で位置を精密に判定し、正確な結果が得られるようにしてください。 > 顧客が米国にいる場合、可能な限り詳細な住所を提供してください。「ルーフトップ・アキュレート」という用語は、顧客の所在地を特定の家や建物まで特定できることを意味します。米国の税区割は非常に複雑で、同じ通りの隣り合った2軒の家であっても、境界線をまたぐことで適用される税率が異なる場合があります。詳細な住所を提供することで、より高い精度で税計算を行うことが可能になります。 `Customer` オブジェクトをまだ作成していない場合 (顧客がウェブサイトで初めて登録したときなど) は、ここで[作成](https://docs.stripe.com/api/customers/create.md)できます。 #### 顧客情報を更新する ```curl curl https://api.stripe.com/v1/customers/{{CUSTOMER_ID}} \ -u "<>:" \ -d "address[line1]={{LINE1}}" \ -d "address[line2]={{LINE2}}" \ -d "address[city]={{CITY}}" \ -d "address[state]={{STATE}}" \ -d "address[postal_code]={{POSTAL_CODE}}" \ -d "address[country]={{COUNTRY}}" \ -d "tax[validate_location]=immediately" ``` > 顧客に、税の自動計算が有効になっている別のサブスクリプションがある場合、住所情報を更新すると、今後発行する請求書の税額や合計金額が変わる可能性があります。これは、税率が顧客の所在地によって異なるためです。 #### 顧客を作成する ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "address[line1]={{LINE1}}" \ -d "address[line2]={{LINE2}}" \ -d "address[city]={{CITY}}" \ -d "address[state]={{STATE}}" \ -d "address[postal_code]={{POSTAL_CODE}}" \ -d "address[country]={{COUNTRY}}" \ -d "tax[validate_location]=immediately" ``` サブスクリプションで自動課税を有効にするには、顧客の税務上の所在地が有効である必要があります。[tax.validate_location](https://docs.stripe.com/api/customers/update.md#update_customer-tax-validate_location) を `immediately` に設定して、顧客の税務上の所在地を検証します。検証に失敗した場合、Stripe は [customer_tax_location_invalid](https://docs.stripe.com/error-codes.md#customer-tax-location-invalid) エラーコードでリクエストを失敗させます。プレビュー請求書の [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) を確認することで、この失敗を回避できます。 ## サブスクリプションを作成する [サーバー側] 税金の自動徴収を有効にしてサブスクリプションを[作成します](https://docs.stripe.com/api/subscriptions/create.md)。 #### Customer v1 ```curl curl https://api.stripe.com/v1/subscriptions \ -u "<>:" \ -d "automatic_tax[enabled]=true" \ -d "customer={{CUSTOMER_ID}}" \ -d "items[0][price]={{PRICE_ID}}" \ -d "payment_settings[save_default_payment_method]=on_subscription" \ -d "expand[0]=latest_invoice.confirmation_secret" ``` [latest_invoice.confirmation_secret.client_secret](https://docs.stripe.com/api/invoices/object.md#invoice_object-confirmation_secret-client_secrett) は、新しいサブスクリプションの最初 (かつ最新) の請求書にある*支払いインテント* (API object that represents your intent to collect payment from a customer, tracking charge attempts and payment state changes throughout the process)の *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) です。支払いインテントを*確定* (Confirming a PaymentIntent indicates that the customer intends to pay with the current or provided payment method. Upon confirmation, the PaymentIntent attempts to initiate a payment)するには、client secret をフロントエンドに渡す必要があります。 > client secret は保存したり、ログに記録したり、顧客以外に漏洩したりしないでください。client secret が含まれるページはすべて、必ず TLS を有効にしてください。 顧客がデフォルトの支払い方法を使用している場合、サブスクリプションの最初の請求書は自動的に支払われます。これは、サブスクリプションの [latest_invoice .status](https://docs.stripe.com/api/invoices/object.md#invoice_object-status)を使用すると確認できます。決済フローで顧客から収集した新しい支払いの詳細を使用する場合は、最初の請求書が自動的に支払われないようにしてください。サブスクリプションの作成時に [payment_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-payment_behavior) に `default_incomplete` を渡し、表示のように [stripe.confirmPayment()](https://docs.stripe.com/js/payment_intents/confirm_payment) を使用して支払いインテントを確定します。詳細は、[請求の回収方法](https://docs.stripe.com/billing/collection-method.md)をご覧ください。 ## Optional: 商品と価格を更新する Stripe Tax では、*商品* (Products represent what your business sells—whether that's a good or a service)と*価格* (Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the interval if the price is for subscriptions)に保存されている、*税コード* (A tax code is the category of your product for tax purposes)や*税金処理* (Tax behavior determines whether you want to include taxes in the price ("inclusive") or add them on top ("exclusive"))などの情報を使用して、税額を計算します。これらの設定を明示的に指定しない場合、Stripe Tax は[税金設定](https://dashboard.stripe.com/settings/tax)で選択したデフォルトの税コードを使用します。 詳細については、[商品の税金コードと税金処理を指定する](https://docs.stripe.com/tax/products-prices-tax-codes-tax-behavior.md) をご覧ください。 ## Optional: 返金を処理する [サーバー側] 請求書の支払いに対する返金を作成すると、Stripe Tax によって仮受消費税が自動的に減額されます。 また、[クレジットノート](https://docs.stripe.com/api/credit_notes/object.md)を発行して、仮受消費税の減少額を追跡し、顧客に記録を提供することもできます。 #### 請求金額を返金する 請求書の合計に関連付けられた金額を返金するには、クレジットノートと返金を作成します。 #### 自動返金のクレジットノート [create Credit Note](https://docs.stripe.com/api/credit_notes/create.md) を呼び出し、`refund_amount` 値を指定して、クレジットノートと[返金](https://docs.stripe.com/api/refunds/object.md)をまとめて作成します。 ```curl curl https://api.stripe.com/v1/credit_notes \ -u "<>:" \ -d "invoice={{INVOICE_ID}}" \ -d refund_amount=1000 ``` #### 手動返金のクレジットノート [返金を作成し](https://docs.stripe.com/api/refunds/create.md)、[クレジットノート](https://docs.stripe.com/api/credit_notes/object.md)の作成時にその ID を含めます。このときに `refund_amount` 値は含めないでください。 ```curl curl https://api.stripe.com/v1/credit_notes \ -u "<>:" \ -d "invoice={{INVOICE_ID}}" \ -d "refunds[0][refund]={{REFUND_ID}}" \ -d "refunds[0][amount_refunded]=1000" ``` Stripe Tax は、返金合計額を税金と正味金額に自動配分します。 #### 請求書のラインアイテムの金額を返金する 請求書のラインアイテムに関連付けられている金額を返金する場合は、まず [preview Credit Note](https://docs.stripe.com/api/credit_notes/preview.md) を呼び出して、[total](https://docs.stripe.com/api/credit_notes/object.md#credit_note_object-total) と [total_excluding_tax](https://docs.stripe.com/api/credit_notes/object.md#credit_note_object-total_excluding_tax) の金額を計算します。 ```curl curl -G https://api.stripe.com/v1/credit_notes/preview \ -u "<>:" \ -d "invoice={{INVOICE_ID}}" \ -d "lines[0][type]=invoice_line_item" \ --data-urlencode "lines[0][invoice_line_item]={{line item id from invoice}}" \ -d "lines[0][amount]=1000" ``` 次に、[Credit Note](https://docs.stripe.com/api/credit_notes/object.md) と [Refund](https://docs.stripe.com/api/refunds/object.md) を作成します。 #### 自動返金のクレジットノート [create Credit Note](https://docs.stripe.com/api/credit_notes/create.md) を呼び出し、`refund_amount` 値を指定して、クレジットノートと[返金](https://docs.stripe.com/api/refunds/object.md)をまとめて作成します。 ```curl curl https://api.stripe.com/v1/credit_notes \ -u "<>:" \ -d "invoice={{INVOICE_ID}}" \ -d refund_amount=1000 \ -d "lines[0][type]=invoice_line_item" \ -d "lines[0][invoice_line_item]={{line item id from invoice}}" \ -d "lines[0][amount]=1000" ``` #### 手動返金のクレジットノート クレジットノートのプレビューで計算された `total` を使用して[返金を作成し](https://docs.stripe.com/api/refunds/create.md)、[Credit Note](https://docs.stripe.com/api/credit_notes/object.md) の作成時にその ID を含めます。このときに `refund_amount` 値は含めないでください。 ```curl curl https://api.stripe.com/v1/credit_notes \ -u "<>:" \ -d "invoice={{INVOICE_ID}}" \ -d "refunds[0][refund]={{REFUND_ID}}" \ -d "refunds[0][amount_refunded]=1000" \ -d "lines[0][type]=invoice_line_item" \ -d "lines[0][invoice_line_item]={{line item id from invoice}}" \ -d "lines[0][amount]=1000" ``` ## Webhook を使用する サブスクリプションアクティビティの大半は非同期で行われるため、*Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) を使用してサブスクリプションイベントをリッスンすることをお勧めします。 Stripe Tax の使用を開始するときは、必ず [invoice.finalization_failed](https://docs.stripe.com/api/events/types.md#event_types-invoice.finalization_failed) イベントをリッスンしてください。請求書の [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) が `requires_location_inputs` の場合は、顧客の住所の詳細が無効であるか、情報に不備があります。この場合、Stripe で税金の計算、請求書の確定、および支払いの回収を行うことはできません。住所情報を入力しなおすか、正確な住所を提供するように顧客に連絡してください。 詳しくは、[サブスクリプションでの Webhook の使用](https://docs.stripe.com/billing/subscriptions/webhooks.md)をご覧ください。 ## See also - [既存のサブスクリプションを更新する](https://docs.stripe.com/tax/subscriptions/update.md) - [Connect で Stripe Tax を使用する](https://docs.stripe.com/tax/connect.md) - [カスタム決済フローで税金を計算する](https://docs.stripe.com/tax/custom.md)