# 請求書をプレビューする 請求書のプレビューを作成する方法をご紹介します。 顧客が購入を検討している間に、請求書のプレビューを作成できます。[プレビューを作成して](https://docs.stripe.com/api/invoices/create_preview.md)、請求書の合計金額を計算し、請求書の各行を取得し、関連する税金や割引を含めます。プレビューを作成すると、請求書を作成せずに顧客に支払いの合計額を表示できます。 たとえば、事業者向けに修理サービスを提供している会社を運営している場合、以下のようにそれぞれ料金や請求スケジュールが異なる複数のアイテムを顧客に提示できます。 - アイテム 1: 299 USD の 1 回限りのサービス手数料 - アイテム 2: 29 USD の修理用資材 A - アイテム 3: 99 USD の修理用資材 B - アイテム 4: 月額 49 USD のサポートプラン 顧客は、お客様の商品とサービスの組み合わせが異なるとコストがどのように変わるかについて、情報を必要とする場合があります。顧客が 15% 割引の `WINTERSALE` プロモーションコードを適用してアイテム 1 と 3 の購入を検討している場合は、次の API コールを実行します。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d "invoice_items[0][price]=price_item_1" \ -d "invoice_items[0][quantity]=1" \ -d "invoice_items[1][price]=price_item_3" \ -d "invoice_items[1][quantity]=1" \ -d "discounts[0][promotion_code]=promo_WINTERSALE" ``` Stripeは、適用される割引および合計金額を示して、各明細行が記載された[請求書](https://docs.stripe.com/api/invoices/object.md)のプレビューを返します。 ```json { "id": "upcoming_in_1OujwkClCIKljWvsq5v2ICAN", "object": "invoice", "account_country": "US", "account_name": "Stripe Docs", "account_tax_ids": null, "amount_due": 39800, "amount_paid": 0, "amount_remaining": 39800, "amount_shipping": 0, "application": null, "application_fee_amount": null, "attachments": [], "attempt_count": 0, "attempted": false, "auto_advance": false, "automatic_tax": { "enabled": false, "liability": null, "status": null }, "billing_reason": "upcoming", "charge": null, "collection_method": "charge_automatically", "created": 1710544434, "currency": "usd", "custom_fields": null, "customer": "cus_PkEPRnhp0Yk1ph", "customer_address": null, "customer_email": null, "customer_name": null, "customer_phone": null, "customer_shipping": null, "customer_tax_exempt": "none", "customer_tax_ids": [], "default_margins": [], "default_payment_method": null, "default_source": null, "default_tax_rates": [], "description": null, "discount": null, "discounts": [], "due_date": null, "effective_at": null, "ending_balance": 0, "footer": null, "from_invoice": null, "hosted_invoice_url": null, "invoice_pdf": null, "issuer": { "type": "self" }, "last_finalization_error": null, "latest_revision": null, "lines": { "object": "list", "data": [ { "id": "il_tmp_133608ClCIKljWvs8da61423", "object": "line_item", "amount": 9900, "amount_excluding_tax": 9900, "currency": "usd", "description": "Price2", "discount_amounts": [], "discountable": true, "discounts": [], "invoice": "in_1OujwkClCIKljWvsfntkIWhT", "invoice_item": "ii_1OujwkClCIKljWvsnajC2mHG", "livemode": false, "margin_amounts": [], "margins": [], "metadata": {}, "period": { "end": 1710544434, "start": 1710544434 }, "plan": null, "price": { "id": "price_1OujwjClCIKljWvsKriuEI60", "object": "price", "active": true, "billing_scheme": "per_unit", "created": 1710544433, "currency": "usd", "custom_unit_amount": null, "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, "product": "prod_PkEPiQtlsZzbaa", "recurring": null, "tax_behavior": "unspecified", "tiers_mode": null, "transform_quantity": null, "type": "one_time", "unit_amount": 9900, "unit_amount_decimal": "9900" }, "proration": false, "proration_details": { "credited_items": null }, "quantity": 1, "rendering": null, "subscription": null, "tax_amounts": [], "tax_rates": [], "type": "invoiceitem", "unit_amount_excluding_tax": "9900" }, { "id": "il_tmp_1f6911ClCIKljWvs7a00e38c", "object": "line_item", "amount": 29900, "amount_excluding_tax": 29900, "currency": "usd", "description": "Price1", "discount_amounts": [], "discountable": true, "discounts": [], "invoice": "in_1OujwkClCIKljWvsfntkIWhT", "invoice_item": "ii_1OujwkClCIKljWvsJVGuvJYk", "livemode": false, "margin_amounts": [], "margins": [], "metadata": {}, "period": { "end": 1710544434, "start": 1710544434 }, "plan": null, "price": { "id": "price_1OujwiClCIKljWvss6aaPCEe", "object": "price", "active": true, "billing_scheme": "per_unit", "created": 1710544432, "currency": "usd", "custom_unit_amount": null, "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, "product": "prod_PkEPv778t9PLvu", "recurring": null, "tax_behavior": "unspecified", "tiers_mode": null, "transform_quantity": null, "type": "one_time", "unit_amount": 29900, "unit_amount_decimal": "29900" }, "proration": false, "proration_details": { "credited_items": null }, "quantity": 1, "rendering": null, "subscription": null, "tax_amounts": [], "tax_rates": [], "type": "invoiceitem", "unit_amount_excluding_tax": "29900" } ], "has_more": false, "total_count": 2, "url": "/v1/invoices/upcoming_in_1OujwkClCIKljWvsq5v2ICAN/lines" }, "livemode": false, "metadata": {}, "next_payment_attempt": null, "number": null, "on_behalf_of": null, "paid": false, "paid_out_of_band": false, "paper_checks": [], "payment_intent": null, "payment_settings": { "default_mandate": null, "payment_method_options": null, "payment_method_types": null }, "period_end": 1710544434, "period_start": 1710544434, "post_payment_credit_notes_amount": 0, "pre_payment_credit_notes_amount": 0, "quote": null, "receipt_number": null, "recurring": true, "redaction": null, "rendering": { "amount_tax_display": "exclude_tax", "pdf": null, "template": null, "template_version": null }, "rendering_options": { "amount_tax_display": "exclude_tax" }, "shipping_cost": null, "shipping_details": null, "starting_balance": 0, "statement_descriptor": null, "status": "draft", "status_transitions": { "finalized_at": null, "marked_uncollectible_at": null, "paid_at": null, "voided_at": null }, "subscription": null, "subscription_details": { "metadata": null, "pause_collection": null }, "subtotal": 39800, "subtotal_excluding_tax": 39800, "tax": null, "tax_filing_currency": null, "test_clock": null, "total": 39800, "total_discount_amounts": [], "total_excluding_tax": 39800, "total_margin_amounts": [], "total_tax_amounts": [], "transfer_data": null, "webhooks_delivered_at": null } ``` その他、生成された請求書のプレビューは、その後 72 時間は [/v1/invoices/:id](https://docs.stripe.com/api/invoices/retrieve.md) エンドポイントを介して取得することが可能です。 ```curl curl https://api.stripe.com/v1/invoices/upcoming_in_1OujwkClCIKljWvsq5v2ICAN \ -u "<>:" ``` ## Stripe Tax を含める Stripe Tax から税額をプレビューするには、`automatic_tax[enabled] = true`を設定し、`customer_details[address]`に顧客の住所を渡します。 顧客の住所が不明な場合は、代わりに `customer_details[tax][ip_address]` に IP アドレスを渡すこともできます。ほとんどの場合、Stripe は IP アドレスを物理エリアに解決できますが、その精度は異なり、顧客の実際の店舗を反映していない可能性があります。顧客の IP アドレスを使用して、当初の見積もり以外の住所を判断することはお勧めしません。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d "customer_details[address][line1]=920 5th Ave" \ -d "customer_details[address][city]=Seattle" \ -d "customer_details[address][state]=WA" \ -d "customer_details[address][postal_code]=98104" \ -d "customer_details[address][country]=US" \ -d "automatic_tax[enabled]=true" \ -d "invoice_items[0][price]=price_item_1" \ -d "invoice_items[0][quantity]=1" \ -d "invoice_items[1][price]=price_item_3" \ -d "invoice_items[1][quantity]=1" \ -d "discounts[0][promotion_code]=promo_WINTERSALE" ``` ## サブスクリプションの請求書をプレビューする 継続価格が含まれる最初の請求書をプレビューするには、[subscription_details.items](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-subscription_details-items) パラメーターを使用します。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d "subscription_details[items][0][price]=price_recurring_4" \ -d "subscription_details[items][0][quantity]=1" \ -d "invoice_items[0][price]=price_item_1" \ -d "invoice_items[0][quantity]=1" \ -d "invoice_items[1][price]=price_item_3" \ -d "invoice_items[1][quantity]=1" \ -d "discounts[0][promotion_code]=promo_WINTERSALE" ``` 既存のサブスクリプションの変更をプレビューするには、[サブスクリプション ID またはサブスクリプションスケジュール ID](https://docs.stripe.com/billing/subscriptions/subscription-schedules.md#preview-an-invoice) を指定します。 ## 継続支払いのみをプレビューする 顧客は、単一の項目や、一時的なクレジットや割引と併せて継続的なサブスクリプションの購入をしようとする場合があります。調整後の継続支払いを確認する場合は、[preview_mode](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-preview_mode) パラメーターを使用して、合計額のプレビューを提供します。 たとえば、`WINTERSALE` が 1 回限りの 15% 割引であり、顧客がアイテム 1、3、4 を購入ようとする場合、次の API コールで継続支払い額を取得できます。 ```curl curl https://api.stripe.com/v1/invoices/create_preview \ -u "<>:" \ -d preview_mode=recurring \ -d "subscription_details[items][0][price]=price_recurring_4" \ -d "subscription_details[items][0][quantity]=1" \ -d "invoice_items[0][price]=price_item_1" \ -d "invoice_items[0][quantity]=1" \ -d "invoice_items[1][price]=price_item_3" \ -d "invoice_items[1][quantity]=1" \ -d "discounts[0][promotion_code]=promo_WINTERSALE" ``` 生成される請求書には、割引のない月額 49 USD のサポートプランのみが記載されます。同様に、`preview_mode` を `subscription` または `subscription_schedule` と組み合わせて、単一の項目や割引を除外した、継続的な支払いの推定額を表示することができます。 ## 請求書行のページ分割 10 行を超える請求書については、[ページ分割された行のビューを取得できます](https://docs.stripe.com/api/invoice-line-item/retrieve.md)。 ```curl curl https://api.stripe.com/v1/invoices/upcoming_in_1OujwkClCIKljWvsq5v2ICAN/lines \ -u "<>:" ```