# Invoicing API を組み込む コードを使用して請求書を作成し、送信する方法をご紹介します。 [ダッシュボード](https://dashboard.stripe.com/invoices)は、[請求書を作成する](https://docs.stripe.com/invoicing/dashboard.md#create-invoice)ための最も一般的な方法です。請求書作成を自動化する場合は、API を組み込むことができます。[実装のサンプル](https://docs.stripe.com/invoicing/integration/quickstart.md)を使用して、完全に機能する Invoicing の実装を構築します。 ## Stripe を設定する Stripe API にアクセスするには、Stripe の公式ライブラリーを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## 商品を作成する 商品を作成するには、その名前を入力します。 ```curl curl https://api.stripe.com/v1/products \ -u "<>:" \ -d "name=Gold Special" ``` ## 価格を作成する [Price (価格)](https://docs.stripe.com/api.md#prices) には、商品の価格と請求期間を定義します。これには、商品の価格、使用通貨、およびサブスクリプションの価格の場合は請求期間も含まれます。商品と同様に、価格の種類が少ない場合はダッシュボードで管理することをお勧めします。単価は、当該通貨の最小単位で示します。この場合はセントになります (10 USD は 1,000 セントのため、単価は 1000)。 商品の価格を作成する必要がない場合は、インボイスアイテムの作成時に [amount](https://docs.stripe.com/api/invoiceitems/create.md#create_invoiceitem-amount) パラメーターを使用できます。 価格を作成してそれを商品に割り当てるには、商品 ID、単価、および通貨を指定します。次の例では、「Gold Special」商品の価格は 10 USD です。 ```curl curl https://api.stripe.com/v1/prices \ -u "<>:" \ -d "product={{PRODUCT_ID}}" \ -d unit_amount=1000 \ -d currency=usd ``` ## 顧客を作成する 請求書を作成する際には、商品を購入した当該顧客を表すオブジェクトが必要です。このオブジェクトには、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) または [Customer](https://docs.stripe.com/api/customers/object.md) を指定できます。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定の Account オブジェクトとしてモデル化する](https://docs.stripe.com/connect/use-accounts-as-customers.md)ことをお勧めします。 #### Accounts v2 顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) を `display_name` および `contact_email` を付して作成する方法は以下のとおりです。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": { "capabilities": {} } }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 [Customer](https://docs.stripe.com/api/customers/create.md) を `name`、`email`、そして `description` を付して作成する方法は以下のとおりです。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" \ -d "description=My first customer" ``` 顧客を作成後、顧客の `id` をデータベースに保存して、後で使用できるようにします。たとえば、次の手順では、顧客 ID を使用して請求書を作成します。 ## 請求書を作成する [collection_method](https://docs.stripe.com/api/invoices/object.md#invoice_object-collection_method) 属性を `send_invoice` に設定します。Stripe がインボイスを期日経過とマークできるようにするために、[days_until_due](https://docs.stripe.com/api/invoices/create.md#create_invoice-days_until_due) パラメーターを追加する必要があります。インボイスを送るときに、インボイスおよび支払い手順がメールで顧客に送信されます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/invoices \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d collection_method=send_invoice \ -d days_until_due=30 ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/invoices \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d collection_method=send_invoice \ -d days_until_due=30 ``` 次に、顧客 ID、製品 `price`、`Invoice` ID を指定して請求書の項目を作成します。 請求書アイテムの最大数は 250 です。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/invoiceitems \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "pricing[price]={{PRICE_ID}}" \ -d "invoice={{INVOICE_ID}}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/invoiceitems \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "pricing[price]={{PRICE_ID}}" \ -d "invoice={{INVOICE_ID}}" ``` `auto_advance` を `false` に設定した場合、インボイスは、[確定する](https://docs.stripe.com/invoicing/integration/workflow-transitions.md)前であればいつでも修正できます。インボイスの下書きを確定するには、ダッシュボードを使用するか、インボイスを顧客に送信するか、またはインボイスに対する支払いを行います。また、以下のように[Finalize (確定)](https://docs.stripe.com/api/invoices/finalize.md) API を使用することもできます。 ```curl curl -X POST https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/finalize \ -u "<>:" ``` 誤って請求書を作成した場合は、それを[無効](https://docs.stripe.com/invoicing/overview.md#void)にします。請求書を[回収不能](https://docs.stripe.com/invoicing/overview.md#uncollectible)とマークすることもできます。 ## 請求書支払いを受け付ける #### 請求書を送信する 顧客に関連付けられているメールアドレスに請求書を送信します。請求書が送信されるとすぐに、Stripe は請求書を確定します。多くの管轄区域では、確定済みの請求書は法的文書と見なされ、一部のフィールドは変更できなくなります。支払い済みの請求書を送信した場合、メールに支払いの参照情報は記載されません。 > 支払い済みの請求書を送信した場合は、メールに支払いの参照情報は含まれません。Stripe は、顧客に関連付けられたメールアドレスに請求書を送信します。 ```curl curl -X POST https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/send \ -u "<>:" ``` #### Stripe Elements 請求書が確定されると、*PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) が生成され、請求書に関連付けられます。[Stripe Elements](https://docs.stripe.com/payments/elements.md) を使用して、支払いの詳細を収集し、請求書の PaymentIntent を確定します。 請求書の確定後に金額や `collection_method` パラメーターを編集することはできません。この制限は、確定された請求書の PaymentIntent にも適用されます。[update](https://docs.stripe.com/api/payment_intents/update.md) コールで請求書の) PaymentIntent) を更新する場合、変更できるのは `setup_future_usage`、`metadata`、`payment_method`、`description`、`receipt_email`、`payment_method_data`、`payment_method_options`、`shipping` の各パラメーターのみです。 #### Payment Element (推奨) [Payment Element](https://docs.stripe.com/payments/payment-element.md) は、さまざまな決済手段で必要な支払い情報のすべてを安全に収集します。設定した決済手段が Invoicing と Payment Element の両方でサポートされているかどうかを確認するには、[決済手段と製品サポート](https://docs.stripe.com/payments/payment-methods/payment-method-support.md)を参照してください。 ### フロントエンドに client secret を渡す Stripe.js は、PaymentIntent の [client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を使用して、決済プロセスを安全に完了します。請求書の client secret を取得するには、請求書を[確定](https://docs.stripe.com/api/invoices/finalize.md)する際、または確定後に請求書で [retrieve](https://docs.stripe.com/api/invoices/retrieve.md) や [update](https://docs.stripe.com/api/invoices/update.md) などの API コールを別途実行する際に、[confirmation_secret](https://docs.stripe.com/api/invoices/object.md#invoice_object-confirmation_secret) 属性を[拡張](https://docs.stripe.com/api/expanding_objects.md)します。`client_secret` をフロントエンドに返して、支払いを完了します。 ```curl curl https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/finalize \ -u "<>:" \ -d "expand[]=confirmation_secret" ``` 請求書が返されたら、展開された `confirmation_secret` フィールドで client secret にアクセスします。 #### curl #### Stripe CLI #### Ruby ```ruby client_secret = invoice.confirmation_secret.client_secret ``` #### Python ```python client_secret = invoice.confirmation_secret.client_secret ``` #### PHP ```php $client_secret = $invoice->confirmation_secret->client_secret; ``` #### Java ```java String clientSecret = invoice.getConfirmationSecret().getClientSecret(); ``` #### Node.js ```javascript const client_secret = invoice.confirmation_secret.client_secret; ``` #### Go ```go clientSecret := invoice.ConfirmationSecret.ClientSecret ``` #### .NET ```csharp var clientSecret = invoice.ConfirmationSecret.ClientSecret; ``` ### Stripe Elements を設定する Payment Element は Stripe.js の機能として自動的に使用できるようになります。決済ページに Stripe.js スクリプトを含めるには、HTML ファイルの `head` にスクリプトを追加します。常に js.stripe.com から Stripe.js を直接読み込むことにより、PCI 準拠が維持されます。スクリプトをバンドルに含めたり、そのコピーを自身でホストしたりしないでください。 ```html Pay Invoice ``` 購入ページで次の JavaScript を使用して、Stripe のインスタンスを作成します。 ```javascript // Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe('<>'); ``` ### Payment Element をページに追加する 決済ページには Payment Element を配置する場所が必要です。決済フォームで、一意の ID を持つ空の DOM ノード (コンテナー) を作成します。 ```html
``` フォームが読み込まれたら、Payment Element のインスタンスを作成して、コンテナーの DOM ノードにマウントします。Elements のインスタンスを作成する際に、PaymentIntent の client secret をオプションとして渡します。 ```javascript const options = { clientSecret: '{{CLIENT_SECRET}}', // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in your checkout form, passing in the client secret. const elements = stripe.elements(options); // Create and mount the Payment Element const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` Payment Element によって動的なフォームが表示され、顧客はここで支払い方法を選択できます。このフォームでは、顧客が選択した支払い方法で必要な決済の詳細のすべてが自動的に収集されます。 Elements のインスタンスを作成する際に [Appearance (デザイン) オブジェクト](https://docs.stripe.com/elements/appearance-api.md)を `options` に渡すことで、サイトのデザインに合わせて Payment Element をカスタマイズできます。 ### 支払いを完了する `stripe.confirmPayment` を使用して、Payment Element からの詳細を指定した支払いを完了します。これにより支払い方法が作成され、請求書の支払いインテントが確定され、その結果支払いが実行されます。支払いに*強力な顧客認証* (Strong Customer Authentication (SCA) is a regulatory requirement in effect as of September 14, 2019, that impacts many European online payments. It requires customers to use two-factor authentication like 3D Secure to verify their purchase) (SCA) が必要とされる場合は、支払いインテントの確定前に Payment Element によって認証プロセスが処理されます。 支払いの完了後に Stripe がユーザーをリダイレクトする場所を指定するには、[return_url](https://docs.stripe.com/api/payment_intents/confirm.md#confirm_payment_intent-return_url) を `confirmPayment` 関数に指定します。ユーザーは、まず発行会社のオーソリページなどの中間サイトにリダイレクトされてから、`return_url` にリダイレクトされることになります。カード支払いでは、支払いが正常に完了するとすぐに `return_url` にリダイレクトされます。 ```javascript const form = document.getElementById('payment-form'); form.addEventListener('submit', async (event) => { event.preventDefault(); const {error} = await stripe.confirmPayment({ //`Elements` instance that was used to create the Payment Element elements, confirmParams: { return_url: "https://example.com/order/123/complete", } }); if (error) { // This point will only be reached if there is an immediate error when // confirming the payment. Show error to your customer (for example, payment // details incomplete) const messageContainer = document.querySelector('#error-message'); messageContainer.textContent = error.message; } else { // Your customer will be redirected to your `return_url`. For some payment // methods like iDEAL, your customer will be redirected to an intermediate // site first to authorize the payment, then redirected to the `return_url`. } }); ``` 顧客が支払いを送信すると、Stripe は顧客を `return_url` にリダイレクトし、以下の URL クエリーパラメーターを含めます。返品ページでは、これらを使用して PaymentIntent のステータスを取得し、顧客に支払いステータスを表示できます。 `return_url` を指定する際に、返品ページで使用する独自のクエリパラメーターを追加することもできます。 | パラメーター | 説明 | | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent` | `PaymentIntent` の一意の識別子。 | | `payment_intent_client_secret` | `PaymentIntent` オブジェクトの [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret)。サブスクリプションの実装の場合、この client_secret は [`confirmation_secret`](https://docs.stripe.com/api/invoices/object.md#invoice_object-confirmation_secret) を通じて `Invoice` オブジェクトでも公開されます | 顧客が自社のサイトにリダイレクトされたら、`payment_intent_client_secret` を使用して PaymentIntent をクエリし、顧客に取引ステータスを表示できます。 > 顧客のブラウザーセッションを追跡するツールを利用している場合、リファラー除外リストに `stripe.com` ドメインの追加が必要になる場合があります。リダイレクトを行うと、一部のツールでは新しいセッションが作成され、セッション全体の追跡ができなくなります。 `payment_intent_client_secret` クエリパラメーターを使用して、PaymentIntent を取得します。[PaymentIntent のステータス](https://docs.stripe.com/payments/paymentintents/lifecycle.md)を調べて、顧客に表示する内容を決定します。また、`return_url` を指定するときに自社のクエリパラメーターを追加することもできます。このパラメーターはリダイレクトプロセス全体を通じて存続します。 ```javascript // Initialize Stripe.js using your publishable key const stripe = Stripe('<>'); // Retrieve the "payment_intent_client_secret" query parameter appended to // your return_url by Stripe.js const clientSecret = new URLSearchParams(window.location.search).get( 'payment_intent_client_secret' ); // Retrieve the PaymentIntent stripe.retrievePaymentIntent(clientSecret).then(({paymentIntent}) => { const message = document.querySelector('#message') // Inspect the PaymentIntent `status` to indicate the status of the payment // to your customer. // // Some payment methods will [immediately succeed or fail][0] upon // confirmation, while others will first enter a `processing` state. // // [0]: https://stripe.com/docs/payments/payment-methods#payment-notification switch (paymentIntent.status) { case 'succeeded': message.innerText = 'Success! Payment received.'; break; case 'processing': message.innerText = "Payment processing. We'll update you when payment is received."; break; case 'requires_payment_method': message.innerText = 'Payment failed. Please try another payment method.'; // Redirect your user back to your payment page to attempt collecting // payment again break; default: message.innerText = 'Something went wrong.'; break; } }); ``` #### Card Element Card Element は、ユーザーからクレジットカード情報を安全に収集して検証します。 ### フロントエンドに client secret を渡す Stripe.js は、PaymentIntent の [client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を使用して、決済プロセスを安全に完了します。請求書の client secret を取得するには、請求書を[確定](https://docs.stripe.com/api/invoices/finalize.md)する際、または確定後に請求書で [retrieve](https://docs.stripe.com/api/invoices/retrieve.md) や [update](https://docs.stripe.com/api/invoices/update.md) などの API コールを別途実行する際に、[confirmation_secret](https://docs.stripe.com/api/invoices/object.md#invoice_object-confirmation_secret) 属性を[拡張](https://docs.stripe.com/api/expanding_objects.md)します。`client_secret` をフロントエンドに返して、支払いを完了します。 ```curl curl https://api.stripe.com/v1/invoices/{{INVOICE_ID}}/finalize \ -u "<>:" \ -d "expand[]=confirmation_secret" ``` 請求書が返されたら、展開された `confirmation_secret` フィールドで client secret にアクセスします。 #### curl #### Stripe CLI #### Ruby ```ruby client_secret = invoice.confirmation_secret.client_secret ``` #### Python ```python client_secret = invoice.confirmation_secret.client_secret ``` #### PHP ```php $client_secret = $invoice->confirmation_secret->client_secret; ``` #### Java ```java String clientSecret = invoice.getConfirmationSecret().getClientSecret(); ``` #### Node.js ```javascript const client_secret = invoice.confirmation_secret.client_secret; ``` #### Go ```go clientSecret := invoice.ConfirmationSecret.ClientSecret ``` #### .NET ```csharp var clientSecret = invoice.ConfirmationSecret.ClientSecret; ``` ### Stripe Elements を設定する Stripe Elements は Stripe.js に含まれています。自社の決済ページに Stripe.js スクリプトを含めるには、これを HTML ファイルの `head` に追加します。 常に js.stripe.com から Stripe.js を直接読み込むことにより、PCI への準拠が維持されます。スクリプトをバンドルに含めたり、そのコピーを自身でホストしたりしないでください。 ```html Subscription prices ``` 以下の JavaScript を使用して、Elements のインスタンスを作成します。 ```javascript // Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys let stripe = Stripe('<>'); let elements = stripe.elements(); ``` ### Elements をページに追加する Elements には、決済フォーム内の配置場所が必要です。決済フォームで一意の ID を持つ空の DOM ノード (コンテナー) を作成し、その ID を Elements に渡します。 ```html
``` Elements のインスタンスを作成し、それを Element コンテナにマウントします。 ```javascript let card = elements.create('card', { style: style }); card.mount('#card-element'); ``` `card` Element はフォームを簡素化し、必要なすべてのカード詳細を安全に収集する 1 つの柔軟な入力フィールドを挿入することによって、入力必須フィールドの数を最小限に抑えます。サポートされているすべての Element タイプのリストについては、[Stripe.js リファレンス](https://docs.stripe.com/js.md#elements_create)ドキュメントをご覧ください。 **4242 4242 4242 4242** のテストカード番号、任意の 3 桁のセキュリティコード、任意の将来日付の有効期限、および任意の 5 桁の郵便番号を使用します。 Elements はユーザーの入力を入力中に検証します。顧客が誤りを見つけやすくするため、次のように `card` Element で `change` イベントをリッスンし、エラーがあれば表示します。 ```javascript card.on('change', function (event) { displayError(event); }); function displayError(event) { changeLoadingStatePrices(false); let displayError = document.getElementById('card-element-errors'); if (event.error) { displayError.textContent = event.error.message; } else { displayError.textContent = ''; } } ``` [郵便番号の検証](https://docs.stripe.com/js.md#postal-code-formatting)は顧客の請求国によって異なります。[国際テストカード](https://docs.stripe.com/testing.md#international-cards)を使用して、さまざまな郵便番号形式をテストしてください。 ### 支払いを完了する 顧客が Elements フォームを送信したら、フロントエンドに渡した *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)) を指定して `stripe.confirmCardPayment` を呼び出します。これにより、支払い方法が作成され、請求書の PaymentIntent が*確定* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)され、その結果支払いが実行されます。支払いに*強力な顧客認証* (Strong Customer Authentication (SCA) is a regulatory requirement in effect as of September 14, 2019, that impacts many European online payments. It requires customers to use two-factor authentication like 3D Secure to verify their purchase) (SCA) が必要とされる場合は、PaymentIntent の確定前に Elements で認証プロセスが処理されます。 ```javascript const btn = document.querySelector('#submit-payment-btn'); btn.addEventListener('click', async (e) => { e.preventDefault(); const nameInput = document.getElementById('name'); // Create payment method and confirm PaymentIntent. stripe.confirmCardPayment(clientSecret, { payment_method: { card: cardElement, billing_details: { name: nameInput.value, }, } }).then((result) => { if(result.error) { alert(result.error.message); } else { // Successful invoice payment } }); }); ``` ## 支払い後のイベントを処理する Stripe は、請求書の支払いが完了すると [invoice.paid](https://docs.stripe.com/api/events/types.md?event_types-invoice.paid) イベントを送信します。このイベントをリッスンして、フルフィルメントが確実に行われるようにします。お客様のシステムでクライアント側のコールバックのみを使用している場合は、コールバックの実行前に顧客の接続が失われ、そのためにサーバーに通知されることなく、顧客への請求が行われることがあります。非同期型のイベントをリッスンするように実装を設定すると、一度の実装で[複数の異なるタイプの支払い方法](https://stripe.com/payments/payment-methods-guide)を受け付けられるようにもなります。 請求書の支払いが完了すると、[invoice.paid](https://docs.stripe.com/api/events/types.md?event_types-invoice.paid) イベントと [invoice.payment_succeeded](https://docs.stripe.com/api/events/types.md?event_types-invoice.payment_succeeded) イベントの双方がトリガーされます。どちらのイベントタイプにも同じ請求書データが含まれるため、どちらか一方のみを受信するだけで、請求書の支払いが完了したことが通知されます。両者の違いは以下の通りです。`invoice.payment_succeeded` イベントは、請求書の支払いが完了した場合に送信されますが、請求書が [paid_out_of_band](https://docs.stripe.com/api/invoices/pay.md#pay_invoice-paid_out_of_band) としてマークされた場合は送信されません。一方、`invoice.paid` イベントは、支払いが完了した場合と外部の支払いの双方に対してトリガーされます。`invoice.paid` は両方のシナリオに対応しているため、通常は、`invoice.payment_succeeded` ではなく、`invoice.paid` を受信することをお勧めします。 これらのイベントを受信して、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行するには、[ダッシュボードの Webhook ツール](https://dashboard.stripe.com/webhooks)を使用するか、[Webhook クイックスタート](https://docs.stripe.com/webhooks/quickstart.md)に従ってください。 Payment Element を使用して支払いを回収する場合は、`invoice.paid` イベントの他に 2 つのイベントを処理することをお勧めします。 | イベント | 説明 | アクション | | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | | [payment_intent.processing](https://docs.stripe.com/api/events/types.md?lang=php#event_types-payment_intent.processing) | 顧客が正常に支払いを開始したが、支払いがまだ完了していない場合に送信されます。このイベントは、多くの場合、銀行口座からの引き落としが開始されたときに送信されます。その後、`invoice.paid` イベントまたは `invoice.payment_failed` イベントが送信されます。 | 顧客に注文確認メールを送信し、支払いが保留中であることを示します。デジタル商品では、支払いの完了を待たずに注文のフルフィルメントを行うことが必要になる場合があります。 | | [invoice.payment_failed](https://docs.stripe.com/api/events/types.md?lang=php#event_types-payment_intent.payment_failed) | 顧客が請求書の支払いを試みたが、支払いに失敗した場合に送信されます。 | 支払いが `processing` から `payment_failed` に変わった場合は、顧客に再度支払いを試すように促します。 | ## Optional: 請求書をカスタマイズする [請求書をカスタマイズする](https://docs.stripe.com/invoicing/customize.md)方法はいくつかあります。Stripe のカスタマイズオプションを使用すると、独自のブランディングを追加したり、お客様が操業する管轄区域の規制に準拠するように変更できます。 ### カスタムフィールド カスタムフィールドを追加すると、請求書の PDF ドキュメントが具体化され、ビジネス慣行や税務報告義務をより遵守しやすくなります。カスタムフィールドには、請求書のヘッダーに表示するキーと値のペアを最大 4 つまで指定できます。[請求書エディター](https://dashboard.stripe.com/invoices/create)、[Invoices API](https://docs.stripe.com/api/invoices/create.md#create_invoice-custom_fields)、または[請求書テンプレート](https://docs.stripe.com/invoicing/invoice-rendering-template.md)で、最大 4 つまでカスタムフィールドのキーと値のペアを設定できます。 以下は、一般的なカスタムフィールドの使用方法です。 - 注文 (PO) 番号 - 請負業者番号 - 税金コンプライアンス PO 番号と付加価値税 (VAT) をカスタムフィールドとして使用して請求書を作成する例を次に示します。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/invoices \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "custom_fields[0][name]=PO number" \ -d "custom_fields[0][value]=12345" \ -d "custom_fields[1][name]=VAT" \ -d "custom_fields[1][value]=123ABC" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/invoices \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "custom_fields[0][name]=PO number" \ -d "custom_fields[0][value]=12345" \ -d "custom_fields[1][name]=VAT" \ -d "custom_fields[1][value]=123ABC" ``` #### カスタムフィールドの継承 顧客を表すために使用するオブジェクトには、カスタムの請求書フィールドを設定できます。顧客レベルで設定するカスタムフィールドは、当該顧客向けに作成する請求書の下書きすべてに適用されます。これらのカスタムフィールドは、請求書が下書きの状態であればいつでも変更できます。請求書が確定されると、カスタムフィールドの変更はできなくなります。 #### Accounts v2 顧客レベルで追加された [custom_fields](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer-billing-invoice-custom_fields) が今後作成される請求書の下書きすべてに適用される例は以下のとおりです。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": { "billing": { "invoice": { "custom_fields": [ { "name": "PO number", "value": "12345" } ] } } } }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 顧客レベルで追加された [custom_fields](https://docs.stripe.com/api/customers/object.md#customer_object-invoice_settings-custom_fields) が今後作成される請求書の下書きすべてに適用される例は以下のとおりです。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ --data-urlencode "email=jenny.rosen@example.com" \ -d payment_method=pm_card_visa \ -d "invoice_settings[default_payment_method]=pm_card_visa" \ -d "invoice_settings[custom_fields][0][name]=PO number" \ -d "invoice_settings[custom_fields][0][value]=12345" \ -d "invoice_settings[custom_fields][1][name]=VAT" \ -d "invoice_settings[custom_fields][1][value]=123ABC" ``` ## See also - [確定後](https://docs.stripe.com/invoicing/integration/workflow-transitions.md#post-finalized) - [着信する Webhook を使用してリアルタイムで更新を取得する](https://docs.stripe.com/webhooks.md)